Java Code Examples for com.facebook.common.internal.ByteStreams#toByteArray()
The following examples show how to use
com.facebook.common.internal.ByteStreams#toByteArray() .
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: EncodedImageTest.java From fresco with MIT License | 6 votes |
private void checkWebpImage( final String imagePath, final ImageFormat imageFormat, final int expectedWidth, final int expectedHeight) throws IOException { PooledByteBuffer buf = new TrivialPooledByteBuffer( ByteStreams.toByteArray(EncodedImageTest.class.getResourceAsStream(imagePath))); EncodedImage encodedImage = new EncodedImage(CloseableReference.of(buf)); encodedImage.parseMetaData(); assertSame(imageFormat, encodedImage.getImageFormat()); assertEquals(expectedWidth, encodedImage.getWidth()); assertEquals(expectedHeight, encodedImage.getHeight()); assertEquals(0, encodedImage.getRotationAngle()); }
Example 2
Source File: ProgressiveJpegParserTest.java From fresco with MIT License | 6 votes |
@Before public void setUp() throws IOException { MockitoAnnotations.initMocks(this); ByteArrayPool byteArrayPool = mock(ByteArrayPool.class); when(byteArrayPool.get(anyInt())).thenReturn(new byte[10]); mProgressiveJpegParser = new ProgressiveJpegParser(byteArrayPool); mJpegBytes = ByteStreams.toByteArray( ProgressiveJpegParserTest.class.getResourceAsStream("images/image.jpg")); mWebpBytes = ByteStreams.toByteArray( ProgressiveJpegParserTest.class.getResourceAsStream(("images/image.webp"))); mPartialWebpBytes = new byte[mWebpBytes.length / 2]; System.arraycopy(mWebpBytes, 0, mPartialWebpBytes, 0, mPartialWebpBytes.length); }
Example 3
Source File: WebpBitmapFactoryTest.java From fresco with MIT License | 5 votes |
private FileDescriptor getImageFileDescriptor(String path) { try { File file = File.createTempFile("reqsquare", "tmp"); byte[] data = ByteStreams.toByteArray(getTestImageInputStream(path)); FileOutputStream fos = new FileOutputStream(file); fos.write(data); fos.close(); return new FileInputStream(file).getFD(); } catch (IOException e) { throw Throwables.propagate(e); } }
Example 4
Source File: WebpBitmapFactoryTest.java From fresco with MIT License | 5 votes |
@Test public void testByteArrayDecode() throws Throwable { byte[] data = ByteStreams.toByteArray(getTestWebpInputStream()); final Bitmap bitmap = mWebpBitmapFactory.decodeByteArray(data, 0, data.length, null); testBitmapDefault(bitmap, 20, 20); }
Example 5
Source File: WebpDecodingTest.java From fresco with MIT License | 5 votes |
private MemoryFile getMemoryFile(String path) { try { byte[] data = ByteStreams.toByteArray(getTestImageInputStream(path)); MemoryFile memoryFile = new MemoryFile(null, data.length); memoryFile.allowPurging(false); memoryFile.writeBytes(data, 0, 0, data.length); return memoryFile; } catch (IOException e) { throw Throwables.propagate(e); } }
Example 6
Source File: EncodedImageTest.java From fresco with MIT License | 5 votes |
@Test public void testParseMetaData_JPEG() throws IOException { PooledByteBuffer buf = new TrivialPooledByteBuffer( ByteStreams.toByteArray( EncodedImageTest.class.getResourceAsStream("images/image.jpg"))); EncodedImage encodedImage = new EncodedImage(CloseableReference.of(buf)); encodedImage.parseMetaData(); assertSame(DefaultImageFormats.JPEG, encodedImage.getImageFormat()); assertEquals(550, encodedImage.getWidth()); assertEquals(468, encodedImage.getHeight()); assertEquals(0, encodedImage.getRotationAngle()); assertEquals(0, encodedImage.getExifOrientation()); }
Example 7
Source File: EncodedImageTest.java From fresco with MIT License | 5 votes |
@Test public void testParseMetaData_PNG() throws IOException { PooledByteBuffer buf = new TrivialPooledByteBuffer( ByteStreams.toByteArray( EncodedImageTest.class.getResourceAsStream("images/image.png"))); EncodedImage encodedImage = new EncodedImage(CloseableReference.of(buf)); encodedImage.parseMetaData(); assertSame(DefaultImageFormats.PNG, encodedImage.getImageFormat()); assertEquals(800, encodedImage.getWidth()); assertEquals(600, encodedImage.getHeight()); assertEquals(0, encodedImage.getRotationAngle()); assertEquals(0, encodedImage.getExifOrientation()); }
Example 8
Source File: ColorImageExample.java From fresco with MIT License | 5 votes |
@Override public CloseableImage decode( EncodedImage encodedImage, int length, QualityInfo qualityInfo, ImageDecodeOptions options) { try { // Read the file as a string String text = new String(ByteStreams.toByteArray(encodedImage.getInputStream())); // Check if the string matches "<color>#" if (!text.startsWith(COLOR_TAG + "#")) { return null; } // Parse the int value between # and < int startIndex = COLOR_TAG.length() + 1; int endIndex = text.lastIndexOf('<'); int color = Integer.parseInt(text.substring(startIndex, endIndex), 16); // Add the alpha component so that we actually see the color color = ColorUtils.setAlphaComponent(color, 255); // Return the CloseableImage return new CloseableColorImage(color); } catch (IOException e) { e.printStackTrace(); } // Return nothing if an error occurred return null; }
Example 9
Source File: DiskStorageCacheTest.java From fresco with MIT License | 4 votes |
private byte[] getContents(BinaryResource resource) throws IOException { return ByteStreams.toByteArray(resource.openStream()); }