List of usage examples for org.apache.commons.io IOUtils toByteArray
public static byte[] toByteArray(String input) throws IOException
String
as a byte[]
using the default character encoding of the platform. From source file:io.hakbot.providers.shell.ShellProvider.java
public boolean process(Job job) { try (InputStream inputStream = process.getInputStream(); InputStream errorStream = process.getErrorStream()) { final ProcessBuilder pb = new ProcessBuilder(command.split(" ")); process = pb.start();/* www. j av a 2s. co m*/ final int exitCode = process.waitFor(); final byte[] stdout = IOUtils.toByteArray(inputStream); final byte[] stderr = IOUtils.toByteArray(errorStream); if (LOGGER.isDebugEnabled()) { LOGGER.debug("STDOUT:"); LOGGER.debug(new String(stdout)); LOGGER.debug("STDERR:"); LOGGER.debug(new String(stderr)); } if (exitCode == 0) { addArtifact(job, JobArtifact.Type.PROVIDER_RESULT, JobArtifact.MimeType.PLAIN_TEXT.value(), stdout, "Console-STDOUT-" + job.getUuid() + ".txt"); } else { if (stdout.length == 0) { addArtifact(job, JobArtifact.Type.PROVIDER_RESULT, JobArtifact.MimeType.PLAIN_TEXT.value(), stderr, "Console-STDERR-" + job.getUuid() + ".txt"); } else { addArtifact(job, JobArtifact.Type.PROVIDER_RESULT, JobArtifact.MimeType.PLAIN_TEXT.value(), stdout, "Console-STDOUT-" + job.getUuid() + ".txt"); } throw new JobException(exitCode); } return true; } catch (IOException | InterruptedException e) { addProcessingMessage(job, "Could not execute job."); addProcessingMessage(job, e.getMessage()); } catch (JobException e) { addProcessingMessage(job, "Job terminated abnormally. Exit code: " + e.getExitCode()); addProcessingMessage(job, e.getMessage()); } return false; }
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 a va 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:name.martingeisse.servlet_httpclient.sidekicks.fakecdn.FakeCdn.java
/** * // w w w. ja va 2s . co m */ private FakeCdnRecord fetch(String key) throws IOException { HttpResponse response = fetchResponse("http://localhost/foo" + key); byte[] data; try (InputStream responseStream = response.getEntity().getContent()) { data = IOUtils.toByteArray(responseStream); } return new FakeCdnRecord(response.getStatusLine().getStatusCode(), key, response.getFirstHeader("Content-Type").getValue(), data); }
From source file:edu.eci.pdsw.samples.managedbeans.EstudianteBean.java
public void handleFileUpload(FileUploadEvent event) throws IOException { file = event.getFile();/* ww w.j a v a 2 s.co m*/ byte[] img = IOUtils.toByteArray(file.getInputstream()); this.ima = new Image(img, String.valueOf(numero_identificacion)); if (img != null) { facesMessage("Foto Exitosamente Cargada"); } else { facesMessage("Cargue de nuevo la foto"); } }
From source file:com.abixen.platform.core.interfaces.web.common.ImageLibraryController.java
@RequestMapping(value = "layout/{fileName}/", method = RequestMethod.GET) public ResponseEntity<byte[]> getImage(@PathVariable String fileName) throws IOException { log.debug("fileName: " + fileName); InputStream in;/*from w w w . j av a 2s . co m*/ try { in = new FileInputStream(platformResourceConfigurationProperties.getImageLibraryDirectory() + "/layout-miniature/" + fileName); } catch (FileNotFoundException e) { in = new FileInputStream(platformResourceConfigurationProperties.getImageLibraryDirectory() + "/layout-miniature/default-layout-icon.png"); } byte[] b = IOUtils.toByteArray(in); in.close(); final HttpHeaders headers = new HttpHeaders(); headers.setContentType(MediaType.IMAGE_PNG); return new ResponseEntity<byte[]>(b, headers, HttpStatus.CREATED); }
From source file:at.gv.egiz.bku.slcommands.impl.cms.ReferencedHashDataInput.java
public InputStream getHashDataInput() throws IOException { InputStream hashDataInputStream = urlDereferencer.dereference(urlReference).getStream(); try {/* ww w . ja v a2 s.c o m*/ byte[] content = IOUtils.toByteArray(hashDataInputStream); if (excludedByteRange != null) { int from = excludedByteRange.getFrom().intValue(); int to = excludedByteRange.getTo().intValue(); byte[] signedContent = ArrayUtils.addAll(ArrayUtils.subarray(content, 0, from), ArrayUtils.subarray(content, to, content.length)); return new ByteArrayInputStream(signedContent); } else { return new ByteArrayInputStream(content); } } finally { hashDataInputStream.close(); } }
From source file:net.sourceforge.jaulp.file.read.ReadFileUtils.java
/** * Get a byte array from the given {@code InputStream}. * * @param input//from www . j a va 2s .c om * The {@code InputStream}. * @return the a byte array. * @throws NullPointerException if the input is null * @throws IOException * Signals that an I/O exception has occurred. */ public static byte[] toByteArray(InputStream input) throws IOException { return IOUtils.toByteArray(input); }
From source file:com.github.restdriver.clientdriver.unit.SecureClientDriverFactoryTest.java
static KeyStore getKeystore() throws Exception { ClassLoader loader = SecureClientDriverTest.class.getClassLoader(); byte[] binaryContent = IOUtils.toByteArray(loader.getResourceAsStream("keystore.jks")); KeyStore keyStore = KeyStore.getInstance("JKS"); keyStore.load(new ByteArrayInputStream(binaryContent), "password".toCharArray()); return keyStore; }
From source file:com.sysunite.weaver.nifi.GetXMLNodesTest.java
@Test public void testOnTrigger() { try {/*from w w w.jav a 2 s . com*/ 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:net.sf.jaceko.mock.util.FileReader.java
public byte[] readBinaryFileContents(final String fileName) { try {/*from www. j a v a 2 s. c om*/ InputStream resourceAsStream = FileReader.class.getClassLoader().getResourceAsStream(fileName); return IOUtils.toByteArray(resourceAsStream); } catch (IOException e) { LOG.error("Problem reading file : " + fileName, e); return null; } }