List of usage examples for org.apache.commons.io FileUtils writeByteArrayToFile
public static void writeByteArrayToFile(File file, byte[] data) throws IOException
From source file:org.dkf.jed2k.android.DefaultFileSystem.java
@Override public boolean write(File file, byte[] data) { try {//from w ww . j a v a 2 s .c om FileUtils.writeByteArrayToFile(file, data); return true; } catch (Exception e) { LOG.error("Error in writing to file: {} {}", file, e); } return false; }
From source file:org.dkf.jed2k.android.LollipopFileSystem.java
@Override public boolean write(File file, byte[] data) { try {/*from w w w . jav a2s . c o m*/ FileUtils.writeByteArrayToFile(file, data); return true; } catch (IOException e) { // ignore } DocumentFile f = getFile(app, file, true); if (f == null) { LOG.error("Unable to obtain document for file: ", file); return false; } return write(app, f, data); }
From source file:org.eclipse.emf.teneo.internal.utils.EmfMavenFileCreator.java
private void process() throws Exception { final String outDirPath = BASE_DIR + dirName + File.separator; final String sourceDirPath = outDirPath + PLUGINS_DIR + File.separator; final File mainDir = new File(outDirPath + PLUGINS_DIR); // clear all files for (File file : new File(BASE_DIR + dirName).listFiles()) { if (file.getName().endsWith(".jar") || file.getName().endsWith(".pom")) { file.delete();/* www . j av a 2s. c o m*/ } } for (String plugin : plugins) { for (File file : mainDir.listFiles()) { final String fileName = file.getName(); if (ignoreFile(fileName, plugin)) { continue; } final String version = getVersion(plugin, fileName); final String groupId; if (plugin.contains(".xsd")) { groupId = "org.eclipse.xsd"; } else { groupId = "org.eclipse.emf"; } // copy the plugin itself copyFile(sourceDirPath + fileName, outDirPath + plugin + "-" + version + ".jar"); // copy the source final String sourceOriginFileName = fileName.replace("_", ".source_"); copyFile(sourceDirPath + sourceOriginFileName, outDirPath + plugin + "-" + version + "-sources.jar"); // copy the javadoc template copyResource(JAVADOC_TEMPLATE_JAR_FILE, outDirPath + plugin + "-" + version + "-javadoc.jar"); // copy the pom File pomTemplate = (new File(this.getClass().getResource(POM_TEMPLATE_FILE).toURI())); String pom = new String(FileUtils.readFileToString(pomTemplate, Charset.defaultCharset())); pom = pom.replace("${version}", version); pom = pom.replace("${name}", plugin); pom = pom.replace("${artifactId}", plugin); pom = pom.replace("${groupId}", groupId); FileUtils.writeByteArrayToFile(new File(outDirPath + plugin + "-" + version + ".pom"), pom.getBytes()); if (isSnapShot()) { System.err.println("<deploy.snapshot name=\"" + plugin + "\" version=\"" + version + "\" jarFileLocation=\"${mainLocation}/" + dirName + "\"/>"); } else { System.err.println("<deploy.staging name=\"" + plugin + "\" version=\"" + version + "\" jarFileLocation=\"${mainLocation}/" + dirName + "\"/>"); } } } }
From source file:org.eclipse.orion.server.tests.servlets.xfer.TransferTest.java
@Test public void testImportFileMultiPart() throws CoreException, IOException, SAXException, URISyntaxException { //create a directory to upload to String directoryPath = "sample/directory/path" + System.currentTimeMillis(); createDirectory(directoryPath);//ww w . j ava 2s . c om URL entry = ServerTestsActivator.getContext().getBundle().getEntry("testData/importTest/client.zip"); File source = new File(FileLocator.toFileURL(entry).getPath()); // current server implementation cannot handle binary data, thus base64-encode client.zip before import File expected = EFS.getStore(makeLocalPathAbsolute(directoryPath + "/expected.txt")).toLocalFile(EFS.NONE, null); byte[] expectedContent = Base64.encode(FileUtils.readFileToByteArray(source)); FileUtils.writeByteArrayToFile(expected, expectedContent); //start the import long length = expectedContent.length; String importPath = getImportRequestPath(directoryPath); PostMethodWebRequest request = new PostMethodWebRequest(importPath); request.setHeaderField("X-Xfer-Content-Length", Long.toString(length)); request.setHeaderField("X-Xfer-Options", "raw"); request.setHeaderField("Slug", "actual.txt"); setAuthentication(request); WebResponse postResponse = webConversation.getResponse(request); assertEquals(HttpURLConnection.HTTP_OK, postResponse.getResponseCode()); String location = postResponse.getHeaderField("Location"); assertNotNull(location); URI importURI = URIUtil.fromString(importPath); location = importURI.resolve(location).toString(); // perform the upload doImport(expected, length, location, "multipart/mixed;boundary=foobar"); //assert the file is present in the workspace assertTrue(checkFileExists(directoryPath + "/actual.txt")); //assert that actual.txt has same content as expected.txt assertTrue(checkContentEquals(expected, directoryPath + "/actual.txt")); }
From source file:org.eclipse.smila.binarystorage.persistence.io.BssIOUtils.java
/** * Saves array of bytes into file./*from w ww . j a va 2 s .c o m*/ * * @param path * @param data * @throws BinaryStorageException */ public static void writeByteArrayToFile(final String path, final byte[] data) throws BinaryStorageException { final File record = mkdirForFileRecord(path); try { FileUtils.writeByteArrayToFile(record, data); } catch (final IOException ioe) { throw new BinaryStorageException(ioe, "Could not write binary record to :" + path); } }
From source file:org.eclipse.smila.blackboard.impl.TransientBlackboardImpl.java
/** * {@inheritDoc}/* www . java2 s . c om*/ * * @throws BlackboardAccessException */ @Override public File getAttachmentAsFile(final String id, final String name) throws BlackboardAccessException { synchronized (_attachmentMap) { File attachmentFile = null; if (_attachmentMap.get(id) != null) { attachmentFile = _attachmentMap.get(id).get(name); if (attachmentFile != null) { return attachmentFile; } } try { attachmentFile = new File(_attachmentsTempDir, getAttachmentId(id, name)); FileUtils.writeByteArrayToFile(attachmentFile, getAttachment(id, name)); // put attachment into cache Map<String, File> recordAtttachmentFiles = _attachmentMap.get(id); if (recordAtttachmentFiles == null) { recordAtttachmentFiles = new HashMap<String, File>(); } recordAtttachmentFiles.put(name, attachmentFile); _attachmentMap.put(id, recordAtttachmentFiles); } catch (final IOException ex) { throw new BlackboardAccessException("Error getting attachment as file, record id: " + id, ex); } return attachmentFile; } }
From source file:org.eclipse.thym.core.internal.util.BundleHttpCacheStorage.java
@Override public void putEntry(String key, HttpCacheEntry entry) throws IOException { ByteArrayOutputStream byteArrayOS = null; ObjectOutputStream objectOut = null; try {/*from w ww .j a v a 2 s.co m*/ File f = getCacheFile(key); byteArrayOS = new ByteArrayOutputStream(); objectOut = new ObjectOutputStream(byteArrayOS); objectOut.writeObject(entry); objectOut.flush(); FileUtils.writeByteArrayToFile(f, byteArrayOS.toByteArray()); } finally { if (objectOut != null) objectOut.close(); if (byteArrayOS != null) byteArrayOS.close(); } }
From source file:org.ednovo.gooru.application.converter.GooruImageUtil.java
public static void scaleImage(ByteArrayInputStream sourceImageStream, int width, int height, File destFile) throws Exception { ByteArrayOutputStream thumbnailBaos = new ByteArrayOutputStream(); Thumbnails.of(sourceImageStream).forceSize(width, height).outputFormat(PNG).toOutputStream(thumbnailBaos); FileUtils.writeByteArrayToFile(destFile, thumbnailBaos.toByteArray()); }
From source file:org.ednovo.gooru.application.util.GooruImageUtil.java
public static void scaleImageUsingCoolbird(ByteArrayInputStream sourceImageStream, int width, int height, String destFilePath) throws Exception { ByteArrayOutputStream thumbnailBaos = new ByteArrayOutputStream(); Thumbnails.of(sourceImageStream).forceSize(width, height).outputFormat(getFileExtenstion(destFilePath)) .toOutputStream(thumbnailBaos); FileUtils.writeByteArrayToFile(new File(destFilePath), thumbnailBaos.toByteArray()); }
From source file:org.efaps.admin.program.esjp.EFapsClassLoader.java
/** * In case of jbpm this is necessary for compiling, * because they search the classes with URL. * @param _name filename as url/* w w w .j av a 2 s . c o m*/ * @return URL if found */ @Override public URL findResource(final String _name) { URL ret = null; final String name = _name.replaceAll(System.getProperty("file.separator"), ".").replaceAll(".class", ""); final byte[] data = loadClassData(name); if (data != null && data.length > 0) { final File file = FileUtils.getFile(EFapsClassLoader.getTempFolder(), name); try { if (!file.exists() || FileUtils.isFileOlder(file, new DateTime().minusHours(1).toDate())) { FileUtils.writeByteArrayToFile(file, data); } ret = file.toURI().toURL(); } catch (final IOException e) { LOG.error("Could not geneate File for reading from URL: {}", name); } } return ret; }