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.github.ctrimble.chlorine.asm.Utils.java
public static byte[] getResourceBytes(String path) throws IOException { return IOUtils.toByteArray(ConstructorInMethodTest.class.getResourceAsStream(path)); }
From source file:net.jadler.stubbing.server.jdk.RequestUtils.java
static Request convert(final HttpExchange httpExchange) throws IOException { final Request.Builder builder = Request.builder().method(httpExchange.getRequestMethod()) .requestURI(httpExchange.getRequestURI()).body(IOUtils.toByteArray(httpExchange.getRequestBody())); addEncoding(builder, httpExchange);// w w w . jav a 2 s .c o m addHeaders(builder, httpExchange); return builder.build(); }
From source file:net.javacrumbs.mocksocket.util.Utils.java
public static final byte[] toByteArray(InputStream stream) { try {/*from w w w .j av a 2 s . co m*/ return IOUtils.toByteArray(stream); } catch (IOException e) { throw new MockSocketException("Can not read data.", e); } finally { IOUtils.closeQuietly(stream); } }
From source file:com.alibaba.simpleimage.io.ByteArraySeekableStreamWrap.java
public static ByteArraySeekableStreamWrap wrapInputStream(InputStream is) throws IOException { byte[] data = IOUtils.toByteArray(is); ByteArraySeekableStreamWrap stream = new ByteArraySeekableStreamWrap(data); return stream; }
From source file:com.alu.e3.common.tools.BundleTools.java
public static byte[] file2ByteArray(InputStream fileInputStream) throws Exception { return IOUtils.toByteArray(fileInputStream); }
From source file:com.redhat.red.build.koji.testutil.TestResourceUtils.java
public static byte[] readTestResourceBytes(String resource) throws IOException { try (InputStream in = Thread.currentThread().getContextClassLoader().getResourceAsStream(resource)) { return IOUtils.toByteArray(in); }//from ww w .j a v a2s . c om }
From source file:net.es.nsi.common.util.ContentType.java
public static byte[] decode2ByteArray(String contentType, InputStream is) throws IOException { if (XGZIP.equalsIgnoreCase(contentType)) { return IOUtils.toByteArray(new GZIPInputStream(is)); } else {//from ww w. jav a 2s.c om return IOUtils.toByteArray(is); } }
From source file:com.gc.iotools.fmt.base.TestUtils.java
public static Map<String, byte[]> getBytesForFiles(final String[] included, final int nbytes, final boolean includes) throws IOException { final String[] goodFiles = (includes ? TestUtils.listFilesIncludingExtension(included) : TestUtils.listFilesExcludingExtension(included)); final Map<String, byte[]> result = new HashMap<String, byte[]>(); for (final String fileName : goodFiles) { final InputStream is = new FileInputStream(fileName); final byte[] bytes = IOUtils.toByteArray(new SizeLimitInputStream(is, nbytes)); result.put(fileName, bytes);//from w w w . j a v a 2 s . co m } return result; }
From source file:Algorithm.ImageEncoder.java
public static String getImageStringRaw(InputStream img) { String theString = null;/* w ww .j a v a 2 s .c o m*/ try { byte[] barr = IOUtils.toByteArray(img); Base64.Encoder en = Base64.getEncoder(); theString = en.encodeToString(barr); } catch (Exception iOException) { System.out.println("err"); } //item.write(f); return theString; }
From source file:com.google.code.docbook4j.XSLTUtils.java
public static final String toBase64(String baseDir, String location) { try {/* ww w . j ava2s . c o m*/ FileObject fo = FileObjectUtils.resolveFile(location, baseDir); byte[] data = IOUtils.toByteArray(fo.getContent().getInputStream()); StringBuffer sb = new StringBuffer(); sb.append("data:"); sb.append(determineMimeType(location)); sb.append(";base64,"); sb.append(Base64.encode(data)); fo.close(); return sb.toString(); } catch (Exception e) { log.error("Error reading image file: " + location, e); } return location; }