List of usage examples for org.apache.commons.io FileUtils readFileToByteArray
public static byte[] readFileToByteArray(File file) throws IOException
From source file:de.mpg.imeji.logic.storage.transform.impl.SimpleImageGenerator.java
@Override public byte[] generateJPG(File file, String extension) throws IOException { if (StorageUtils.getMimeType(extension).contains("image")) return ImageUtils.toJpeg(FileUtils.readFileToByteArray(file), StorageUtils.getMimeType(extension)); return null;//from w w w. java 2s . c om }
From source file:com.nidhinova.tools.ssh.SFTPClient.java
public SFTPClient(String hostname, String username, String password, String passphrase, File privateKeyfile) throws IOException { this.hostname = hostname; this.username = username; this.passphrase = this.str2byte(passphrase); this.privatekey = FileUtils.readFileToByteArray(privateKeyfile); this.userinfo = new JSchUserInfo(password, passphrase); }
From source file:com.ssn.ws.rest.request.SSNFaceRecognitionRequest.java
public SSNFaceRecognitionRequest(String filePath) { try {/* w w w .java 2 s . c om*/ parameters.put(API_KEY, API_KEY_VALUE); parameters.put(API_SECRET, API_SECRET_VALUE); parameters.put(NAME_SPACE, NAME_SPACE_VALUE); parameters.put(USER_ID, USER_ID_VALUE); File file = new File(filePath); byte[] bytes = FileUtils.readFileToByteArray(file); String encoded = Base64.encode(bytes); parameters.put(FILE_PARAM, encoded); } catch (IOException ex) { Logger.getLogger(SSNFaceRecognitionRequest.class.getName()).log(Level.SEVERE, null, ex); } }
From source file:com.cloudant.sync.datastore.BasicDBCoreObservableTest.java
@Test public void createDocument_bodyOnly_success() throws ConflictException, IOException, SQLException { this.core = new BasicDatastore(database_dir, "test"); this.database = this.core.getSQLDatabase(); this.jsonData = FileUtils.readFileToByteArray(new File(documentOneFile)); this.bodyOne = new BasicDocumentBody(jsonData); this.jsonData = FileUtils.readFileToByteArray(new File(documentTwoFile)); this.bodyTwo = new BasicDocumentBody(jsonData); this.testObserver = new TestObserver(core); this.core.getEventBus().register(testObserver); Assert.assertEquals(-1L, testObserver.getSequence()); DocumentRevision doc1 = core.createDocument(bodyOne); Assert.assertNotNull(doc1);/* ww w . j a v a2 s .c o m*/ Assert.assertEquals(1L, core.getLastSequence()); Assert.assertEquals(1L, testObserver.getSequence()); DocumentRevision doc2 = core.createDocument(bodyOne); Assert.assertNotNull(doc2); Assert.assertEquals(2L, core.getLastSequence()); Assert.assertEquals(2L, testObserver.getSequence()); DocumentRevision doc1_1 = core.updateDocument(doc1.getId(), doc1.getRevision(), bodyTwo); Assert.assertNotNull(doc1_1); Assert.assertEquals(3L, core.getLastSequence()); Assert.assertEquals(3L, testObserver.getSequence()); }
From source file:com.ewcms.publication.task.publish.SitePublishTest.java
private byte[] getContent() throws IOException { File file = new File(MultiSitePublishTest.class.getResource("write.jpg").getPath()); return FileUtils.readFileToByteArray(file); }
From source file:hext.HexView.java
private void updateFromFile() { try {/* w w w .j a v a 2 s . com*/ byte[] byteContent = FileUtils.readFileToByteArray(content); String hexContent = ""; int j = 0; int l = 0; for (int i = 0; i < byteContent.length; i++) { if (l > 31) { hexContent += "\n"; l = 0; j = 0; } if (j > 3) { hexContent += " "; j = 0; } hexContent += hexString(byteContent[i]); j++; l++; } String stringContent = FileUtils.readFileToString(content); stringContent = convert(stringContent); hexArea.setText(hexContent); textArea.setText(stringContent); } catch (IOException ex) { Logger.getLogger(HexView.class.getName()).log(Level.SEVERE, null, ex); } tab.setTitle(content.getName()); }
From source file:hudson.scm.credential.SslClientCertificateCredential.java
public SslClientCertificateCredential(File certificate, String password) throws IOException { this.password = Scrambler.scramble(password); this.certificate = Secret.fromString(new String(Base64.encode(FileUtils.readFileToByteArray(certificate)))); }
From source file:net.rptools.lib.FileUtil.java
/** * Reads the entire content of the given file into a byte array. * //from w ww. j a v a 2s. co m * @deprecated use {@link FileUtils#readFileToByteArray(File)} instead. * @param file * @return * @throws IOException */ @Deprecated public static byte[] getBytes(File file) throws IOException { return FileUtils.readFileToByteArray(file); }
From source file:io.wcm.devops.conga.plugins.aem.tooling.crypto.cli.AnsibleVault.java
private static void handleFile(File file, Function<byte[], byte[]> vaultHandler) throws IOException { if (!file.exists()) { throw new FileNotFoundException(file.getPath()); }//from w w w . ja va 2 s . c o m byte[] input = FileUtils.readFileToByteArray(file); byte[] output = vaultHandler.apply(input); file.delete(); FileUtils.writeByteArrayToFile(file, output); }
From source file:com.rom.jmultipatcher.Utils.java
public static long getCRC32(final String filepath, final int bytesBeforeEnd) throws IOException { final CRC32 sum_control = new CRC32(); final byte[] fileAsByteArray = FileUtils.readFileToByteArray(new File(filepath)); final byte[] copyOfRange = Arrays.copyOfRange(fileAsByteArray, 0, fileAsByteArray.length - bytesBeforeEnd); sum_control.update(copyOfRange);// w w w.j a v a 2 s .com return sum_control.getValue(); }