use of com.facebook.common.memory.PooledByteBufferInputStream in project fresco by facebook.
the class LocalExifThumbnailProducer method buildEncodedImage.
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;
}
use of com.facebook.common.memory.PooledByteBufferInputStream in project fresco by facebook.
the class GingerbreadPurgeableDecoder method copyToMemoryFile.
private static MemoryFile copyToMemoryFile(CloseableReference<PooledByteBuffer> bytesRef, int inputLength, @Nullable byte[] suffix) throws IOException {
int outputLength = inputLength + (suffix == null ? 0 : suffix.length);
MemoryFile memoryFile = new MemoryFile(null, outputLength);
memoryFile.allowPurging(false);
PooledByteBufferInputStream pbbIs = null;
LimitedInputStream is = null;
OutputStream os = null;
try {
pbbIs = new PooledByteBufferInputStream(bytesRef.get());
is = new LimitedInputStream(pbbIs, inputLength);
os = memoryFile.getOutputStream();
ByteStreams.copy(is, os);
if (suffix != null) {
memoryFile.writeBytes(suffix, 0, inputLength, suffix.length);
}
return memoryFile;
} finally {
CloseableReference.closeSafely(bytesRef);
Closeables.closeQuietly(pbbIs);
Closeables.closeQuietly(is);
Closeables.close(os, true);
}
}
use of com.facebook.common.memory.PooledByteBufferInputStream in project fresco by facebook.
the class NativePooledByteBufferTest method testReadFromStream.
@Test
public void testReadFromStream() 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());
}
Aggregations