List of usage examples for org.apache.commons.io FileUtils readFileToByteArray
public static byte[] readFileToByteArray(File file) throws IOException
From source file:com.sangupta.clitools.checksum.MD2.java
protected boolean processFile(File file) throws IOException { if (file.isDirectory()) { return true; }/*from w w w . j a v a 2s.c o m*/ byte[] bytes = FileUtils.readFileToByteArray(file); try { java.security.MessageDigest md = java.security.MessageDigest.getInstance(getAlgorithmName()); byte[] array = md.digest(bytes); StringBuilder sb = new StringBuilder(); for (int i = 0; i < array.length; ++i) { sb.append(Integer.toHexString((array[i] & 0xFF) | 0x100).substring(1, 3)); } System.out.println(sb.toString() + " *" + file.getName()); } catch (java.security.NoSuchAlgorithmException e) { // do nothing System.out.println("No " + getAlgorithmName() + " implementation available"); return false; } return true; }
From source file:com.thoughtworks.go.security.CipherProvider.java
private void primeKeyCache() { if (cachedKey == null) { File cipherFile = environment.getCipherFile(); synchronized (cipherFile.getAbsolutePath().intern()) { if (cachedKey == null) { try { if (cipherFile.exists()) { cachedKey = FileUtils.readFileToByteArray(cipherFile); return; }/*from ww w .j a v a 2 s. com*/ byte[] newKey = generateKey(); FileUtils.writeByteArrayToFile(cipherFile, newKey); LOGGER.info("Cipher not found. Creating a new cipher file"); cachedKey = newKey; } catch (IOException e) { throw new RuntimeException(e); } } } } }
From source file:de.saly.json.jsr353.benchmark.data.Buffers.java
private static byte[] readBytes(final int count, final Charset charset) { try {/* w w w .j a va 2 s . co m*/ return FileUtils.readFileToByteArray(new File( "./generated/generated_benchmark_test_file_" + charset.name() + "_" + count + ".json")); } catch (final IOException e) { return null; } }
From source file:com.haulmont.yarg.structure.impl.ReportTemplateBuilder.java
public ReportTemplateBuilder readFileFromPath() throws IOException { Preconditions.checkNotNull(reportTemplate.documentPath, "\"documentPath\" parameter is null. Can not load data from null path"); reportTemplate.documentContent = FileUtils.readFileToByteArray(new File(reportTemplate.documentPath)); return this; }
From source file:edu.umn.msi.tropix.common.io.FileUtilsImpl.java
public byte[] readFileToByteArray(final File file) { try {//from w w w . j a v a 2s. c o m return FileUtils.readFileToByteArray(file); } catch (final IOException e) { throw new IORuntimeException(e); } }
From source file:com.sysunite.weaver.nifi.GetXMLNodesTest.java
@Test public void testOnTrigger() { try {/* w w w . j a v a2s. c o m*/ String file = "inputTripleStore_Library.xml"; byte[] contents = FileUtils .readFileToByteArray(new File(getClass().getClassLoader().getResource(file).getFile())); InputStream in = new ByteArrayInputStream(contents); InputStream cont = new ByteArrayInputStream(IOUtils.toByteArray(in)); // Generate a test runner to mock a processor in a flow TestRunner runner = TestRunners.newTestRunner(new GetXMLNodes()); // Add properites runner.setProperty(GetXMLNodes.PROP_XPATH, "//Report/InFunctionalPhysicalObjects/FunctionalPhysicalObject"); // Add the content to the runner runner.enqueue(cont); // Run the enqueued content, it also takes an int = number of contents queued runner.run(); // All results were processed with out failure //runner.assertQueueEmpty(); // If you need to read or do aditional tests on results you can access the content List<MockFlowFile> results = runner.getFlowFilesForRelationship(GetXMLNodes.MY_RELATIONSHIP); //assertTrue("1 match", results.size() == 1); System.out.println("aantal gevonden: " + results.size()); //MockFlowFile result = results.get(0); //String resultValue = new String(runner.getContentAsByteArray(result)); //System.out.println("Match: " + IOUtils.toString(runner.getContentAsByteArray(result))); } catch (IOException e) { System.out.println("FOUT!!"); } }
From source file:de.mpg.imeji.logic.storage.transform.impl.SimpleAudioImageGenerator.java
@Override public byte[] generateJPG(File file, String extension) throws IOException, URISyntaxException { if (StorageUtils.getMimeType(extension).contains("audio")) { return FileUtils.readFileToByteArray( new File(XuggleImageGenerator.class.getClassLoader().getResource(PATH_TO_AUDIO_ICON).toURI())); }/*w w w .jav a2 s .com*/ return null; }
From source file:de.mpg.imeji.logic.storage.util.MediaUtils.java
/** * User imagemagick to convert any image into a jpeg * //from w w w. j ava 2 s. c om * @param bytes * @param extension * @throws IOException * @throws URISyntaxException * @throws InterruptedException * @throws IM4JavaException */ public static byte[] convertToJPEG(File tmp, String extension) throws IOException, URISyntaxException, InterruptedException, IM4JavaException { // In case the file is made of many frames, (for instance videos), generate only the frames from 0 to 48 to // avoid high memory consumption String path = tmp.getAbsolutePath() + "[0-48]"; ConvertCmd cmd = getConvert(); // create the operation, add images and operators/options IMOperation op = new IMOperation(); if (isImage(extension)) op.colorspace(findColorSpace(tmp)); op.strip(); op.flatten(); op.addImage(path); // op.colorspace("RGB"); File jpeg = File.createTempFile("uploadMagick", ".jpg"); try { op.addImage(jpeg.getAbsolutePath()); cmd.run(op); int frame = getNonBlankFrame(jpeg.getAbsolutePath()); if (frame >= 0) { File f = new File(FilenameUtils.getFullPath(jpeg.getAbsolutePath()) + FilenameUtils.getBaseName(jpeg.getAbsolutePath()) + "-" + frame + ".jpg"); return FileUtils.readFileToByteArray(f); } return FileUtils.readFileToByteArray(jpeg); } finally { removeFilesCreatedByImageMagick(jpeg.getAbsolutePath()); FileUtils.deleteQuietly(jpeg); } }
From source file:com.heliosdecompiler.helios.transformers.assemblers.KrakatauAssembler.java
@Override public byte[] assemble(String name, String contents) { if (Helios.ensurePython2Set()) { File tempFolder = null;//from w w w . ja v a 2s. c om File tempFile = null; String processLog = ""; try { tempFolder = Files.createTempDirectory("ka").toFile(); tempFile = new File(tempFolder, name.replace('/', File.separatorChar) + ".j"); FileUtils.write(tempFile, contents, "UTF-8", false); Process process = Helios .launchProcess(new ProcessBuilder(Settings.PYTHON2_LOCATION.get().asString(), "-O", "assemble.py", "-out", tempFolder.getAbsolutePath(), tempFile.getAbsolutePath()) .directory(Constants.KRAKATAU_DIR)); processLog = Utils.readProcess(process); return FileUtils.readFileToByteArray(new File(tempFile.toString().replace(".j", ".class"))); } catch (Exception e) { ExceptionHandler.handle(e); SWTUtil.showMessage(processLog); } finally { try { if (tempFolder != null) { FileUtils.deleteDirectory(tempFolder); } } catch (IOException e) { } if (tempFile != null) { tempFile.delete(); } } } else { SWTUtil.showMessage("You need to set Python!"); } return null; }
From source file:net.bpelunit.framework.control.deploy.activebpel.BPRDeployRequestEntity.java
@Override protected void populateMessage(SOAPMessage message) throws SOAPException, IOException { SOAPElement xmlDeployBpr = addRootElement(message, new QName(ACTIVEBPEL_ELEMENT_DEPLOYBPR)); // Add filename SOAPElement xmlBprFilename = xmlDeployBpr.addChildElement(ACTIVEBPEL_ELEMENT_ABPRFILENAME); xmlBprFilename.addAttribute(new QName(ActiveBPELRequestEntityBase.NS_XMLSCHEMA_INSTANCE, "type"), XSD_STRING);/*from ww w . j a v a 2 s. c o m*/ xmlBprFilename.setTextContent(FilenameUtils.getName(file.toString())); // Add data SOAPElement xmlBase64File = xmlDeployBpr.addChildElement(ACTIVEBPEL_ELEMENT_ABASE64FILE); xmlBase64File.addAttribute(new QName(ActiveBPELRequestEntityBase.NS_XMLSCHEMA_INSTANCE, "type"), XSD_STRING); StringBuilder content = new StringBuilder(); byte[] arr = FileUtils.readFileToByteArray(file); byte[] encoded = Base64.encodeBase64Chunked(arr); for (int i = 0; i < encoded.length; i++) { content.append((char) encoded[i]); } xmlBase64File.setTextContent(content.toString()); }