List of usage examples for org.apache.commons.io FileUtils readFileToByteArray
public static byte[] readFileToByteArray(File file) throws IOException
From source file:gov.nih.nci.cacis.nav.InMemoryCacheDocumentHolder.java
/** * Adds the document to the in memory cache with the docId as the key * // ww w . java 2s. c o m * @param docId - key to identify the document * @param docFile - File instance representing the document * @throws IOException - thrown if any IO error happens */ public void putDocument(String docId, File docFile) throws IOException { if (docFile == null || !docFile.exists()) { return; } final byte[] docContent = FileUtils.readFileToByteArray(docFile); final InputStream docIn = new ByteArrayInputStream(docContent); putDocument(docId, docIn); }
From source file:com.edduarte.protbox.core.Constants.java
/** * Moves all contents from the first specified registry to the second specified * registry, overriding if it already exists! *//* w w w . ja v a 2 s. c o m*/ public static void moveContentsFromDirToDir(File fromDir, File toDir) throws IOException { try { File[] list = fromDir.listFiles(); if (list == null) { return; } for (File f : list) { File destination = new File(toDir, f.getName()); if (f.isDirectory()) { destination.mkdir(); moveContentsFromDirToDir(f, destination); } else { FileUtils.writeByteArrayToFile(destination, FileUtils.readFileToByteArray(f)); } Constants.delete(f); } } catch (NullPointerException ex) { throw new IOException("Specified registry is not a folder.", ex); } }
From source file:com.ettrema.zsync.UploadReaderTests.java
@Test public void testSendRangesFileInput() throws IOException { createTestFiles();// w w w .j a va 2 s .c om String inString = "MOVEBLOCKSXXXXXXXXXXXXXXXXXXXXXXXXX"; InputStream dataIn = new ByteArrayInputStream(inString.getBytes("US-ASCII")); List<ByteRange> ranges = new ArrayList<ByteRange>(); ranges.add(new ByteRange(new Range(20, 30), dataIn)); Enumeration<ByteRange> dataEnum = new Upload.IteratorEnum<ByteRange>(ranges); UploadReader.sendRanges(dataEnum, updatedcopy); byte[] updatedbytes = FileUtils.readFileToByteArray(updatedcopy); String expResult = "XXXXXXXXXXXXXXXXXXXXMOVEBLOCKSXXXXXXXXXX"; String actResult = new String(updatedbytes, "US-ASCII"); Assert.assertEquals(expResult, actResult); }
From source file:com.cws.esolutions.agent.processors.impl.FileManagerProcessorImplTest.java
@Test public final void testDeployFiles() { try {//from www. ja v a 2s. c om List<String> fileSet = new ArrayList<String>( Arrays.asList("C:\\var\\temp\\acct.sql", "C:\\var\\temp\\cust.sql", "C:\\var\\temp\\dns.sql")); List<byte[]> dataSet = new ArrayList<byte[]>( Arrays.asList(FileUtils.readFileToByteArray(FileUtils.getFile("C:\\temp\\acct.sql")), FileUtils.readFileToByteArray(FileUtils.getFile("C:\\temp\\cust.sql")), FileUtils.readFileToByteArray(FileUtils.getFile("C:\\temp\\dns.sql")))); FileManagerRequest request = new FileManagerRequest(); request.setSourceFiles(dataSet); request.setTargetFiles(fileSet); // request.setType(FileManagementType.DEPLOY); FileManagerResponse response = processor.deployFile(request); Assert.assertEquals(AgentStatus.SUCCESS, response.getRequestStatus()); } catch (FileManagerException fmx) { Assert.fail(fmx.getMessage()); } catch (IOException iox) { Assert.fail(iox.getMessage()); } }
From source file:com.exalttech.trex.ui.views.streams.viewer.PacketParser.java
/** * * @param fileName// w ww . ja v a 2 s.c om * @param packetInfo */ public void parseFile(String fileName, PacketInfo packetInfo) { Packet packet; try { this.packetInfo = packetInfo; total_octetes = 0; PcapHandle handle = Pcaps.openOffline(fileName); packet = handle.getNextPacketEx(); packetInfo.setPacket(packet); extractPacketInfo(packet); handle.close(); } catch (PcapNativeException | EOFException | TimeoutException | NotOpenException ex) { packet = null; LOG.warn("Failed to extract packet info from first try"); } if (packet == null) { try { LOG.info("Attempting alternate method to read Pcap file"); byte[] pkt = FileUtils.readFileToByteArray(new File(fileName)); packet = EthernetPacket.newPacket(pkt, 0, pkt.length); extractPacketInfo(packet); } catch (IOException | IllegalRawDataException ex) { LOG.error("Failed to read Pcap file", ex); } } }
From source file:brooklyn.util.task.ssh.SshFetchTaskWrapper.java
/** blocks, returns the fetched file as bytes, throwing if there was an exception */ public byte[] getBytes() { block();//from www .jav a 2s . c o m try { return FileUtils.readFileToByteArray(backingFile); } catch (IOException e) { throw Exceptions.propagate(e); } }
From source file:com.playonlinux.core.utils.archive.TarTest.java
@Test public void testBunzip2() throws IOException { final File inputFile = new File(inputUrl.getPath(), "pol.txt.bz2"); final File outputFile = File.createTempFile("output", "txt"); new Tar().bunzip2(inputFile, outputFile); assertEquals("PlayOnLinux", new String(FileUtils.readFileToByteArray(outputFile))); }
From source file:gobblin.security.ssl.SSLContextFactory.java
private static InputStream toInputStream(File storeFile) throws IOException { byte[] data = FileUtils.readFileToByteArray(storeFile); return new ByteArrayInputStream(data); }
From source file:io.clubby.server.ClubbyDynamicSettings.java
public static String getIconBase64() { String iconBase64 = ""; File iconFile = null;/*w w w . j a va 2 s.c o m*/ if (getIconImage() != null) { String folder = Settings.instance().getDataDirectory() + "/uploaded-files/"; String fullPath = folder + getIconImage().getCloudKey(); File file = new File(fullPath); if (file.exists()) { iconFile = file; } } if (iconFile == null) { try { iconFile = new IconHelper().getOrCreateAutoIcon(); } catch (IOException e) { Log.exception(e, "Error generating icon"); } } if (iconFile != null) { try { byte[] bytes = FileUtils.readFileToByteArray(iconFile); iconBase64 = Base64.encodeBase64String(bytes); } catch (IOException e) { Log.exception(e, "Error reading and encoding icon file " + iconFile.getAbsolutePath()); } } return iconBase64; }
From source file:de.undercouch.gradle.tasks.download.FunctionalDownloadTest.java
/** * Test if multiple files can be downloaded successfully * @throws Exception if anything went wrong *//* ww w. j a v a 2 s. com*/ @Test public void downloadMultipleFiles() throws Exception { assertTaskSuccess(download(new Parameters(multipleSrc, dest, true, false))); assertTrue(destFile.isDirectory()); assertArrayEquals(contents, FileUtils.readFileToByteArray(new File(destFile, TEST_FILE_NAME))); assertArrayEquals(contents2, FileUtils.readFileToByteArray(new File(destFile, TEST_FILE_NAME2))); }