List of usage examples for org.apache.commons.io FileUtils writeByteArrayToFile
public static void writeByteArrayToFile(File file, byte[] data) throws IOException
From source file:com.edduarte.protbox.core.registry.PbxFile.java
/** * Sets the data of the file to the specified data. *//*from ww w . ja v a2s .c o m*/ public void writeSnapshotToFile(int index, File snapshotFile, FolderOption toFolder) throws ProtboxException { Snapshot snapshot; try { snapshot = snapshotStack.remove(index); snapshotStack.forcePush(snapshot); } catch (IndexOutOfBoundsException ex) { return; } try { if (toFolder.equals(FolderOption.SHARED)) { FileUtils.writeByteArrayToFile(snapshotFile, parentRegistry.encrypt(snapshot.getSnapshotData(), true)); } else { FileUtils.writeByteArrayToFile(snapshotFile, snapshot.getSnapshotData()); } snapshotFile.setLastModified(snapshot.getLastModifiedDate().getTime()); } catch (IOException ex) { throw new ProtboxException(ex); } }
From source file:net.nicholaswilliams.java.licensing.encryption.TestFilePrivateKeyDataProvider.java
@Test public void testGetEncryptedPrivateKeyData03() throws IOException { final String fileName = "testGetEncryptedPrivateKeyData03.key"; File file = new File(fileName); if (file.exists()) FileUtils.forceDelete(file);/*from w w w. j av a 2 s.c o m*/ byte[] data = new byte[] { 0x01, 0x71, 0x33 }; 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.blazarquant.bfp.core.parser.FixDefinitionProvidersFileStore.java
public void saveProviderFile(UserID userID, ProviderDescriptor providerDescriptor, byte[] content) throws IOException { File savedFile = new File(FixDefinitionProvidersFileUtility.getUserProvidersDir(userID), FixDefinitionProvidersFileUtility.createProviderFileName(providerDescriptor.getLoaderType(), providerDescriptor.getProviderName())); savedFile.getParentFile().mkdirs();//from ww w. j av a2s .co m FileUtils.writeByteArrayToFile(savedFile, content); }
From source file:com.feedzai.fos.impl.weka.utils.Cloner.java
/** * Writes the serialized object to file. * * @param file the file to write to (will be overwritten) * @throws IOException when the file could not be written *//*from w w w .j a v a2 s . c o m*/ public void write(File file) throws IOException { checkNotNull(file, "Output file cannot be null"); FileUtils.writeByteArrayToFile(file, serializedObject); }
From source file:com.jaspersoft.studio.dnd.DataAdapterDragSourceListener.java
private String createTemDataAdapterFile(final MDataAdapter dataAdapter) { try {/*from w ww.j av a 2 s . c om*/ File tempDirectory = FileUtils.getTempDirectory(); String tempDataAdapterFilePath = tempDirectory.getAbsolutePath() + "/" //$NON-NLS-1$ + StringUtils.deleteWhitespace(dataAdapter.getDisplayText()) + DATA_ADAPTER_FILE_EXT; File tempDataAdapterFile = new File(tempDataAdapterFilePath); if (tempDataAdapterFile.exists()) { // fallback solution tempDataAdapterFile = File.createTempFile(DATA_ADAPTER_FILE_PREFIX, DATA_ADAPTER_FILE_EXT); } JasperReportsConfiguration jrConfig = dataAdapter.getJasperConfiguration(); if (jrConfig == null) jrConfig = JasperReportsConfiguration.getDefaultInstance(); String xml = DataAdapterManager.toDataAdapterFile(dataAdapter.getValue(), jrConfig); FileUtils.writeByteArrayToFile(tempDataAdapterFile, xml.getBytes(ENCODING)); return tempDataAdapterFile.getAbsolutePath(); } catch (UnsupportedEncodingException e) { JaspersoftStudioPlugin.getInstance() .logError(NLS.bind(Messages.DataAdapterDragSourceListener_EncondingErrorMsg, ENCODING), e); } catch (IOException e) { JaspersoftStudioPlugin.getInstance().logError(Messages.DataAdapterDragSourceListener_IOErrorMsg, e); } return null; }
From source file:com.exalttech.trex.util.TrafficProfile.java
/** * @param binaryPacket//from w w w. j ava 2s .c o m * @throws java.io.IOException * @ * @return decodes the bytes array of a PCAP File using Base64 */ public File decodePcapBinary(String binaryPacket) throws IOException { byte[] decodedBytes = Base64.decodeBase64(binaryPacket); File pcapFile = File.createTempFile("temp-file-name", ".pcap"); FileUtils.writeByteArrayToFile(pcapFile, decodedBytes); return pcapFile; }
From source file:controllers.PropertyController.java
@RequestMapping("/updateFromXml") public String updateFromXml(Map<String, Object> model, @RequestParam(value = "propId", required = true) Long propId, @RequestParam(value = "xlsFile", required = false) MultipartFile file, RedirectAttributes ras) throws Exception { if (file == null || file.isEmpty()) { ras.addFlashAttribute("error", "File not found"); } else {/*from w w w. j a v a 2s . com*/ File newFile = new File("/usr/local/etc/Properties"); if (newFile.exists()) { newFile.delete(); } try { FileUtils.writeByteArrayToFile(newFile, file.getBytes()); propertyNameService.updateFromXml(newFile); ras.addFlashAttribute("error", propertyNameService.getResult().getErrors()); } catch (Exception e) { //ras.addFlashAttribute("error", "updateFromXml"+e.getMessage()); throw new Exception(StringAdapter.getStackTraceException(e)); } if (newFile.exists()) { newFile.delete(); } } ras.addAttribute("propId", propId); return "redirect:/PropertyName/show"; }
From source file:algorithm.F5Steganography.java
private String getPayloadPathString(File carrier, File payload) throws IOException { PayloadSegment payloadSegment = new PayloadSegment(carrier, payload, this); File payloadSemgentFile = new File("tmp"); FileUtils.writeByteArrayToFile(payloadSemgentFile, payloadSegment.getPayloadSegmentBytes()); return "" + payloadSemgentFile.toPath(); }
From source file:gov.nih.nci.firebird.service.file.FileServiceBeanTest.java
@BeforeClass public static void setupFile() throws IOException { byte[] data = "123".getBytes(); dataFile = File.createTempFile("test", ".blob"); FileUtils.writeByteArrayToFile(dataFile, data); }
From source file:algorithm.OaiOreSubmissionInformationPackage.java
@Override public File encapsulate(File carrier, List<File> userPayloadList) throws IOException { List<File> payloadList = new ArrayList<File>(); payloadList.addAll(userPayloadList); String mapName = ""; mapName = getOutputFileName(carrier); try {// w w w . j a v a 2 s .c om Aggregation informationPackage = OREFactory .createAggregation(new URI("http://www.pericles-project.eu/pericat/oai-ore-package")); informationPackage.addTitle( "PeriCAT - PERICLES Content Aggregation Tool created Oai-Ore sumbission information package"); informationPackage.createAggregatedResource(new URI( "http://www.pericles-project.eu/pericat/oai-ore-package/carrier-files/" + carrier.getName())); for (File payload : payloadList) { informationPackage.createAggregatedResource( new URI("http://www.pericles-project.eu/pericat/oai-ore-package/payload-files/" + payload.getName())); } ResourceMap resourceMap = informationPackage.createResourceMap( new URI("http://www.pericles-project.eu/pericat/oai-ore-package/resource-map/" + mapName + ".map.rdf.xml")); Agent creator = OREFactory.createAgent(); List<String> names = new ArrayList<String>(); names.add("PeriCAT"); creator.setNames(names); informationPackage.addCreator(creator); resourceMap.addCreator(creator); // serialising: ORESerialiser serialiser = ORESerialiserFactory.getInstance("RDF/XML"); ResourceMapDocument doc = serialiser.serialise(resourceMap); String serialisedMap = doc.toString(); File resourceMapFile = new File(mapName + ".map.rdf.xml"); FileUtils.writeByteArrayToFile(resourceMapFile, serialisedMap.getBytes()); payloadList.add(resourceMapFile); File outputFile = null; if (zipButton.isSelected()) { outputFile = new ZipPackaging().encapsulate(carrier, payloadList); } else if (tarButton.isSelected()) { outputFile = new TarPackaging().encapsulate(carrier, payloadList); } resourceMapFile.delete(); // was temporary return outputFile; } catch (OREException | URISyntaxException | ORESerialiserException e) { } return null; }