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.joyent.manta.client.crypto.SecretKeyUtilsTest.java
public void canLoadKeyFromURIPath() throws IOException { File file = File.createTempFile("ciphertext-", ".data"); FileUtils.forceDeleteOnExit(file);//from www. j a v a 2 s.c o m FileUtils.writeByteArrayToFile(file, keyBytes); URI uri = file.toURI(); SecretKey expected = SecretKeyUtils.loadKey(keyBytes, AesGcmCipherDetails.INSTANCE_128_BIT); SecretKey actual = SecretKeyUtils.loadKeyFromPath(Paths.get(uri), AesGcmCipherDetails.INSTANCE_128_BIT); Assert.assertEquals(actual.getAlgorithm(), expected.getAlgorithm()); Assert.assertTrue(Arrays.equals(expected.getEncoded(), actual.getEncoded()), "Secret key loaded from URI doesn't match"); }
From source file:com.edmunds.etm.agent.impl.ProcessController.java
@Override public void writeRuleSetData(byte[] ruleSetData) { File configFile = new File(agentConfig.getFilePath()); try {/*w ww . ja v a 2 s . c o m*/ FileUtils.writeByteArrayToFile(configFile, ruleSetData); } catch (IOException e) { String message = String.format("Could not write configuration file at path %s", agentConfig.getFilePath()); logger.error(message, e); throw new RuntimeException(message, e); } }
From source file:com.joyent.manta.config.ConfigContextTest.java
public void canValidateContextWithKeyPaths() throws IOException { File mantaAuthPrivateKey = File.createTempFile("manta-key", ""); FileUtils.forceDeleteOnExit(mantaAuthPrivateKey); FileUtils.write(mantaAuthPrivateKey, UnitTestConstants.PRIVATE_KEY, StandardCharsets.US_ASCII); File encryptionPrivateKey = File.createTempFile("encryption-key", ""); FileUtils.forceDeleteOnExit(encryptionPrivateKey); FileUtils.writeByteArrayToFile(encryptionPrivateKey, keyBytes); StandardConfigContext config = new StandardConfigContext(); config.setMantaURL(DefaultsConfigContext.DEFAULT_MANTA_URL); config.setMantaUser("username"); config.setMantaKeyId(UnitTestConstants.FINGERPRINT); config.setMantaKeyPath(mantaAuthPrivateKey.getAbsolutePath()); config.setClientEncryptionEnabled(true); config.setEncryptionKeyId("test-key-1"); config.setEncryptionAuthenticationMode(EncryptionAuthenticationMode.DEFAULT_MODE); config.setPermitUnencryptedDownloads(false); config.setEncryptionPrivateKeyPath(encryptionPrivateKey.getAbsolutePath()); config.setEncryptionAlgorithm(AesGcmCipherDetails.INSTANCE_128_BIT.getCipherId()); ConfigContext.validate(config);//from w w w. ja v a2s . co m }
From source file:com.hp.application.automation.tools.octane.tests.CopyResourceSCM.java
@Override public boolean checkout(AbstractBuild<?, ?> build, Launcher launcher, FilePath workspace, BuildListener listener, File changeLogFile) throws IOException, InterruptedException { if (workspace.exists()) { listener.getLogger().println("Deleting existing workspace " + workspace.getRemote()); workspace.deleteRecursive();//from w ww . j av a 2 s. c om } Resource[] resources = new PathMatchingResourcePatternResolver().getResources("classpath*:" + path + "/**"); for (Resource resource : resources) { if (resource.exists() && resource.isReadable()) { String urlString = resource.getURL().toExternalForm(); String targetName = urlString.substring(urlString.indexOf(path) + path.length()); byte[] fileContent = IOUtils.toByteArray(resource.getInputStream()); FileUtils.writeByteArrayToFile(new File(new File(workspace.getRemote(), targetPath), targetName), fileContent); } } return true; }
From source file:edu.mayo.xsltserver.FileService.java
/** * Store an artifact to disk.// w w w . ja va 2 s . c o m * * @param name the name * @param bytes the bytes * @throws IOException Signals that an I/O exception has occurred. */ public void store(String name, byte[] bytes) throws IOException { FileUtils.writeByteArrayToFile(new File(storageDirectory + File.separator + name), bytes); }
From source file:com.offbynull.coroutines.mavenplugin.AbstractInstrumentMojo.java
/** * Instruments all classes in a path recursively. * @param log maven logger/*from ww w.j av a 2 s . 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:glluch.com.ontotaxoseeker.TestsGen.java
public void FindPaths_StringResults() throws IOException { System.out.println("TaxoPath findPaths"); String doc = TestsGen.DOC;/*ww w . j a v a 2s.c om*/ TaxoPath instance = new TaxoPath(); PathsCount result = instance.findPaths(doc); TermsCount res = result.conceptsCount(); File target = new File("resources/test/FindPaths_StringResults.bin"); byte[] vs = SerializationUtils.serialize(res); FileUtils.writeByteArrayToFile(target, vs); }
From source file:com.portal.service.SimplePortalService.java
@Override public void saveFile(String fileName, MultipartFile file) throws Exception { try {/* w w w . j a v a 2 s . c o m*/ FileUtils.writeByteArrayToFile(new File(fileName), file.getBytes()); } catch (IOException ex) { throw new PortalException("? ? ? "); } }
From source file:com.feedzai.fos.api.util.ManagerUtils.java
/** * Creates a file in {@code <location>/<id>.model} and serializes the given byte array to it. * * @param location The target location where the binary will be written to. * @param id The UUID of the model. * @param model The serialized classifier. * @return The File where the model was written to. * @throws java.io.IOException if saving to disk was not possible. *//*from w w w. j av a 2 s .c o m*/ private static File createModelBinaryFile(File location, UUID id, byte[] model) throws IOException { File file = File.createTempFile(id.toString(), ".model", location); FileUtils.writeByteArrayToFile(file, model); return file; }
From source file:com.frostwire.platform.DefaultFileSystem.java
@Override public boolean write(File file, byte[] data) { try {/* ww w . jav a 2 s. c o m*/ FileUtils.writeByteArrayToFile(file, data); return true; } catch (Throwable e) { LOG.error("Error in writing to file: " + file, e); } return false; }