/** * Read the specified file into a byte array. * * @param in * The file to read into a byte array. * @return The contents of the file as a byte array. * @throws IOException Thrown by underlying stream. */ public static byte[] readBytes(File in) throws IOException { return readBytes(in, 1024); }
/** * Read the specified input stream into a byte array. * * @param in * The stream to read into a byte array. * @return The contents of the stream as a byte array. * @throws IOException Thrown by underlying stream. */ public static byte[] readBytes(InputStream in) throws IOException { return readBytes(in, 1024); }
/** * Read the specified input stream into a byte array. * * @param in * The stream to read into a byte array. * @return The contents of the stream as a byte array. * @throws IOException Thrown by underlying stream. */ public static byte[] readBytes(InputStream in) throws IOException { return readBytes(in, 1024); }
/** * Read the specified file into a byte array. * * @param in * The file to read into a byte array. * @return The contents of the file as a byte array. * @throws IOException Thrown by underlying stream. */ public static byte[] readBytes(File in) throws IOException { return readBytes(in, 1024); }
/** * Read the specified input stream into a byte array. * * @param in * The stream to read into a byte array. * @return The contents of the stream as a byte array. * @throws IOException Thrown by underlying stream. */ public static byte[] readBytes(InputStream in) throws IOException { return readBytes(in, 1024); }
/** * Read the specified file into a byte array. * * @param in * The file to read into a byte array. * @return The contents of the file as a byte array. * @throws IOException Thrown by underlying stream. */ public static byte[] readBytes(File in) throws IOException { return readBytes(in, 1024); }
/** * Constructor. * Create a stream resource from an <code>InputStream</code>. * Contents of stream will be loaded into a reusable byte array. * * @param contents The resource contents. * @param mediaType The resource media type. * @throws IOException */ public StreamResource(InputStream contents, String mediaType) throws IOException { this.contents = IOUtils.readBytes(contents, 1024); this.mediaType = mediaType; }
/** * Add the specified input stream to this cache. * * @param contents The input stream whose contents are to be added to this cache. * @return * Either the same byte array or a previously cached byte array depending on whether the byte array already * exists in the cache. * @throws IOException */ public byte[] cache(InputStream contents) throws IOException { if (contents == null) return null; ByteArray ba = new ByteArray(IOUtils.readBytes(contents, 1024)); cache.putIfAbsent(ba, ba.contents); return cache.get(ba); }
/** * Add the specified input stream to this cache. * * @param contents The input stream whose contents are to be added to this cache. * @return * Either the same byte array or a previously cached byte array depending on whether the byte array already * exists in the cache. * @throws IOException */ public byte[] cache(InputStream contents) throws IOException { if (contents == null) return null; ByteArray ba = new ByteArray(IOUtils.readBytes(contents, 1024)); cache.putIfAbsent(ba, ba.contents); return cache.get(ba); }
/** * Returns the HTTP body content as a plain string. * * <h5 class='section'>Notes:</h5> * <ul class='spaced-list'> * <li> * If {@code allowHeaderParams} init parameter is true, then first looks for {@code &body=xxx} in the URL query string. * </ul> * * @return The incoming input from the connection as a plain string. * @throws IOException If a problem occurred trying to read from the reader. */ public String asString() throws IOException { if (body == null) body = readBytes(getInputStream(), 1024); return new String(body, UTF8); }
/** * Add the specified input stream to this cache. * * @param contents The input stream whose contents are to be added to this cache. * @return * Either the same byte array or a previously cached byte array depending on whether the byte array already * exists in the cache. * @throws IOException */ public byte[] cache(InputStream contents) throws IOException { if (contents == null) return null; ByteArray ba = new ByteArray(IOUtils.readBytes(contents, 1024)); cache.putIfAbsent(ba, ba.contents); return cache.get(ba); }
/** * Returns the HTTP body content as a simple hexadecimal character string. * * <h5 class='section'>Example:</h5> * <p class='bcode w800'> * 0123456789ABCDEF * </p> * * @return The incoming input from the connection as a plain string. * @throws IOException If a problem occurred trying to read from the reader. */ public String asHex() throws IOException { if (body == null) body = readBytes(getInputStream(), 1024); return toHex(body); }
@Override /* HttpClientConnection */ public void sendRequestEntity(HttpEntityEnclosingRequest request) throws HttpException, IOException { req.body(request.getEntity() == null ? "" : IOUtils.readBytes(request.getEntity().getContent(), 1024)); }
/** * Returns the HTTP body content as a simple space-delimited hexadecimal character string. * * <h5 class='section'>Example:</h5> * <p class='bcode w800'> * 01 23 45 67 89 AB CD EF * </p> * * @return The incoming input from the connection as a plain string. * @throws IOException If a problem occurred trying to read from the reader. */ public String asSpacedHex() throws IOException { if (body == null) body = readBytes(getInputStream(), 1024); return toSpacedHex(body); }
/** * Returns the HTTP body content as a simple space-delimited hexadecimal character string. * * <h5 class='section'>Example:</h5> * <p class='bcode w800'> * 01 23 45 67 89 AB CD EF * </p> * * @return The incoming input from the connection as a plain string. * @throws IOException If a problem occurred trying to read from the reader. */ public String asSpacedHex() throws IOException { if (body == null) body = readBytes(getInputStream(), 1024); return toSpacedHex(body); }
/** * Returns the HTTP body content as a simple space-delimited hexadecimal character string. * * <h5 class='section'>Example:</h5> * <p class='bcode w800'> * 01 23 45 67 89 AB CD EF * </p> * * @return The incoming input from the connection as a plain string. * @throws IOException If a problem occurred trying to read from the reader. */ public String asSpacedHex() throws IOException { if (body == null) body = readBytes(getInputStream(), 1024); return toSpacedHex(body); }
@Override /* HttpClientConnection */ public void sendRequestEntity(HttpEntityEnclosingRequest request) throws HttpException, IOException { req.body(request.getEntity() == null ? "" : IOUtils.readBytes(request.getEntity().getContent(), 1024)); }
/** * Returns the HTTP body content as a simple hexadecimal character string. * * <h5 class='section'>Example:</h5> * <p class='bcode w800'> * 0123456789ABCDEF * </p> * * @return The incoming input from the connection as a plain string. * @throws IOException If a problem occurred trying to read from the reader. */ public String asHex() throws IOException { if (body == null) body = readBytes(getInputStream(), 1024); return toHex(body); }
/** * Returns the HTTP body content as a simple hexadecimal character string. * * <h5 class='section'>Example:</h5> * <p class='bcode w800'> * 0123456789ABCDEF * </p> * * @return The incoming input from the connection as a plain string. * @throws IOException If a problem occurred trying to read from the reader. */ public String asHex() throws IOException { if (body == null) body = readBytes(getInputStream(), 1024); return toHex(body); }
@Override /* HttpClientConnection */ public void sendRequestEntity(HttpEntityEnclosingRequest request) throws HttpException, IOException { req.body(request.getEntity() == null ? "" : IOUtils.readBytes(request.getEntity().getContent(), 1024)); }