Java 类com.android.volley.toolbox.PoolingByteArrayOutputStream 实例源码

项目:GeekZone    文件:BaseNetwork.java   
/**
 * Reads the contents of HttpEntity into a byte[].
 */
private byte[] entityToBytes(HttpEntity entity) throws IOException, ServerError {
    PoolingByteArrayOutputStream bytes = new PoolingByteArrayOutputStream(mPool, (int) entity.getContentLength());
    byte[] buffer = null;
    try {
        InputStream in = entity.getContent();
        if (in == null) {
            throw new ServerError();
        }
        buffer = mPool.getBuf(1024);
        int count;
        while ((count = in.read(buffer)) != -1) {
            bytes.write(buffer, 0, count);
        }
        return bytes.toByteArray();
    } finally {
        try {
            // Close the InputStream and release the resources by "consuming the content".
            entity.consumeContent();
        } catch (IOException e) {
            // This can happen if there was an exception above that left the entity in
            // an invalid state.
            VolleyLog.v("Error occured when calling consumingContent");
        }
        mPool.returnBuf(buffer);
        bytes.close();
    }
}
项目:EsperantoRadio    文件:DrBasicNetwork.java   
/**
 * Reads the contents of HttpEntity into a byte[].
 */
private byte[] entityToBytes(HttpEntity entity) throws IOException, ServerError {
  PoolingByteArrayOutputStream bytes =
      new PoolingByteArrayOutputStream(mPool, (int) entity.getContentLength());
  byte[] buffer = null;
  try {
    InputStream in = entity.getContent();
    if (in == null) {
      throw new ServerError();
    }
    buffer = mPool.getBuf(1024);
    int count;
    while ((count = in.read(buffer)) != -1) {
      bytes.write(buffer, 0, count);
    }
    return bytes.toByteArray();
  } finally {
    try {
      // Close the InputStream and release the resources by "consuming the content".
      entity.consumeContent();
    } catch (IOException e) {
      // This can happen if there was an exception above that left the entity in
      // an invalid state.
      VolleyLog.v("Error occured when calling consumingContent");
    }
    mPool.returnBuf(buffer);
    bytes.close();
  }
}
项目:RestVolley    文件:StreamBasedNetwork.java   
/** Reads the contents of HttpEntity into a byte[]. */
public static byte[] entityToBytes(InputStream inputStream, long contentLength, int bufferSize) throws IOException, ServerError {
    ByteArrayPool bytePool = new ByteArrayPool(bufferSize);
    PoolingByteArrayOutputStream bytes = new PoolingByteArrayOutputStream(bytePool, (int)contentLength);
    byte[] buffer = null;
    try {
        if (inputStream == null) {
            throw new ServerError();
        }
        buffer = bytePool.getBuf(1024);
        int count;
        while ((count = inputStream.read(buffer)) != -1) {
            bytes.write(buffer, 0, count);
        }
        return bytes.toByteArray();
    } finally {
        try {
            // Close the InputStream and release the resources by "consuming the content".
            inputStream.close();
        } catch (IOException e) {
            // This can happen if there was an exception above that left the entity in
            // an invalid state.
            VolleyLog.v("Error occured when calling consumingContent");
        }
        bytePool.returnBuf(buffer);
        bytes.close();
    }
}
项目:RestVolley    文件:RVNetwork.java   
/** Reads the contents of HttpEntity into a byte[]. */
private byte[] entityToBytes(HttpEntity entity) throws IOException, ServerError {
    PoolingByteArrayOutputStream bytes =
            new PoolingByteArrayOutputStream(mPool, (int) entity.getContentLength());
    byte[] buffer = null;
    try {
        InputStream in = entity.getContent();
        if (in == null) {
            throw new ServerError();
        }
        buffer = mPool.getBuf(1024);
        int count;
        while ((count = in.read(buffer)) != -1) {
            bytes.write(buffer, 0, count);
        }
        return bytes.toByteArray();
    } finally {
        try {
            // Close the InputStream and release the resources by "consuming the content".
            entity.consumeContent();
        } catch (IOException e) {
            // This can happen if there was an exception above that left the entity in
            // an invalid state.
            VolleyLog.v("Error occured when calling consumingContent");
        }
        mPool.returnBuf(buffer);
        bytes.close();
    }
}
项目:saarang-iosched    文件:VolleyDiskCacheWrapper.java   
private byte[] streamToBytes(InputStream in) throws IOException {
    PoolingByteArrayOutputStream outputStream = new PoolingByteArrayOutputStream(byteArrayPool);
    byte[] bytes = byteArrayPool.getBuf(DEFAULT_BYTE_ARRAY_SIZE);
    int pos = 0;
    while ((in.read(bytes, pos, bytes.length - pos)) != -1) {
        outputStream.write(bytes);
    }
    byteArrayPool.returnBuf(bytes);
    byte[] result = outputStream.toByteArray();
    outputStream.close();
    return result;
}
项目:AppDevFestSudeste2015    文件:VolleyDiskCacheWrapper.java   
private byte[] streamToBytes(InputStream in) throws IOException {
    PoolingByteArrayOutputStream outputStream = new PoolingByteArrayOutputStream(byteArrayPool);
    byte[] bytes = byteArrayPool.getBuf(DEFAULT_BYTE_ARRAY_SIZE);
    int pos = 0;
    while ((in.read(bytes, pos, bytes.length - pos)) != -1) {
        outputStream.write(bytes);
    }
    byteArrayPool.returnBuf(bytes);
    byte[] result = outputStream.toByteArray();
    outputStream.close();
    return result;
}
项目:devfestnorte-app    文件:VolleyDiskCacheWrapper.java   
private byte[] streamToBytes(InputStream in) throws IOException {
    PoolingByteArrayOutputStream outputStream = new PoolingByteArrayOutputStream(byteArrayPool);
    byte[] bytes = byteArrayPool.getBuf(DEFAULT_BYTE_ARRAY_SIZE);
    int pos = 0;
    while ((in.read(bytes, pos, bytes.length - pos)) != -1) {
        outputStream.write(bytes);
    }
    byteArrayPool.returnBuf(bytes);
    byte[] result = outputStream.toByteArray();
    outputStream.close();
    return result;
}
项目:saarang-iosched    文件:VolleyDiskCacheWrapper.java   
private byte[] streamToBytes(InputStream in) throws IOException {
    PoolingByteArrayOutputStream outputStream = new PoolingByteArrayOutputStream(byteArrayPool);
    byte[] bytes = byteArrayPool.getBuf(DEFAULT_BYTE_ARRAY_SIZE);
    int pos = 0;
    while ((in.read(bytes, pos, bytes.length - pos)) != -1) {
        outputStream.write(bytes);
    }
    byteArrayPool.returnBuf(bytes);
    byte[] result = outputStream.toByteArray();
    outputStream.close();
    return result;
}
项目:volley-jackson-extension    文件:JacksonNetwork.java   
/**
 * Copied from {@link com.android.volley.toolbox.BasicNetwork}
 *
 * Reads the contents of HttpEntity into a byte[].
 *
 */
private byte[] entityToBytes(HttpEntity entity) throws IOException, ServerError {
    PoolingByteArrayOutputStream bytes = new PoolingByteArrayOutputStream(mPool, (int) entity.getContentLength());
    byte[] buffer = null;
    try {
        InputStream in = entity.getContent();
        if (in == null) {
            throw new ServerError();
        }
        buffer = mPool.getBuf(1024);
        int count;
        while ((count = in.read(buffer)) != -1) {
            bytes.write(buffer, 0, count);
        }
        return bytes.toByteArray();
    } finally {
        try {
            // Close the InputStream and release the resources by "consuming the content".
            entity.consumeContent();
        } catch (IOException e) {
            // This can happen if there was an exception above that left the entity in
            // an invalid state.
            VolleyLog.v("Error occured when calling consumingContent");
        }
        mPool.returnBuf(buffer);
        bytes.close();
    }
}