本文整理汇总了Java中com.facebook.common.references.CloseableReference.of方法的典型用法代码示例。如果您正苦于以下问题:Java CloseableReference.of方法的具体用法?Java CloseableReference.of怎么用?Java CloseableReference.of使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.facebook.common.references.CloseableReference
的用法示例。
在下文中一共展示了CloseableReference.of方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: setUp
import com.facebook.common.references.CloseableReference; //导入方法依赖的package包/类
@Before
public void setUp() {
MockitoAnnotations.initMocks(this);
mRemoveMetaDataProducer = new RemoveImageTransformMetaDataProducer(mInputProducer);
mIntermediateByteBuffer = mock(PooledByteBuffer.class);
mFinalByteBuffer = mock(PooledByteBuffer.class);
mIntermediateResult = CloseableReference.of(mIntermediateByteBuffer);
mFinalResult = CloseableReference.of(mFinalByteBuffer);
mRemoveMetaDataConsumer = null;
doAnswer(
new Answer() {
@Override
public Object answer(InvocationOnMock invocation) throws Throwable {
mRemoveMetaDataConsumer = (Consumer<EncodedImage>) invocation.getArguments()[0];
return null;
}
}).when(mInputProducer).produceResults(any(Consumer.class), any(ProducerContext.class));
mRemoveMetaDataProducer.produceResults(mConsumer, mProducerContext);
}
示例2: setUp
import com.facebook.common.references.CloseableReference; //导入方法依赖的package包/类
@Before
public void setUp() {
MockitoAnnotations.initMocks(this);
MemoryCacheParams params = new MemoryCacheParams(
4 * ByteConstants.MB,
256,
Integer.MAX_VALUE,
Integer.MAX_VALUE,
Integer.MAX_VALUE);
when(mMemoryCacheParamsSupplier.get()).thenReturn(params);
CountingMemoryCache<CacheKey, CloseableImage> countingMemoryCache =
BitmapCountingMemoryCacheFactory.get(
mMemoryCacheParamsSupplier,
mMemoryTrimmableRegistry,
mPlatformBitmapFactory,
true);
mCacheKey = new SimpleCacheKey("key");
mAnimatedFrameCache = new AnimatedFrameCache(mCacheKey, countingMemoryCache);
mFrame1 = CloseableReference.of(mock(CloseableImage.class));
mFrame2 = CloseableReference.of(mock(CloseableImage.class));
}
示例3: testDontCacheIntermediateImageAsAlreadyHaveFullQuality
import com.facebook.common.references.CloseableReference; //导入方法依赖的package包/类
@Test
public void testDontCacheIntermediateImageAsAlreadyHaveFullQuality() {
setupBitmapMemoryCacheGetNotFound();
setupInputProducerStreamingSuccess();
CloseableImage closeableImage = mock(CloseableImage.class);
when(closeableImage.getQualityInfo()).thenReturn(ImmutableQualityInfo.FULL_QUALITY);
CloseableReference<CloseableImage> closeableImageRef = CloseableReference.of(closeableImage);
setupBitmapMemoryCacheGetSuccessOnSecondRead(closeableImageRef);
mBitmapMemoryCacheProducer.produceResults(mConsumer, mProducerContext);
verify(mMemoryCache, never()).cache(mBitmapMemoryCacheKey, mIntermediateImageReference);
verify(mMemoryCache).cache(mBitmapMemoryCacheKey, mFinalImageReference);
verify(mConsumer).onNewResult(closeableImageRef, Consumer.NO_FLAGS);
verify(mConsumer).onNewResult(mFinalImageReferenceClone, Consumer.IS_LAST);
Assert.assertTrue(!mFinalImageReferenceClone.isValid());
Assert.assertEquals(
0,
closeableImageRef.getUnderlyingReferenceTestOnly().getRefCountTestOnly());
verify(mProducerListener).onProducerStart(mRequestId, PRODUCER_NAME);
Map<String, String> extraMap =
ImmutableMap.of(BitmapMemoryCacheProducer.EXTRA_CACHED_VALUE_FOUND, "false");
verify(mProducerListener).onProducerFinishWithSuccess(mRequestId, PRODUCER_NAME, extraMap);
verify(mProducerListener, never())
.onUltimateProducerReached(anyString(), anyString(), anyBoolean());
}
示例4: setup
import com.facebook.common.references.CloseableReference; //导入方法依赖的package包/类
@Before
public void setup() {
MockitoAnnotations.initMocks(this);
mImageReference = CloseableReference.of((CloseableImage) mCloseableStaticBitmap);
when(mCloseableStaticBitmap.getUnderlyingBitmap()).thenReturn(mBitmap);
// 100 * 15 = 1500 (between MIN_BITMAP_SIZE_BYTES and MAX_BITMAP_SIZE_BYTES)
when(mBitmap.getRowBytes()).thenReturn(100);
when(mBitmap.getHeight()).thenReturn(15);
doAnswer(
new Answer() {
@Override
public Object answer(InvocationOnMock invocation) throws Throwable {
Object[] args = invocation.getArguments();
Consumer<CloseableReference<CloseableImage>> consumer =
(Consumer<CloseableReference<CloseableImage>>) args[0];
consumer.onNewResult(mImageReference, 0);
return null;
}
})
.when(mInputProducer)
.produceResults(any(Consumer.class), any(ProducerContext.class));
}
示例5: setUp
import com.facebook.common.references.CloseableReference; //导入方法依赖的package包/类
@Before
public void setUp() {
MockitoAnnotations.initMocks(this);
mTestExecutorService = new TestExecutorService(new FakeClock());
mPostprocessorProducer =
new PostprocessorProducer(
mInputProducer,
mPlatformBitmapFactory,
mTestExecutorService);
when(mImageRequest.getPostprocessor()).thenReturn(mPostprocessor);
when(mProducerContext.getId()).thenReturn(mRequestId);
when(mProducerContext.getListener()).thenReturn(mProducerListener);
when(mProducerContext.getImageRequest()).thenReturn(mImageRequest);
mResults = new ArrayList<>();
when(mPostprocessor.getName()).thenReturn(POSTPROCESSOR_NAME);
when(mProducerListener.requiresExtraMap(mRequestId)).thenReturn(true);
doAnswer(
new Answer<Object>() {
@Override
public Object answer(InvocationOnMock invocation) throws Throwable {
mResults.add(
((CloseableReference<CloseableImage>) invocation.getArguments()[0]).clone());
return null;
}
}
).when(mConsumer).onNewResult(any(CloseableReference.class), anyInt());
mInOrder = inOrder(mPostprocessor, mProducerListener, mConsumer);
mSourceBitmap = mock(Bitmap.class);
mSourceCloseableStaticBitmap = mock(CloseableStaticBitmap.class);
when(mSourceCloseableStaticBitmap.getUnderlyingBitmap()).thenReturn(mSourceBitmap);
mSourceCloseableImageRef =
CloseableReference.<CloseableImage>of(mSourceCloseableStaticBitmap);
mDestinationBitmap = mock(Bitmap.class);
mDestinationCloseableBitmapRef =
CloseableReference.of(mDestinationBitmap, mBitmapResourceReleaser);
}
示例6: setUp
import com.facebook.common.references.CloseableReference; //导入方法依赖的package包/类
@Before
public void setUp() {
MockitoAnnotations.initMocks(this);
mResourceReleaser = mock(ResourceReleaser.class);
mResultRef1 = CloseableReference.of(new Object(), mResourceReleaser);
mResultRef2 = CloseableReference.of(new Object(), mResourceReleaser);
mResultRef3 = CloseableReference.of(new Object(), mResourceReleaser);
mException = mock(Exception.class);
mDataSubscriber1 = mock(DataSubscriber.class);
mDataSubscriber2 = mock(DataSubscriber.class);
mSettableProducerContext = mock(SettableProducerContext.class);
when(mSettableProducerContext.getId()).thenReturn(mRequestId);
when(mSettableProducerContext.isPrefetch()).thenReturn(false);
mProducer = mock(Producer.class);
mDataSource = CloseableProducerToDataSourceAdapter.create(
mProducer,
mSettableProducerContext,
mRequestListener);
ArgumentCaptor<Consumer> captor = ArgumentCaptor.forClass(Consumer.class);
verify(mRequestListener).onRequestStart(
mSettableProducerContext.getImageRequest(),
mSettableProducerContext.getCallerContext(),
mRequestId,
mSettableProducerContext.isPrefetch());
verify(mProducer).produceResults(captor.capture(), any(SettableProducerContext.class));
mInternalConsumer = captor.getValue();
mDataSource.subscribe(mDataSubscriber1, CallerThreadExecutor.getInstance());
}
示例7: setupNewSourceImage
import com.facebook.common.references.CloseableReference; //导入方法依赖的package包/类
private void setupNewSourceImage() {
mSourceBitmap = mock(Bitmap.class);
mSourceCloseableStaticBitmap = mock(CloseableStaticBitmap.class);
when(mSourceCloseableStaticBitmap.getUnderlyingBitmap()).thenReturn(mSourceBitmap);
mSourceCloseableImageRef =
CloseableReference.<CloseableImage>of(mSourceCloseableStaticBitmap);
}
示例8: handleResult
import com.facebook.common.references.CloseableReference; //导入方法依赖的package包/类
/**
* Notifies consumer of new result and finishes if the result is final.
*/
private void handleResult(final CloseableImage decodedImage, final @Status int status) {
CloseableReference<CloseableImage> decodedImageRef = CloseableReference.of(decodedImage);
try {
maybeFinish(isLast(status));
getConsumer().onNewResult(decodedImageRef, status);
} finally {
CloseableReference.closeSafely(decodedImageRef);
}
}
示例9: testParseMetaData_JPEG
import com.facebook.common.references.CloseableReference; //导入方法依赖的package包/类
@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());
}
示例10: setUp
import com.facebook.common.references.CloseableReference; //导入方法依赖的package包/类
@Before
public void setUp() {
MockitoAnnotations.initMocks(this);
mSettableDataSource1 = SettableDataSource.create();
mSettableDataSource2 = SettableDataSource.create();
mListDataSource = ListDataSource.create(mSettableDataSource1, mSettableDataSource2);
mRef1 = CloseableReference.of(1, mResourceReleaser);
mRef2 = CloseableReference.of(2, mResourceReleaser);
mRuntimeException = new RuntimeException();
mListDataSource.subscribe(mDataSubscriber, CallerThreadExecutor.getInstance());
}
示例11: checkWebpImage
import com.facebook.common.references.CloseableReference; //导入方法依赖的package包/类
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());
}
示例12: testIsJpegCompleteAt_notComplete
import com.facebook.common.references.CloseableReference; //导入方法依赖的package包/类
@Test
public void testIsJpegCompleteAt_notComplete() {
byte[] encodedBytes = new byte[ENCODED_BYTES_LENGTH];
encodedBytes[ENCODED_BYTES_LENGTH - 2] = 0;
encodedBytes[ENCODED_BYTES_LENGTH - 1] = 0;
PooledByteBuffer buf = new TrivialPooledByteBuffer(encodedBytes);
EncodedImage encodedImage = new EncodedImage(CloseableReference.of(buf));
encodedImage.setImageFormat(DefaultImageFormats.JPEG);
assertFalse(encodedImage.isCompleteAt(ENCODED_BYTES_LENGTH));
}
示例13: setUp
import com.facebook.common.references.CloseableReference; //导入方法依赖的package包/类
@Before
public void setUp() throws Exception {
MockitoAnnotations.initMocks(this);
mProgressiveJpegConfig = new SimpleProgressiveJpegConfig(
new SimpleProgressiveJpegConfig.DynamicValueConfig() {
public List<Integer> getScansToDecode() {
return Arrays.asList(PREVIEW_SCAN, GOOD_ENOUGH_SCAN);
}
public int getGoodEnoughScanNumber() {
return GOOD_ENOUGH_SCAN;
}
});
PowerMockito.mockStatic(ProgressiveJpegParser.class);
PowerMockito.whenNew(ProgressiveJpegParser.class).withAnyArguments()
.thenReturn(mProgressiveJpegParser);
PowerMockito.mockStatic(JobScheduler.class);
PowerMockito.whenNew(JobScheduler.class).withAnyArguments()
.thenReturn(mJobScheduler);
when(mExperimentalResizingEnabledSupplier.get()).thenReturn(false);
mDecodeProducer =
new DecodeProducer(
mByteArrayPool,
mExecutor,
mImageDecoder,
mProgressiveJpegConfig,
false, /* Set downsampleEnabled to false */
false, /* Set resizeAndRotateForNetwork to false */
false, /* We don't cancel when the request is cancelled */
mInputProducer,
mExperimentalResizingEnabledSupplier); /* No experimental resizing */
PooledByteBuffer pooledByteBuffer = mockPooledByteBuffer(IMAGE_SIZE);
mByteBufferRef = CloseableReference.of(pooledByteBuffer);
mEncodedImage = new EncodedImage(mByteBufferRef);
mEncodedImage.setImageFormat(DefaultImageFormats.JPEG);
mEncodedImage.setWidth(IMAGE_WIDTH);
mEncodedImage.setHeight(IMAGE_HEIGHT);
mEncodedImage.setRotationAngle(IMAGE_ROTATION_ANGLE);
mEncodedImage.setExifOrientation(IMAGE_EXIF_ORIENTATION);
}
示例14: testCreateWithDecodeAlFrames
import com.facebook.common.references.CloseableReference; //导入方法依赖的package包/类
@Test
public void testCreateWithDecodeAlFrames() throws Exception {
WebPImage mockWebPImage = mock(WebPImage.class);
Bitmap mockBitmap1 = MockBitmapFactory.create(50, 50, DEFAULT_BITMAP_CONFIG);
Bitmap mockBitmap2 = MockBitmapFactory.create(50, 50, DEFAULT_BITMAP_CONFIG);
// Expect a call to WebPImage.create
TrivialPooledByteBuffer byteBuffer = createByteBuffer();
when(mWebPImageMock.decode(byteBuffer.getNativePtr(), byteBuffer.size()))
.thenReturn(mockWebPImage);
when(mockWebPImage.getWidth()).thenReturn(50);
when(mockWebPImage.getHeight()).thenReturn(50);
// For decoding preview frame, expect some calls.
final AnimatedDrawableBackend mockAnimatedDrawableBackend =
createAnimatedDrawableBackendMock(2);
when(
mMockAnimatedDrawableBackendProvider.get(
any(AnimatedImageResult.class),
isNull(Rect.class)))
.thenReturn(mockAnimatedDrawableBackend);
when(mMockBitmapFactory.createBitmapInternal(50, 50, DEFAULT_BITMAP_CONFIG))
.thenReturn(CloseableReference.of(mockBitmap1, FAKE_BITMAP_RESOURCE_RELEASER))
.thenReturn(CloseableReference.of(mockBitmap2, FAKE_BITMAP_RESOURCE_RELEASER));
AnimatedImageCompositor mockCompositor = mock(AnimatedImageCompositor.class);
PowerMockito.whenNew(AnimatedImageCompositor.class)
.withAnyArguments()
.thenReturn(mockCompositor);
ImageDecodeOptions imageDecodeOptions = ImageDecodeOptions.newBuilder()
.setDecodePreviewFrame(true)
.setDecodeAllFrames(true)
.build();
EncodedImage encodedImage = new EncodedImage(
CloseableReference.of(byteBuffer, FAKE_RESOURCE_RELEASER));
encodedImage.setImageFormat(ImageFormat.UNKNOWN);
CloseableAnimatedImage closeableImage =
(CloseableAnimatedImage) mAnimatedImageFactory.decodeWebP(
encodedImage,
imageDecodeOptions,
DEFAULT_BITMAP_CONFIG);
// Verify we got the right result
AnimatedImageResult imageResult = closeableImage.getImageResult();
assertSame(mockWebPImage, imageResult.getImage());
assertNotNull(imageResult.getDecodedFrame(0));
assertNotNull(imageResult.getDecodedFrame(1));
assertNotNull(imageResult.getPreviewBitmap());
// Should not have interacted with these.
verify(mMockAnimatedDrawableBackendProvider).get(
any(AnimatedImageResult.class),
isNull(Rect.class));
verifyNoMoreInteractions(mMockAnimatedDrawableBackendProvider);
verify(mMockBitmapFactory, times(2)).createBitmapInternal(50, 50, DEFAULT_BITMAP_CONFIG);
verifyNoMoreInteractions(mMockBitmapFactory);
verify(mockCompositor).renderFrame(0, mockBitmap1);
verify(mockCompositor).renderFrame(1, mockBitmap2);
}
示例15: buildEncodedImage
import com.facebook.common.references.CloseableReference; //导入方法依赖的package包/类
private EncodedImage buildEncodedImage(TrivialPooledByteBuffer byteBuffer) {
return new EncodedImage(CloseableReference.<PooledByteBuffer>of(byteBuffer));
}