com.facebook.common.memory.PooledByteBufferInputStream Java Examples

The following examples show how to use com.facebook.common.memory.PooledByteBufferInputStream. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: EncodedImage.java    From fresco with MIT License 6 votes vote down vote up
/**
 * Returns an InputStream from the internal InputStream Supplier if it's not null. Otherwise
 * returns an InputStream for the internal buffer reference if valid and null otherwise.
 *
 * <p>The caller has to close the InputStream after using it.
 */
public @Nullable InputStream getInputStream() {
  if (mInputStreamSupplier != null) {
    return mInputStreamSupplier.get();
  }
  CloseableReference<PooledByteBuffer> pooledByteBufferRef =
      CloseableReference.cloneOrNull(mPooledByteBufferRef);
  if (pooledByteBufferRef != null) {
    try {
      return new PooledByteBufferInputStream(pooledByteBufferRef.get());
    } finally {
      CloseableReference.closeSafely(pooledByteBufferRef);
    }
  }
  return null;
}
 
Example #2
Source File: LocalExifThumbnailProducer.java    From fresco with MIT License 6 votes vote down vote up
private EncodedImage buildEncodedImage(PooledByteBuffer imageBytes, ExifInterface exifInterface) {
  Pair<Integer, Integer> dimensions =
      BitmapUtil.decodeDimensions(new PooledByteBufferInputStream(imageBytes));
  int rotationAngle = getRotationAngle(exifInterface);
  int width = dimensions != null ? dimensions.first : EncodedImage.UNKNOWN_WIDTH;
  int height = dimensions != null ? dimensions.second : EncodedImage.UNKNOWN_HEIGHT;
  EncodedImage encodedImage;
  CloseableReference<PooledByteBuffer> closeableByteBuffer = CloseableReference.of(imageBytes);
  try {
    encodedImage = new EncodedImage(closeableByteBuffer);
  } finally {
    CloseableReference.closeSafely(closeableByteBuffer);
  }
  encodedImage.setImageFormat(DefaultImageFormats.JPEG);
  encodedImage.setRotationAngle(rotationAngle);
  encodedImage.setWidth(width);
  encodedImage.setHeight(height);
  return encodedImage;
}
 
Example #3
Source File: MemoryPooledByteBufferTest.java    From fresco with MIT License 5 votes vote down vote up
private static void testReadFromStream(final MemoryPooledByteBuffer mPooledByteBuffer)
    throws Exception {
  InputStream is = new PooledByteBufferInputStream(mPooledByteBuffer);
  byte[] tmp = new byte[BUFFER_LENGTH + 1];
  int bytesRead = is.read(tmp, 0, tmp.length);
  assertEquals(BUFFER_LENGTH, bytesRead);
  for (int i = 0; i < BUFFER_LENGTH; i++) {
    assertEquals(BYTES[i], tmp[i]);
  }
  assertEquals(-1, is.read());
}
 
Example #4
Source File: MemoryPooledByteBufferTest.java    From fresco with MIT License 5 votes vote down vote up
private static void testReadFromStream(final MemoryPooledByteBuffer mPooledByteBuffer)
    throws Exception {
  InputStream is = new PooledByteBufferInputStream(mPooledByteBuffer);
  byte[] tmp = new byte[BUFFER_LENGTH + 1];
  int bytesRead = is.read(tmp, 0, tmp.length);
  assertEquals(BUFFER_LENGTH, bytesRead);
  for (int i = 0; i < BUFFER_LENGTH; i++) {
    assertEquals(BYTES[i], tmp[i]);
  }
  assertEquals(-1, is.read());
}
 
Example #5
Source File: MemoryPooledByteBufferTest.java    From fresco with MIT License 5 votes vote down vote up
private static void testReadFromStream(final MemoryPooledByteBuffer mPooledByteBuffer)
    throws Exception {
  InputStream is = new PooledByteBufferInputStream(mPooledByteBuffer);
  byte[] tmp = new byte[BUFFER_LENGTH + 1];
  int bytesRead = is.read(tmp, 0, tmp.length);
  assertEquals(BUFFER_LENGTH, bytesRead);
  for (int i = 0; i < BUFFER_LENGTH; i++) {
    assertEquals(BYTES[i], tmp[i]);
  }
  assertEquals(-1, is.read());
}