List of usage examples for org.apache.commons.io FileUtils readFileToByteArray
public static byte[] readFileToByteArray(File file) throws IOException
From source file:com.sonymobile.tools.gerrit.gerritevents.ssh.SshUtil.java
/** * Parses the keyFile hiding any Exceptions that might occur. * @param keyFile the file.//from w ww . j a v a 2 s.com * @return the "parsed" file. */ private static SshPrivateKeyFile parsePrivateKeyFile(File keyFile) { try { byte[] data = FileUtils.readFileToByteArray(keyFile); SshPrivateKeyFile key = SshPrivateKeyFileFactory.parse(data); return key; } catch (Exception ex) { return null; } }
From source file:FeatureExtraction.FeatureExtractorNgramsByte.java
/** * Return list of n-grams (and occurrences) extracted from the given source * * @param element the type of object represent the element that the features * should be extracted from// w ww . j av a 2s . c om * @return list of n-grams (and occurrences) extracted from the given source */ @Override public Map<String, Integer> ExtractFeaturesFrequencyFromSingleElement(T element) { Map<String, Integer> ngrams = new HashMap<>(); String filePath = (String) element; File file = new File(filePath); if (file.exists()) { try { byte[] fileBytes = FileUtils.readFileToByteArray(file); String ngram = ""; for (int i = 0; i <= fileBytes.length - m_grams; i = i + m_skip) { for (int j = 0; j < m_grams; j++) { ngram += (char) fileBytes[i + j]; } if (!ngrams.containsKey(ngram)) { ngrams.put(ngram, 1); } else { ngrams.put(ngram, ngrams.get(ngram) + 1); } ngram = ""; } } catch (IOException e) { Console.PrintException( String.format("Error extracting Byte n-grams features from file: %s", filePath), e); } } return ngrams; }
From source file:name.martingeisse.esdk.picoblaze.simulator.instruction.PicoblazeInstructionMemory.java
/** * Creates a {@link PicoblazeInstructionMemory} instance from a .psmbin file. * @param file the file to load//from w w w . j a v a 2 s. c o m * @return the memory instance * @throws IOException on I/O errors */ public static PicoblazeInstructionMemory createFromPsmBinFile(File file) throws IOException { byte[] encodedInstructions = FileUtils.readFileToByteArray(file); int[] instructions = PsmBinUtil.decodePsmBin(encodedInstructions); return new PicoblazeInstructionMemory(instructions); }
From source file:com.sangupta.andruil.commands.base.AbstractHashCommand.java
/** * @see com.sangupta.andruil.commands.base.AbstractMultiFileCommand#processFile(java.io.File) *///from www . j a va 2s. co m @Override protected boolean processFile(File file) throws IOException { if (file.isDirectory()) { return true; } 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:name.martingeisse.esdk.model.picoblaze.simulator.instruction.PicoblazeInstructionMemory.java
/** * Creates a {@link PicoblazeInstructionMemory} instance from a .psmbin file. * @param file the file to load//from ww w. j ava 2s . c om * @return the memory instance * @throws IOException on I/O errors */ public static PicoblazeInstructionMemory createFromPsmBinFile(final File file) throws IOException { final byte[] encodedInstructions = FileUtils.readFileToByteArray(file); final int[] instructions = PsmBinUtil.decodePsmBin(encodedInstructions); return new PicoblazeInstructionMemory(instructions); }
From source file:gerenciador.incubadora.controller.ArquivoController.java
@RequestMapping(value = "/imagem/{id}") public ModelAndView download(HttpServletResponse response, @PathVariable Long id) throws FileNotFoundException, Exception { InputStream is = new ByteArrayInputStream( FileUtils.readFileToByteArray(new File(Empreendimento.EMPREENDIMENTO_PATH_LOGO_DEFAULT))); ModelAndView mv = new ModelAndView("redirect:/empreendedor"); Empreendimento empreendimento = ServiceLocator.getEmpreendimentoService().readById(id); mv.addObject("empreendimento", empreendimento); //is.close(); response.setContentType("image/jpeg"); IOUtils.copy(is, response.getOutputStream()); response.flushBuffer();/*w ww.j av a2s . c o m*/ if (response.isCommitted()) { System.out.println("Resposta Comitada!"); } return new ModelAndView("empreendimento/new"); }
From source file:net.grinder.util.LogCompressUtilTest.java
@Test public void testLogCompressDecompress() throws IOException { File file = new File(LogCompressUtilTest.class.getResource("/grinder1.properties").getFile()); byte[] zippedContent = LogCompressUtils.compress(file); File createTempFile2 = File.createTempFile("a22aa", ".zip"); createTempFile2.deleteOnExit();// w ww . j a v a 2s . c om FileUtils.writeByteArrayToFile(createTempFile2, zippedContent); File createTempFile = File.createTempFile("a22", "tmp"); LogCompressUtils.decompress(zippedContent, createTempFile); assertThat(createTempFile.exists(), is(true)); byte[] unzippedContent = FileUtils.readFileToByteArray(createTempFile); assertThat(unzippedContent, is(FileUtils.readFileToByteArray(file))); }
From source file:ezbake.deployer.cli.commands.DeployTarCommand.java
@Override public void call() throws IOException, TException, DeploymentException { String[] args = globalParameters.unparsedArgs; minExpectedArgs(1, args, this); String prefix = trimNamePrefix(args[0]); final File manifest = new File(prefix + "-manifest.yml"); final File artifact = new File(prefix + ".tar.gz"); ArtifactManifest artifactManifest = readManifestFile(manifest).get(0); byte[] artifactBuffer = FileUtils.readFileToByteArray(artifact); getClient().deployService(artifactManifest, ByteBuffer.wrap(artifactBuffer), getSecurityToken()); }
From source file:de.undercouch.gradle.tasks.download.OfflineTest.java
/** * Test if the task is skipped if we're in offline mode * @throws Exception if anything goes wrong *///from ww w . j a v a 2 s . co m @Test public void offlineSkip() throws Exception { Download t = makeProjectAndTask(); t.getProject().getGradle().getStartParameter().setOffline(true); t.src(makeSrc(TEST_FILE_NAME)); // create empty destination file File dst = folder.newFile(); t.dest(dst); t.execute(); // file should still be empty byte[] dstContents = FileUtils.readFileToByteArray(dst); assertArrayEquals(new byte[0], dstContents); }
From source file:net.nicholaswilliams.java.licensing.encryption.KeyFileUtilities.java
protected static PublicKey readEncryptedPublicKey(File file, char[] passphrase) throws IOException { return KeyFileUtilities.readEncryptedPublicKey(FileUtils.readFileToByteArray(file), passphrase); }