List of usage examples for org.apache.commons.io IOUtils toByteArray
public static byte[] toByteArray(String input) throws IOException
String
as a byte[]
using the default character encoding of the platform. From source file:com.shuzhilian.icu.license.LicenseGenerator.java
private void startUp(File key, char[] passwd) { LicenseCreatorProperties.setPrivateKeyDataProvider(() -> { try {//from w w w . ja va 2s. co m return IOUtils.toByteArray(new FileInputStream(key)); } catch (IOException e) { throw new KeyNotFoundException("Key file was not found.", e); } }); LicenseCreatorProperties.setPrivateKeyPasswordProvider(() -> passwd); }
From source file:com.eatnumber1.util.compression.AbstractCompressionProvider.java
@NotNull @Override// ww w . j a v a2s.c o m public byte[] decompress(@NotNull byte[] data) throws CompressionException { InputStream decompressedData = decompress(new ByteArrayInputStream(data)); try { return IOUtils.toByteArray(decompressedData); } catch (IOException e) { throw new CompressionException(e); } }
From source file:com.github.dynamo.torrent.parser.TorrentProcessor.java
/** * Given a File (supposed to be a torrent), parse it and represent it as a Map * @param file File//from www .ja v a 2 s .com * @return Map */ private static Map parseTorrent(InputStream input) { byte[] data; try { data = IOUtils.toByteArray(input); } catch (IOException e) { ErrorManager.getInstance().reportThrowable(e); return null; } Map torrent = null; try { torrent = BDecoder.decode(data); } catch (IOException e) { ErrorManager.getInstance().reportThrowable(e); } return torrent; }
From source file:com.spotify.echoprintserver.InvertedIndexBlockMakerTest.java
@Test public void testInvertedIndexCreation() throws IOException, IndexCreationException { List<Integer[]> codes = new TestUtils().test100EchoprintCodes(); byte[] invertedIndex = InvertedIndexBlockMaker.fromCodeSequences(codes); InputStream referenceInvertedIndexStream = this.getClass().getResourceAsStream("/inverted_index.bin"); byte[] referenceInvertedIndex = IOUtils.toByteArray(referenceInvertedIndexStream); Assert.assertArrayEquals(referenceInvertedIndex, invertedIndex); }
From source file:net.ion.radon.cload.stores.FileResourceStore.java
public byte[] read(final String pResourceName) { InputStream is = null;//from www . j ava2 s.c om try { is = new FileInputStream(getFile(pResourceName)); final byte[] data = IOUtils.toByteArray(is); return data; } catch (Exception e) { return null; } finally { IOUtils.closeQuietly(is); } }
From source file:com.talis.storage.memory.MemoryStore.java
@Override public synchronized StoredItem read(URI tmbURI) throws IOException, ItemNotFoundException { StoredItem stored = storage.get(tmbURI); if (null == stored) { throw new ItemNotFoundException(tmbURI); } else {//ww w . ja v a 2 s . c o m byte[] entity = IOUtils.toByteArray(stored.getEntity()); StoredItem toStore = copyItem(entity, stored); StoredItem toReturn = copyItem(entity, stored); storage.put(tmbURI, toStore); return toReturn; } }
From source file:com.sap.hana.cloud.samples.jenkins.common.StoredOrDefaultConfigurationProviderTest.java
@Test public void testEmptyRepositoryProvidesDefaultConfiguration() throws IOException { final Storage storage = setupMockStorage(null); final InputStream configuration = new StoredOrDefaultConfigurationProvider(storage) .getConfigurationStream();//from www .j a v a2 s.com final InputStream expectedStream = getClass().getResourceAsStream("cloud-jenkins-defaults-assembly.zip"); assertArrayEquals(IOUtils.toByteArray(expectedStream), IOUtils.toByteArray(configuration)); }
From source file:framework.JarResourceStore.java
public synchronized byte[] read(String pResourceName) { JarFile jar = null;/*from w w w .ja v a 2 s . c om*/ try { jar = new JarFile(URLDecoder.decode(filename, "utf-8")); JarEntry jarEntry = jar.getJarEntry(pResourceName); if (jarEntry != null) { InputStream inputStream = jar.getInputStream(jarEntry); try { return IOUtils.toByteArray(inputStream); } finally { inputStream.close(); } } } catch (IOException e) { Loggers.RELOADER.error(e.getMessage(), e); } finally { if (jar != null) { try { jar.close(); } catch (IOException e2) { Loggers.RELOADER.error(e2.getMessage(), e2); } } } return null; }
From source file:edu.byui.fb.BytesToImage.java
/** * Processes requests for both HTTP <code>GET</code> and <code>POST</code> * methods.// w w w .j a v a 2 s .com * * @param request servlet request * @param response servlet response * @throws ServletException if a servlet-specific error occurs * @throws IOException if an I/O error occurs */ protected void processRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { // Set as an image response.setContentType("image/jpeg"); // Get the id of the image String idstr = request.getParameter("id"); int id = Integer.parseInt(idstr); // Get the image given its id DataBaseHandler dbh = DataBaseHandler.getInstance(); Image image = dbh.getImage(id); // Get the InputStream of the image and convert to bytes byte[] ba = IOUtils.toByteArray(image.getBytes()); // Write bytes to screen response.getOutputStream().write(ba); }
From source file:hu.jozsef.vesza.so.servlets.EventImageService.java
@Override protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { Long eventId = new Long(request.getParameter("identifier")); Event fetchedEvent = objectify.load().type(Event.class).id(eventId).now(); String imageUrl = "/WEB-INF/" + fetchedEvent.getShortTitle() + ".png"; String imageRealPath = this.getServletContext().getRealPath(imageUrl); InputStream imgStream = new FileInputStream(new File(imageRealPath)); Blob image = new Blob(IOUtils.toByteArray(imgStream)); if (image != null) { response.setContentType("image/jpeg"); response.getOutputStream().write(image.getBytes()); } else {//from w w w . j a v a 2 s .c o m response.getWriter().write("no image"); } }