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:eu.unifiedviews.plugins.transformer.gzipper.GzipperTest.java
@Test public void execute() throws Exception { GzipperConfig_V1 config = new GzipperConfig_V1(); // Prepare DPU. Gzipper dpu = new Gzipper(); dpu.configure((new ConfigurationBuilder()).setDpuConfiguration(config).toString()); // Prepare test environment. TestEnvironment environment = new TestEnvironment(); // Prepare data unit. WritableFilesDataUnit filesOutput = environment.createFilesOutput("filesOutput"); WritableFilesDataUnit filesInput = environment.createFilesInput("filesInput"); File inputFile = new File(URI.create(filesInput.addNewFile("LICENSE"))); try (FileOutputStream fout = new FileOutputStream(inputFile)) { IOUtils.copy(Thread.currentThread().getContextClassLoader().getResourceAsStream("LICENSE"), fout); }/*from ww w. j a v a 2 s . c o m*/ try { // Run. environment.run(dpu); // Get file iterator. Set<FilesDataUnit.Entry> outputFiles = FilesHelper.getFiles(filesOutput); Assert.assertEquals(1, outputFiles.size()); FilesDataUnit.Entry entry = outputFiles.iterator().next(); byte[] outputContent = IOUtils.toByteArray( new GZIPInputStream(new FileInputStream(new File(new URI(entry.getFileURIString()))))); byte[] expectedContent = IOUtils .toByteArray(Thread.currentThread().getContextClassLoader().getResourceAsStream("LICENSE")); Assert.assertArrayEquals(expectedContent, outputContent); Assert.assertEquals("LICENSE.gz", VirtualPathHelpers.getVirtualPath(filesOutput, "LICENSE")); } finally { // Release resources. environment.release(); } }
From source file:be.solidx.hot.test.data.jdbc.TestJsCollectionApi.java
@Test public void testSync() throws Exception { JSScriptExecutor executor = new JSScriptExecutor(); Map<String, Object> context = new HashMap<>(); context.put("db", db); context.put("adb", new JSAsyncDB(db, Executors.newCachedThreadPool(), Executors.newSingleThreadExecutor(), executor.getGlobalScope())); executor.setGlobalScopeScripts(Arrays.asList("/js/qunit-1.14.js")); Script<org.mozilla.javascript.Script> script = new Script<>( IOUtils.toByteArray(getClass().getResourceAsStream("/be/solidx/hot/test/data/jdbc/scripts/db.js")), "db.js"); StringWriter out = new StringWriter(); executor.execute(script, context, out); Assert.assertFalse(out.toString().contains("FAIL")); }
From source file:io.swagger.inflector.processors.BinaryProcessor.java
@Override public Object process(MediaType mediaType, InputStream entityStream, Class<?> cls) throws ConversionException { try {//from ww w .j av a 2 s. com return IOUtils.toByteArray(entityStream); } catch (IOException e) { LOGGER.trace("unable to extract entity from content-type `" + mediaType + "` to byte[]", e); throw new ConversionException().message(new ValidationMessage().code(ValidationError.UNACCEPTABLE_VALUE) .message("unable to convert input to " + cls.getCanonicalName())); } }
From source file:net.javacrumbs.mocksocket.SampleTest.java
@Test public void testMultiple() throws Exception { byte[] mockData1 = new byte[] { 1, 2, 3, 4 }; byte[] mockData2 = new byte[] { 1, 2, 3, 4 }; expectCall().andReturn(data(mockData1)).andReturn(data(mockData2)); Socket socket1 = SocketFactory.getDefault().createSocket("example.org", 1234); byte[] data1 = IOUtils.toByteArray(socket1.getInputStream()); socket1.close();/* w ww . j av a 2 s .c o m*/ assertThat(data1, is(mockData1)); Socket socket2 = SocketFactory.getDefault().createSocket("example.org", 1234); byte[] data2 = IOUtils.toByteArray(socket2.getInputStream()); socket2.close(); assertThat(data2, is(mockData2)); }
From source file:be.solidx.hot.test.data.jdbc.TestJsAsyncCollectionApi.java
@Test public void testAsync() throws Exception { JSScriptExecutor executor = new JSScriptExecutor(); Map<String, Object> context = new HashMap<>(); context.put("db", db); context.put("adb", new JSAsyncDB(db, Executors.newCachedThreadPool(), Executors.newSingleThreadExecutor(), executor.getGlobalScope())); executor.setGlobalScopeScripts(Arrays.asList("/js/qunit-1.14.js")); Script<org.mozilla.javascript.Script> script = new Script<>( IOUtils.toByteArray( getClass().getResourceAsStream("/be/solidx/hot/test/data/jdbc/scripts/async-db.js")), "async-db.js"); StringWriter out = new StringWriter(); executor.execute(script, context, out); System.out.println(out.toString()); Assert.assertFalse(out.toString().contains("FAIL")); }
From source file:com.qubit.terra.docs.util.OdtToPdfOpenofficeConverter.java
@Override public byte[] convert(InputStream document) { try {/*from ww w . ja va 2 s.c o m*/ //return OpenofficeInProcessConverter.convertToPdf(IOUtils.toByteArray(document), "/tmp"); //THIS SHOULD BE REPLACED WITH System.IO. TEMP DIR String property = "java.io.tmpdir"; String tempDir = System.getProperty(property); return OpenofficeInProcessConverter.convert(IOUtils.toByteArray(document), tempDir, "pdf"); } catch (final Exception e) { throw new ReportGenerationException("Error converting the report", e); } }
From source file:com.qubit.terra.docs.util.OdtToDocxOpenofficeConverter.java
@Override public byte[] convert(InputStream document) { try {//from w w w . j a v a2 s. c om //return OpenofficeInProcessConverter.convertToPdf(IOUtils.toByteArray(document), "/tmp"); //THIS SHOULD BE REPLACED WITH System.IO. TEMP DIR String property = "java.io.tmpdir"; String tempDir = System.getProperty(property); return OpenofficeInProcessConverter.convert(IOUtils.toByteArray(document), tempDir, "docx"); } catch (final Exception e) { throw new ReportGenerationException("Error converting the report", e); } }
From source file:com.square.print.core.service.implementations.EditiqueServiceImpl.java
@Override public byte[] fusionnerFichiersPdfs(List<FichierDto> listeFichiers) { try {/*from ww w . ja v a 2s . c o m*/ return IOUtils.toByteArray(this.getClass().getResourceAsStream("/matrice.pdf")); } catch (IOException e) { throw new TechnicalException(e.getMessage(), e); } }
From source file:com.qubit.terra.docs.core.DocumentGenerator.java
public static DocumentGenerator create(InputStream inputStream, final String mimeType) { try {//from w ww . ja v a2 s . c o m return new DocumentGenerator(IOUtils.toByteArray(inputStream), mimeType); } catch (IOException e) { throw new ReportGenerationException("Error finding template", e); } }
From source file:com.canoo.webtest.boundary.StreamBoundary.java
public static byte[] tryGetBytes(final Context context, final Step step) { try {//from w w w. j a v a 2 s.c o m return IOUtils.toByteArray(context.getCurrentResponse().getWebResponse().getContentAsStream()); } catch (IOException e) { throw new StepExecutionException("Error processing content: " + e.getMessage(), step); } }