List of usage examples for org.apache.commons.io FileUtils readFileToByteArray
public static byte[] readFileToByteArray(File file) throws IOException
From source file:gemlite.core.internal.support.hotdeploy.scanner.ScannerIteratorItem.java
public byte[] getBytes(ClassLoader loader) throws IOException { byte[] bytes = null; if (jarFile)/*from www . j av a 2 s . c om*/ bytes = readContent(loader, (JarEntry) item); else bytes = FileUtils.readFileToByteArray((File) item); return bytes; }
From source file:com.baasbox.util.Util.java
public static void createZipFile(String path, File... files) { if (BaasBoxLogger.isDebugEnabled()) BaasBoxLogger.debug("Zipping into:" + path); ZipOutputStream zip = null;//from www . j a v a 2s . c om FileOutputStream dest = null; try { File f = new File(path); dest = new FileOutputStream(f); zip = new ZipOutputStream(new BufferedOutputStream(dest)); for (File file : files) { zip.putNextEntry(new ZipEntry(file.getName())); zip.write(FileUtils.readFileToByteArray(file)); zip.closeEntry(); } } catch (Exception e) { e.printStackTrace(); throw new RuntimeException("Unable to create zip file"); } finally { try { if (zip != null) zip.close(); if (dest != null) dest.close(); } catch (Exception ioe) { //Nothing to do } } }
From source file:com.offbynull.coroutines.mavenplugin.AbstractInstrumentMojo.java
/** * Instruments all classes in a path recursively. * @param log maven logger/*w w w. j av a 2s . c o m*/ * @param instrumenter coroutine instrumenter * @param path directory containing files to instrument * @throws MojoExecutionException if any exception occurs */ protected final void instrumentPath(Log log, Instrumenter instrumenter, File path) throws MojoExecutionException { try { for (File classFile : FileUtils.listFiles(path, new String[] { "class" }, true)) { log.info("Instrumenting " + classFile); byte[] input = FileUtils.readFileToByteArray(classFile); byte[] output = instrumenter.instrument(input); log.debug("File size changed from " + input.length + " to " + output.length); FileUtils.writeByteArrayToFile(classFile, output); } } catch (Exception ex) { throw new MojoExecutionException("Unable to get compile classpath elements", ex); } }
From source file:com.cloudant.sync.datastore.BasicDatastoreForceInsertTest.java
@Before public void setUp() throws Exception { database_dir = TestUtils.createTempTestingDir(BasicDatastoreForceInsertTest.class.getName()); datastore = new BasicDatastore(database_dir, "test"); database = datastore.getSQLDatabase(); jsonData = FileUtils.readFileToByteArray(new File(documentOneFile)); bodyOne = new BasicDocumentBody(jsonData); jsonData = FileUtils.readFileToByteArray(new File(documentTwoFile)); bodyTwo = new BasicDocumentBody(jsonData); }
From source file:com.jaxio.celerio.output.FolderSourceFile.java
@Override public byte[] getContent(String pathToFile) { try {/*from w ww. ja v a 2 s . c o m*/ return FileUtils.readFileToByteArray(new File(getFullPath(pathToFile))); } catch (IOException e) { log.warn("could not read content: " + pathToFile, e); return new byte[0]; } }
From source file:com.feedzai.fos.impl.weka.utils.ClonerTest.java
@Test public void fromByteArrayTest() throws IOException, ClassNotFoundException { Cloner<Classifier> cloner = new Cloner<Classifier>( FileUtils.readFileToByteArray(new File("target/test-classes/models/test.model"))); Classifier serializable1 = cloner.get(); Classifier serializable2 = cloner.get(); Assert.assertNotSame(serializable1, serializable2); }
From source file:com.sastix.cms.server.services.content.ZipFileHandlerServiceTest.java
@Before public void setUp() throws IOException { bytesDemoContentZipFile = FileUtils.readFileToByteArray(Paths.get(demoContentZipFile.getFile()).toFile()); bytesDemoContentZipFileNoScorm = FileUtils .readFileToByteArray(Paths.get(demoContentZipFileNoScorm.getFile()).toFile()); }
From source file:com.playonlinux.core.utils.archive.TarTest.java
@Test public void testUncompress_withSymbolicLinks() throws IOException { final File inputFile = new File(inputUrl.getPath(), "tarLink.tar.gz"); final File temporaryDirectory = Files.createTempDir(); temporaryDirectory.deleteOnExit();/*w w w . j a v a 2s . c om*/ final List<File> extractedFiles = new Extractor().uncompress(inputFile, temporaryDirectory); final File file1 = new File(temporaryDirectory, "file1.txt"); final File file2 = new File(temporaryDirectory, "file1_link.txt"); assertTrue(file1.exists()); assertTrue(file2.exists()); assertEquals("file1content", new String(FileUtils.readFileToByteArray(file1))); assertEquals("file1content", new String(FileUtils.readFileToByteArray(file2))); assertTrue(java.nio.file.Files.isSymbolicLink(Paths.get(file2.getPath()))); }
From source file:com.fibon.maven.confluence.AddAttachmentConfluenceMojo.java
private void addAttachment(String token, Long pageId, File file) throws MojoFailureException { RemoteAttachment attachment = new RemoteAttachment(); attachment.setPageId(pageId);//from w ww. java 2 s . c om attachment.setComment(comment); attachment.setFileName(file.getName()); try { byte[] content = FileUtils.readFileToByteArray(file); String type = MimeUtil.getMimeTypes(file).iterator().next().toString(); attachment.setContentType(type); attachment = getClient().getService().addAttachment(token, attachment, content); } catch (Exception e) { throw fail("Unable to upload attachment", e); } }
From source file:com.mirth.connect.server.userutil.FileUtil.java
/** * Returns the contents of the file as a byte array. * // w ww.ja v a2s .c o m * @see org.apache.commons.io.FileUtils#readFileToByteArray(File) * @param fileName * The pathname string of the file to read from. * @return The byte array representation of the file. * @throws IOException */ public static byte[] readBytes(String fileName) throws IOException { return FileUtils.readFileToByteArray(new File(fileName)); }