List of usage examples for org.apache.commons.io FileUtils writeByteArrayToFile
public static void writeByteArrayToFile(File file, byte[] data) throws IOException
From source file:it.anyplace.sync.core.cache.FileBlockCache.java
@Override public boolean pushData(final String code, final byte[] data) { try {//from w w w . ja v a2s. c o m writerThread.submit(new Runnable() { @Override public void run() { File file = new File(dir, code); if (!file.exists()) { try { FileUtils.writeByteArrayToFile(file, data); logger.debug("cached block {} to file {}", code, file); size += data.length; runCleanup(); } catch (IOException ex) { logger.warn("error writing block in cache", ex); FileUtils.deleteQuietly(file); } } } }); return true; } catch (Exception ex) { logger.warn("error caching block", ex); return false; } }
From source file:com.adaptris.hpcc.SprayToThor.java
private File saveFile(AdaptrisMessage msg, Object marker) throws ProduceException { File result = null;//ww w. ja v a 2 s . c om if (msg instanceof FileBackedMessage) { result = ((FileBackedMessage) msg).currentSource(); } else { // If the message is not file-backed, write it to a temp file try { if (getTempDirectory() != null) { result = File.createTempFile("adp", ".dat", new File(getTempDirectory())); } else { result = File.createTempFile("adp", ".dat"); } tracker.track(result, marker); FileUtils.writeByteArrayToFile(result, msg.getPayload()); } catch (IOException e) { throw new ProduceException("Unable to write temporary file", e); } } return result; }
From source file:gov.nih.nci.caarray.application.translation.geosoft.GeoSoftExporterBeanTest.java
private File writeTempFile(String name, String suffix) throws IOException { final File file = File.createTempFile(name, suffix); FileUtils.writeByteArrayToFile(file, TEST_DATA.getBytes()); return file;// ww w . j a va 2s . c o m }
From source file:com.disney.opa.fhb.util.FacilityUtil.java
/** * This method is to save the SQ document file to disk * /* ww w. j av a2 s.c o m*/ * @param document * @throws Exception */ public void saveSQDocumentOnServer(Document document, int productId) throws Exception { String fileNameOnServer = getSQDocumentFileNameOnServer(document, productId); String serverPath = getSQDocumentServerPath(fileNameOnServer); FileUtils.writeByteArrayToFile(new File(serverPath), document.getFile()); document.setFileNameOnServer(fileNameOnServer); document.setServerPath(serverPath); }
From source file:net.monofraps.gradlebukkit.tasks.DownloadCraftBukkit.java
private void downloadArtifact(final String url, final String referenceMd5) throws IOException, LifecycleExecutionException { getLogger().lifecycle("Going to download CraftBukkit from " + url); final HttpGet httpGet = new HttpGet(url); final HttpClient httpClient = HttpClientBuilder.create().build(); final HttpResponse httpResponse = httpClient.execute(httpGet); if (!bukkitServerJar.exists()) { if (!bukkitServerJar.createNewFile()) throw new LifecycleExecutionException("Failed to create bukkit server jar " + bukkitServerJar); }//from ww w. ja v a 2 s. co m final HttpEntity httpEntity = httpResponse.getEntity(); getLogger().lifecycle("Writing " + httpEntity.getContentLength() + " bytes to bukkit.jar"); final byte[] data = EntityUtils.toByteArray(httpEntity); FileUtils.writeByteArrayToFile(bukkitServerJar, data); final String localMd5 = DigestUtils.md5Hex(new FileInputStream(bukkitServerJar)); if (!localMd5.equals(referenceMd5)) { throw new LifecycleExecutionException("bukkit.jar MD5 sum mismatch. - Download failed."); } }
From source file:contact.Contact.java
/** * Create contact from WebDAV.//from w w w . ja va2 s .c o m */ public Contact(String strVCardData, String strFileOnDavServer, String strWorkingDir) { this.statusContact = Status.READIN; this.vcard = Ezvcard.parse(strVCardData).first(); this.strUid = this.vcard.getUid().getValue(); this.strFileOnDavServer = strFileOnDavServer; this.strEntryID = null; this.getContactAsString(); if (this.vcard.getPhotos().size() > 0) { Photo photo = this.vcard.getPhotos().get(0); byte[] photoData = photo.getData(); // data can be null if (photoData != null) { this.strPathToContactPicture = strWorkingDir + Math.random() + ".jpg"; File tmpFile = new File(strPathToContactPicture); try { FileUtils.writeByteArrayToFile(tmpFile, photoData); } catch (IOException e) { e.printStackTrace(); } } } this.dateLastModificationTme = this.vcard.getRevision().getValue(); }
From source file:controler.util.FileUtil.java
public static void CreateFileFromAnArrayOfBytes(byte[] bFile) throws IOException { File file = new File("E:\\testing.pdf"); FileUtils.writeByteArrayToFile(file, bFile);//au cas ou kan deja wahd lfichier blmeme nom+type katecrasiih }
From source file:net.nicholaswilliams.java.licensing.encryption.TestFilePublicKeyDataProvider.java
@Test public void testGetEncryptedPublicKeyData04() throws IOException { final String fileName = "testGetEncryptedPublicKeyData04.key"; File file = new File(fileName); if (file.exists()) FileUtils.forceDelete(file);//from ww w . j a v a 2 s. com byte[] data = new byte[] { 0x51, 0x12, 0x23 }; FileUtils.writeByteArrayToFile(file, data); try { FilePublicKeyDataProvider provider = new FilePublicKeyDataProvider(file); byte[] returnedData = provider.getEncryptedPublicKeyData(); assertNotNull("The data should not be null.", returnedData); assertArrayEquals("The data is not correct.", data, returnedData); } finally { FileUtils.forceDelete(file); } }
From source file:net.nicholaswilliams.java.licensing.encryption.TestFilePrivateKeyDataProvider.java
@Test public void testGetEncryptedPrivateKeyData04() throws IOException { final String fileName = "testGetEncryptedPrivateKeyData04.key"; File file = new File(fileName); if (file.exists()) FileUtils.forceDelete(file);/* w ww . j av a2s.com*/ byte[] data = new byte[] { 0x51, 0x12, 0x23 }; FileUtils.writeByteArrayToFile(file, data); try { FilePrivateKeyDataProvider provider = new FilePrivateKeyDataProvider(file); byte[] returnedData = provider.getEncryptedPrivateKeyData(); assertNotNull("The data should not be null.", returnedData); assertArrayEquals("The data is not correct.", data, returnedData); } finally { FileUtils.forceDelete(file); } }
From source file:com.adaptris.core.lms.StreamWrapperCase.java
private File writeFile(File f) throws IOException { FileUtils.writeByteArrayToFile(f, BYTES_TEXT); return f; }