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:be.solidx.hot.test.data.jdbc.TestPyAsyncCollectionApi.java
@Test public void testAsync() throws Exception { Map<String, Object> context = new HashMap<>(); context.put("db", db); context.put("adb", asyncDB); Script<CompiledScript> script = new Script<>( IOUtils.toByteArray( getClass().getResourceAsStream("/be/solidx/hot/test/data/jdbc/scripts/async-db.py")), "py-db"); PythonScriptExecutor executor = new PythonScriptExecutor(); executor.execute(script, context);/* ww w . j a v a 2s.co m*/ }
From source file:com.abixen.platform.core.controller.common.ImageLibraryController.java
@RequestMapping(value = "/{fileName}/", method = RequestMethod.GET) public ResponseEntity<byte[]> getImage(@PathVariable String fileName) throws IOException { log.debug("fileName: " + fileName); InputStream in = new FileInputStream(platformResourceConfigurationProperties.getImageLibraryDirectory() + "/layout-miniature/" + fileName); byte[] b = IOUtils.toByteArray(in); in.close();/*from w w w.j a va 2 s.c o m*/ final HttpHeaders headers = new HttpHeaders(); headers.setContentType(MediaType.IMAGE_PNG); return new ResponseEntity<byte[]>(b, headers, HttpStatus.CREATED); }
From source file:com.gargoylesoftware.htmlunit.WebResponseDataTest.java
/** * Tests that gzipped content is handled correctly. * @throws Exception if the test fails// w ww . j a v a2s . c om */ @Test public void gZippedContent() throws Exception { final InputStream stream = getClass().getClassLoader().getResourceAsStream(GZIPPED_FILE); final byte[] zippedContent = IOUtils.toByteArray(stream); final List<NameValuePair> headers = new ArrayList<>(); headers.add(new NameValuePair("Content-Encoding", "gzip")); final WebResponseData data = new WebResponseData(zippedContent, HttpStatus.SC_OK, "OK", headers); final String body = new String(data.getBody(), "UTF-8"); assertTrue(StringUtils.contains(body, "Test")); }
From source file:com.cloudera.cli.validator.components.DescriptorRunner.java
@Override public boolean run(String target, Writer writer) throws IOException { FileInputStream stream = null; try {/* w ww.j a v a 2 s.c o m*/ stream = new FileInputStream(target); return run(target, IOUtils.toByteArray(stream), writer); } catch (Exception e) { writer.write(String.format("==> %s\n", e.getMessage())); return false; } finally { IOUtils.closeQuietly(stream); } }
From source file:com.monarchapis.driver.servlet.ApiRequest.java
public ApiRequest(HttpServletRequest request) throws IOException { super(request); this.body = IOUtils.toByteArray(request.getInputStream()); requestId = StringUtils.replace(UUID.randomUUID().toString(), "-", ""); }
From source file:mx.com.quadrum.service.util.firma.ValidacionesCertificado.java
public ValidacionesCertificado(InputStream archivoClavePublica, InputStream archivoClavePrivada, String password) {//from ww w .j av a2 s . co m try { this.clavePrivada = IOUtils.toByteArray(archivoClavePrivada); this.clavePublica = IOUtils.toByteArray(archivoClavePublica); //this.clavePublica2=IOUtils.toString(archivoClavePublica); this.password = password; this.certificado = X509Certificate.getInstance(this.clavePublica); cerInputStream = archivoClavePublica; keyInputStream = archivoClavePrivada; //this.cadenaOriginal= cadenaOrigin; /* X509Certificate cert = X509Certificate.getInstance(this.clavePublica); boolean statusFecha; int statusFIEL=-1; boolean statusCorresp; boolean statusLCO; statusFecha=validaFecha(cert); System.out.println("\nel status fecha es: \n" + statusFecha); //statusFIEL=validaFIEL(cert); //System.out.println("el status FIEL es: " + statusFIEL); statusCorresp=validaCorrespondencias(); System.out.println("\nel status de que el .key y el .cer correspondan es: \n" + statusCorresp); statusLCO=validaLCO(); System.out.println("\nel status LCO es: \n" + statusLCO); */ } catch (Exception ea) { ea.printStackTrace(); } }
From source file:com.cloudera.csd.validation.SdlTestUtils.java
public static ServiceMonitoringDefinitionsDescriptor parseMDL(String path) { try {/*from w w w . j a v a 2 s. c om*/ InputStream stream = SdlTestUtils.class.getResourceAsStream(path); return MDL_PARSER.parse(IOUtils.toByteArray(stream)); } catch (IOException io) { throw new RuntimeException(io); } }
From source file:de.micromata.genome.util.collections.NewPropertiesLineReader.java
public void read(InputStream is, Charset charset) throws RuntimeIOException { try {/*from ww w .j a v a 2 s . c o m*/ byte[] cdata = IOUtils.toByteArray(is); String text = new String(cdata, charset); data = text.toCharArray(); parse(); } catch (IOException ex) { throw new RuntimeIOException(ex); } }
From source file:cn.guoyukun.spring.utils.fetch.RemoteFileFetcher.java
private void doFetch() { if (url == null) { return;/*from ww w . j a v a 2 s . c om*/ } LOGGER.info("Begin fetch remote file... url = {}", this.url); try { URL target = new URL(this.url); this.fileConent = IOUtils.toByteArray(target); this.lastModified = System.currentTimeMillis(); if (this.listener != null && this.fileConent != null) { this.listener.fileReloaded(this.fileConent); } } catch (Exception e) { LOGGER.error("read from url failed", e); } }
From source file:it.greenvulcano.gvesb.adapter.http.MultiReadHttpServletRequest.java
public MultiReadHttpServletRequest(HttpServletRequest request) throws IOException { super(request); //String method = request.getMethod(); //if (method.equals("POST") || method.equals("PUT")) { //if (request.getContentType().indexOf("application/x-www-form-urlencoded") != -1) { // Read the request body and save it as a byte array InputStream is = super.getInputStream(); body = IOUtils.toByteArray(is); //}/*from w w w . j a va2s.com*/ //} }