List of usage examples for org.apache.http.util ByteArrayBuffer append
public void append(CharArrayBuffer charArrayBuffer, int i, int i2)
From source file:com.cloudbase.CBBasePart.java
private static void append(ByteArrayBuffer buf, byte[] data) { buf.append(data, 0, data.length); }
From source file:ch.cyberduck.core.http.DelayedHttpMultipartEntity.java
private static ByteArrayBuffer encode(final Charset charset, final String input) { final ByteBuffer encoded = charset.encode(CharBuffer.wrap(input)); final ByteArrayBuffer bab = new ByteArrayBuffer(encoded.remaining()); bab.append(encoded.array(), encoded.position(), encoded.remaining()); return bab;//ww w. ja va 2s .c om }
From source file:com.mcxiaoke.next.http.entity.mime.AbstractMultipartForm.java
private static ByteArrayBuffer encode(final Charset charset, final String string) { final ByteBuffer encoded = charset.encode(CharBuffer.wrap(string)); final ByteArrayBuffer bab = new ByteArrayBuffer(encoded.remaining()); bab.append(encoded.array(), encoded.position(), encoded.remaining()); return bab;/* ww w .j a v a 2s . c o m*/ }
From source file:com.net.plus.common.Utils.Util.java
public static byte[] toByteArray(HttpEntity entity) { InputStream instream = null;/*from www . ja v a 2 s . com*/ byte[] ret = null; try { if (entity == null) { throw new IllegalArgumentException("HTTP entity may not be null"); } instream = entity.getContent(); if (instream == null) { return null; } int i = (int) entity.getContentLength(); if (i < 0) { i = 4096; } ByteArrayBuffer buffer = new ByteArrayBuffer(i); byte tmp[] = new byte[4096]; int l; while ((l = instream.read(tmp)) != -1) { buffer.append(tmp, 0, l); } ret = buffer.toByteArray(); } catch (IOException e) { e.printStackTrace(); } finally { try { if (instream != null) { instream.close(); } } catch (IOException e) { } } return ret; }
From source file:fr.itinerennes.utils.IOUtils.java
/** * Reads the given input stream and returns it as an array of bytes. * //from w w w.jav a 2s .c o m * @param in * an input stream to read * @return an array of bytes with the content provided by the given input stream */ public static byte[] readBytes(final InputStream in) { final byte[] buffer = new byte[BYTE_BUF_SIZE]; final ByteArrayBuffer bytes = new ByteArrayBuffer(10 * BYTE_BUF_SIZE); int len = 0; try { while ((len = in.read(buffer)) != -1) { bytes.append(buffer, 0, len); } } catch (final IOException e) { LOGGER.error("unable to read the input stream", e); } return bytes.toByteArray(); }
From source file:android.wulongdao.thirdparty.mime.HttpMultipart.java
private static ByteArrayBuffer encode(final Charset charset, final String string) { ByteBuffer encoded = charset.encode(CharBuffer.wrap(string)); ByteArrayBuffer bab = new ByteArrayBuffer(encoded.remaining()); bab.append(encoded.array(), encoded.position(), encoded.remaining()); return bab;//from ww w . j a v a 2 s. c o m }
From source file:com.shopgun.android.sdk.network.impl.NetworkImpl.java
private static byte[] entityToBytes(HttpEntity entity) throws IllegalStateException, IOException { // Find best buffer size int init_buf = 0 <= entity.getContentLength() ? (int) entity.getContentLength() : BUFFER_SIZE; ByteArrayBuffer bytes = new ByteArrayBuffer(init_buf); InputStream is = entity.getContent(); if (is == null) return bytes.toByteArray(); byte[] buf = new byte[init_buf]; int c = -1;// w w w.jav a2s . co m while ((c = is.read(buf)) != -1) { bytes.append(buf, 0, c); } return bytes.toByteArray(); }
From source file:mobisocial.musubi.social.FacebookFriendFetcher.java
public static byte[] getImageFromURL(String remoteUrl) { try {//w ww .j a v a2 s.co m // Grab the content URL url = new URL(remoteUrl); URLConnection ucon = url.openConnection(); InputStream is = ucon.getInputStream(); // Read the content chunk by chunk BufferedInputStream bis = new BufferedInputStream(is, 8192); ByteArrayBuffer baf = new ByteArrayBuffer(0); byte[] chunk = new byte[CHUNK_SIZE]; int current = bis.read(chunk); while (current != -1) { baf.append(chunk, 0, current); current = bis.read(chunk); } return baf.toByteArray(); } catch (IOException e) { Log.e(TAG, "HTTP error", e); } return null; }
From source file:topoos.APIAccess.mime.HttpMultipart.java
/** * Encode./*from www .ja va 2 s . co m*/ * * @param charset the charset * @param string the string * @return the byte array buffer */ private static ByteArrayBuffer encode(final Charset charset, final String string) { ByteBuffer encoded = charset.encode(CharBuffer.wrap(string)); ByteArrayBuffer bab = new ByteArrayBuffer(encoded.remaining()); bab.append(encoded.array(), encoded.position(), encoded.remaining()); return bab; }
From source file:com.seo.support.http.EntityUtils.java
/** * Read the contents of an entity and return it as a byte array. * * @param entity// w w w.j a v a 2 s. c o m * @return byte array containing the entity content. May be null if * {@link HttpEntity#getContent()} is null. * @throws IOException if an error occurs reading the input stream * @throws IllegalArgumentException if entity is null or if content length > Integer.MAX_VALUE */ public static byte[] toByteArray(final HttpEntity entity) throws IOException { if (entity == null) { throw new IllegalArgumentException("HTTP entity may not be null"); } InputStream instream = entity.getContent(); if (instream == null) { return null; } try { if (entity.getContentLength() > Integer.MAX_VALUE) { throw new IllegalArgumentException("HTTP entity too large to be buffered in memory"); } int i = (int) entity.getContentLength(); if (i < 0) { i = 4096; } ByteArrayBuffer buffer = new ByteArrayBuffer(i); byte[] tmp = new byte[4096]; int l; while ((l = instream.read(tmp)) != -1) { buffer.append(tmp, 0, l); } return buffer.toByteArray(); } finally { instream.close(); } }