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:com.doculibre.constellio.feedprotocol.parse.xml.FeedEntityResolver.java
private FeedEntityResolver() { InputStream inputStream = null; try {/* w w w . jav a 2 s. c om*/ inputStream = DTD_PATH.getInputStream(); if (inputStream == null) { throw new IOException("Could not find : " + DTD_PATH.getPath()); } byteArray = IOUtils.toByteArray(inputStream); } catch (IOException ioe) { ioe.printStackTrace(); throw new RuntimeException(ioe); } finally { IOUtils.closeQuietly(inputStream); } }
From source file:com.github.bpark.vertx.webconsole.handler.ClasspathContentHandler.java
@Override public void handle(HttpServerRequest serverRequest) { HttpServerResponse serverResponse = serverRequest.response(); String path = serverRequest.path(); InputStream inputStream = WebConsoleVerticle.class.getResourceAsStream(path); if (inputStream != null) { try {//from w ww . j a v a 2s.c o m setContentType(serverResponse, path); byte[] data = IOUtils.toByteArray(inputStream); serverResponse.headers().add(CONTENT_LENGTH, String.valueOf(data.length)); serverResponse.end(new Buffer(data)); } catch (IOException e) { sendError(serverResponse); } } else { sendNotFound(serverResponse); } }
From source file:mx.com.gaby.service.AsynchronousService.java
private void serializeFile() { try {// w w w . j a va2 s .c o m File file = new File("C:\\Users\\iam_g\\Downloads\\alto.pdf"); InputStream isNew = new FileInputStream(file); byte[] bytes = IOUtils.toByteArray(isNew); String codigoMd5 = Md5Converter.calculaMD5(bytes); Long maxMemory = Runtime.getRuntime().maxMemory(); int[] matrix = new int[(int) (maxMemory + 1)]; for (int i = 0; i < matrix.length; ++i) { matrix[i] = i + 1; } System.out.println("Serializando archivo: [Tamao: " + file.length() + "][" + maxMemory + "]" + "[" + file.getName() + "][" + codigoMd5 + "][" + bytes.length + "]"); } catch (FileNotFoundException fnfe) { System.out.println("FileNotFoundException: " + fnfe.getMessage()); } catch (IOException ioe) { System.out.println("IOException: " + ioe.getMessage()); } }
From source file:com.haulmont.yarg.structure.impl.ReportTemplateImpl.java
public ReportTemplateImpl(String code, String documentName, String documentPath, InputStream documentContent, ReportOutputType reportOutputType) throws IOException { this.code = code; this.documentName = documentName; this.documentPath = documentPath; this.documentContent = IOUtils.toByteArray(documentContent); this.reportOutputType = reportOutputType; }
From source file:com.tess4j.rest.Tess4jV1SmokeTest.java
@Test public void testDoOcr() throws IOException { Map<String, String> headers = new HashMap<String, String>(); headers.put("Accept", MediaType.APPLICATION_JSON_VALUE); headers.put("Content-Type", MediaType.APPLICATION_JSON_VALUE); Image image = new Image(); InputStream inputStream = ClassLoader.getSystemResourceAsStream("eurotext.png"); image.setUserId("arun0009"); image.setExtension(".png"); image.setImage(Base64.encodeBase64(IOUtils.toByteArray(inputStream))); String response = given().contentType("application/json").headers(headers).when().body(image).expect() .statusCode(200).post("http://localhost:8080/ocr/v0.9/upload").asString(); System.out.println(response); }
From source file:edu.cmu.cs.diamond.android.Filter.java
public Filter(int resourceId, Context context, String name, String[] args, byte[] blob) throws IOException { Resources r = context.getResources(); String resourceName = r.getResourceEntryName(resourceId); File f = context.getFileStreamPath(resourceName); if (!f.exists()) { InputStream ins = r.openRawResource(resourceId); byte[] buf = IOUtils.toByteArray(ins); FileOutputStream fos = context.openFileOutput(resourceName, Context.MODE_PRIVATE); IOUtils.write(buf, fos);/* w w w .j a v a 2 s . c o m*/ context.getFileStreamPath(resourceName).setExecutable(true); fos.close(); } ProcessBuilder pb = new ProcessBuilder(f.getAbsolutePath()); Map<String, String> env = pb.environment(); tempDir = File.createTempFile("filter", null, context.getCacheDir()); tempDir.delete(); // Delete file and create directory. if (!tempDir.mkdir()) { throw new IOException("Unable to create temporary directory."); } env.put("TEMP", tempDir.getAbsolutePath()); env.put("TMPDIR", tempDir.getAbsolutePath()); proc = pb.start(); is = proc.getInputStream(); os = proc.getOutputStream(); sendInt(1); sendString(name); sendStringArray(args); sendBinary(blob); while (this.getNextToken().tag != TagEnum.INIT) ; Log.d(TAG, "Filter initialized."); }
From source file:com.android.email.mail.store.imap.ImapStringTest.java
public void testEmpty() throws Exception { assertTrue(ImapString.EMPTY.isEmpty()); assertEquals("", ImapString.EMPTY.getString()); assertEquals("", Utility.fromAscii(IOUtils.toByteArray(ImapString.EMPTY.getAsStream()))); assertFalse(ImapString.EMPTY.isNumber()); assertFalse(ImapString.EMPTY.isDate()); assertTrue(ImapString.EMPTY.is("")); assertTrue(ImapString.EMPTY.startsWith("")); assertFalse(ImapString.EMPTY.is("a")); assertFalse(ImapString.EMPTY.startsWith("a")); assertTrue(new ImapSimpleString(null).isEmpty()); }
From source file:com.github.pemapmodder.pocketminegui.utils.Utils.java
private static File installLinuxPHP(File home, InstallProgressReporter progress) { progress.report(0.0);/*from w ww . j a v a 2s . c om*/ File bin = new File(home, ".pmgui_tmp_pm_linux_installer"); bin.mkdirs(); try { InputStream get = new URL("http", "get.pocketmine.net", "").openStream(); Process bash = new ProcessBuilder("bash -s - -v development").directory(bin) .redirectOutput(ProcessBuilder.Redirect.INHERIT).redirectError(ProcessBuilder.Redirect.INHERIT) .start(); progress.report(0.25); byte[] bytes = IOUtils.toByteArray(get); progress.report(0.5); bash.getOutputStream().write(bytes); int result = bash.waitFor(); progress.report(0.75); if (result == 0) { File out = new File(bin, "bin"); FileUtils.copyDirectory(out, new File(home, "bin")); FileUtils.deleteDirectory(bin); File output = new File(out, "php7/bin/php"); progress.completed(output); return output; } else { FileUtils.deleteDirectory(bin); return null; } } catch (IOException | InterruptedException e) { e.printStackTrace(); try { FileUtils.deleteDirectory(bin); } catch (IOException e1) { } return null; } }
From source file:edu.umn.msi.tropix.proteomics.test.CreateMzXML.java
@Test(groups = { "create" }) public void createMzXML() throws Exception { final DTAToMzXMLConverterImpl converter = new DTAToMzXMLConverterImpl(); final InMemoryDTAListImpl dtaList = new InMemoryDTAListImpl(); final String[] dtaNames = new String[] { "mrr.103.106.1.dta", "mrr.1105.1106.2.dta", "mrr.1105.1106.3.dta", "mrr.2025.2026.2.dta", "mrr.2025.2026.3.dta", "mrr.3009.3011.1.dta" }; for (final String dtaName : dtaNames) { final InputStream dtaStream = ProteomicsTests.getResourceAsStream(dtaName); dtaList.add(IOUtils.toByteArray(dtaStream), dtaName); }/*www .j ava 2 s . c om*/ final MzXML mzxml = converter.dtaToMzXML(dtaList, null); final MzXMLUtility mzxmlUtility = new MzXMLUtility(); mzxmlUtility.serialize(mzxml, File.createTempFile("valid", "mzxml")); System.out.println(mzxmlUtility.toString(mzxml)); }
From source file:controllers.upload.FileUploadController.java
@Route(method = HttpMethod.POST, uri = "/ajax") public Result ajax() throws IOException { byte[] content = IOUtils.toByteArray(context().getReader()); return ok(content.length + " bytes uploaded"); }