Search in sources :

Example 1 with PooledByteBufferInputStream

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;
}
Also used : PooledByteBufferInputStream(com.facebook.common.memory.PooledByteBufferInputStream) PooledByteBuffer(com.facebook.common.memory.PooledByteBuffer) EncodedImage(com.facebook.imagepipeline.image.EncodedImage)

Example 2 with PooledByteBufferInputStream

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);
    }
}
Also used : MemoryFile(android.os.MemoryFile) PooledByteBufferInputStream(com.facebook.common.memory.PooledByteBufferInputStream) LimitedInputStream(com.facebook.common.streams.LimitedInputStream) OutputStream(java.io.OutputStream)

Example 3 with PooledByteBufferInputStream

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());
}
Also used : PooledByteBufferInputStream(com.facebook.common.memory.PooledByteBufferInputStream) PooledByteBufferInputStream(com.facebook.common.memory.PooledByteBufferInputStream) InputStream(java.io.InputStream) Test(org.junit.Test)

Aggregations

PooledByteBufferInputStream (com.facebook.common.memory.PooledByteBufferInputStream)3 MemoryFile (android.os.MemoryFile)1 PooledByteBuffer (com.facebook.common.memory.PooledByteBuffer)1 LimitedInputStream (com.facebook.common.streams.LimitedInputStream)1 EncodedImage (com.facebook.imagepipeline.image.EncodedImage)1 InputStream (java.io.InputStream)1 OutputStream (java.io.OutputStream)1 Test (org.junit.Test)1