当前位置: 首页>>代码示例>>Java>>正文


Java CloseableReference.close方法代码示例

本文整理汇总了Java中com.facebook.common.references.CloseableReference.close方法的典型用法代码示例。如果您正苦于以下问题:Java CloseableReference.close方法的具体用法?Java CloseableReference.close怎么用?Java CloseableReference.close使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在com.facebook.common.references.CloseableReference的用法示例。


在下文中一共展示了CloseableReference.close方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: testSuccess

import com.facebook.common.references.CloseableReference; //导入方法依赖的package包/类
@Test
public void testSuccess() {
  SingleUsePostprocessorConsumer postprocessorConsumer = produceResults();
  doReturn(mDestinationCloseableBitmapRef)
      .when(mPostprocessor).process(mSourceBitmap, mPlatformBitmapFactory);
  postprocessorConsumer.onNewResult(mSourceCloseableImageRef, Consumer.IS_LAST);
  mSourceCloseableImageRef.close();
  mTestExecutorService.runUntilIdle();

  mInOrder.verify(mProducerListener).onProducerStart(mRequestId, PostprocessorProducer.NAME);
  mInOrder.verify(mPostprocessor).process(mSourceBitmap, mPlatformBitmapFactory);
  mInOrder.verify(mProducerListener).requiresExtraMap(mRequestId);
  mInOrder.verify(mProducerListener)
      .onProducerFinishWithSuccess(mRequestId, PostprocessorProducer.NAME, mExtraMap);
  mInOrder.verify(mConsumer).onNewResult(any(CloseableReference.class), eq(Consumer.IS_LAST));
  mInOrder.verifyNoMoreInteractions();

  assertEquals(1, mResults.size());
  CloseableReference<CloseableImage> res0 = mResults.get(0);
  assertTrue(CloseableReference.isValid(res0));
  assertSame(mDestinationBitmap, ((CloseableStaticBitmap) res0.get()).getUnderlyingBitmap());
  res0.close();

  verify(mBitmapResourceReleaser).release(mDestinationBitmap);
  verify(mSourceCloseableStaticBitmap).close();
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:27,代码来源:SingleUsePostprocessorProducerTest.java

示例2: testReuseExclusive_CacheSameItemWithDifferentKey

import com.facebook.common.references.CloseableReference; //导入方法依赖的package包/类
@Test
public void testReuseExclusive_CacheSameItemWithDifferentKey() {
  CloseableReference<Integer> cachedRef =
      mCache.cache(KEY, newReference(100), mEntryStateObserver);
  cachedRef.close();
  verify(mEntryStateObserver).onExclusivityChanged(KEY, true);
  assertTotalSize(1, 100);
  assertExclusivelyOwnedSize(1, 100);
  cachedRef = mCache.reuse(KEY);
  assertNotNull(cachedRef);
  verify(mEntryStateObserver).onExclusivityChanged(KEY, false);
  assertTotalSize(0, 0);
  assertExclusivelyOwnedSize(0, 0);
  CloseableReference<Integer> newItem = mCache.cache(KEYS[2], cachedRef);
  cachedRef.close();
  assertTotalSize(1, 100);
  assertExclusivelyOwnedSize(0, 0);
  newItem.close();
  verify(mEntryStateObserver).onExclusivityChanged(KEY, true);
  assertTotalSize(1, 100);
  assertExclusivelyOwnedSize(1, 100);
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:23,代码来源:CountingMemoryCacheTest.java

示例3: testNonStaticBitmapIsPassedOn

import com.facebook.common.references.CloseableReference; //导入方法依赖的package包/类
@Test
public void testNonStaticBitmapIsPassedOn() {
  SingleUsePostprocessorConsumer postprocessorConsumer = produceResults();
  CloseableAnimatedImage sourceCloseableAnimatedImage = mock(CloseableAnimatedImage.class);
  CloseableReference<CloseableImage> sourceCloseableImageRef =
      CloseableReference.<CloseableImage>of(sourceCloseableAnimatedImage);
  postprocessorConsumer.onNewResult(sourceCloseableImageRef, Consumer.IS_LAST);
  sourceCloseableImageRef.close();
  mTestExecutorService.runUntilIdle();

  mInOrder.verify(mConsumer).onNewResult(any(CloseableReference.class), eq(Consumer.IS_LAST));
  mInOrder.verifyNoMoreInteractions();

  assertEquals(1, mResults.size());
  CloseableReference<CloseableImage> res0 = mResults.get(0);
  assertTrue(CloseableReference.isValid(res0));
  assertSame(sourceCloseableAnimatedImage, res0.get());
  res0.close();

  verify(sourceCloseableAnimatedImage).close();
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:22,代码来源:AnimatedSingleUsePostprocessorProducerTest.java

示例4: decodeStaticImage

import com.facebook.common.references.CloseableReference; //导入方法依赖的package包/类
/**
 * @param encodedImage input image (encoded bytes plus meta data)
 * @return a CloseableStaticBitmap
 */
public CloseableStaticBitmap decodeStaticImage(
    final EncodedImage encodedImage,
    ImageDecodeOptions options) {
  CloseableReference<Bitmap> bitmapReference =
      mPlatformDecoder.decodeFromEncodedImage(encodedImage, options.bitmapConfig, null);
  try {
    return new CloseableStaticBitmap(
        bitmapReference,
        ImmutableQualityInfo.FULL_QUALITY,
        encodedImage.getRotationAngle(),
        encodedImage.getExifOrientation());
  } finally {
    bitmapReference.close();
  }
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:20,代码来源:DefaultImageDecoder.java

示例5: verifyNewResultProcessed

import com.facebook.common.references.CloseableReference; //导入方法依赖的package包/类
private void verifyNewResultProcessed(int index, Bitmap destBitmap) {
  mInOrder.verify(mProducerListener).onProducerStart(mRequestId, PostprocessorProducer.NAME);
  mInOrder.verify(mPostprocessor).process(mSourceBitmap, mPlatformBitmapFactory);
  mInOrder.verify(mProducerListener).requiresExtraMap(mRequestId);
  mInOrder.verify(mProducerListener)
      .onProducerFinishWithSuccess(mRequestId, PostprocessorProducer.NAME, mExtraMap);
  mInOrder.verify(mConsumer).onNewResult(any(CloseableReference.class), eq(Consumer.NO_FLAGS));
  mInOrder.verifyNoMoreInteractions();

  assertEquals(index + 1, mResults.size());
  CloseableReference<CloseableImage> res0 = mResults.get(index);
  assertTrue(CloseableReference.isValid(res0));
  assertSame(destBitmap, ((CloseableStaticBitmap) res0.get()).getUnderlyingBitmap());
  res0.close();
  verify(mBitmapResourceReleaser).release(destBitmap);
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:17,代码来源:AnimatedRepeatedPostprocessorProducerTest.java

示例6: getFirstBytesAsHexString

import com.facebook.common.references.CloseableReference; //导入方法依赖的package包/类
/**
 * Returns first n bytes of encoded image as hexbytes
 *
 * @param length the number of bytes to return
 */
public String getFirstBytesAsHexString(int length) {
  CloseableReference<PooledByteBuffer> imageBuffer = getByteBufferRef();
  if (imageBuffer == null) {
    return "";
  }
  int imageSize = getSize();
  int resultSampleSize = Math.min(imageSize, length);
  byte[] bytesBuffer = new byte[resultSampleSize];
  try {
    PooledByteBuffer pooledByteBuffer = imageBuffer.get();
    if (pooledByteBuffer == null) {
      return "";
    }
    pooledByteBuffer.read(0, bytesBuffer, 0, resultSampleSize);
  } finally {
    imageBuffer.close();
  }
  StringBuilder stringBuilder = new StringBuilder(bytesBuffer.length * 2);
  for (byte b : bytesBuffer) {
    stringBuilder.append(String.format("%02X", b));
  }
  return stringBuilder.toString();
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:29,代码来源:EncodedImage.java

示例7: prepareCanvasWithClosestCachedFrame

import com.facebook.common.references.CloseableReference; //导入方法依赖的package包/类
/**
 * Given a frame number, prepares the canvas to render based on the nearest cached frame
 * at or before the frame. On return the canvas will be prepared as if the nearest cached
 * frame had been rendered and disposed. The returned index is the next frame that needs to be
 * composited onto the canvas.
 *
 * @param previousFrameNumber the frame number that is ones less than the one we're rendering
 * @param canvas the canvas to prepare
 * @return the index of the the next frame to process
 */
private int prepareCanvasWithClosestCachedFrame(int previousFrameNumber, Canvas canvas) {
  for (int index = previousFrameNumber; index >= 0; index--) {
    FrameNeededResult neededResult = isFrameNeededForRendering(index);
    switch (neededResult) {
      case REQUIRED:
        AnimatedDrawableFrameInfo frameInfo = mAnimatedDrawableBackend.getFrameInfo(index);
        CloseableReference<Bitmap> startBitmap = mCallback.getCachedBitmap(index);
        if (startBitmap != null) {
          try {
            canvas.drawBitmap(startBitmap.get(), 0, 0, null);
            if (frameInfo.disposalMethod == DisposalMethod.DISPOSE_TO_BACKGROUND) {
              disposeToBackground(canvas, frameInfo);
            }
            return index + 1;
          } finally {
            startBitmap.close();
          }
        } else {
          if (isKeyFrame(index)) {
            return index;
          } else {
            // Keep going.
            break;
          }
        }
      case NOT_REQUIRED:
        return index + 1;
      case ABORT:
        return index;
      case SKIP:
      default:
        // Keep going.
    }
  }
  return 0;
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:47,代码来源:AnimatedImageCompositor.java

示例8: testContainsWhenReused

import com.facebook.common.references.CloseableReference; //导入方法依赖的package包/类
@Test
public void testContainsWhenReused() {
  CloseableReference<CloseableImage> ret = mAnimatedFrameCache.cache(1, mFrame1);
  ret.close();

  assertTrue(mAnimatedFrameCache.contains(1));
  assertFalse(mAnimatedFrameCache.contains(2));

  CloseableReference<CloseableImage> free = mAnimatedFrameCache.getForReuse();
  free.close();

  assertFalse(mAnimatedFrameCache.contains(1));
  assertFalse(mAnimatedFrameCache.contains(2));
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:15,代码来源:AnimatedFrameCacheTest.java

示例9: close

import com.facebook.common.references.CloseableReference; //导入方法依赖的package包/类
/**
 * Releases the bitmap to the pool.
 */
@Override
public void close() {
  CloseableReference<Bitmap> reference = detachBitmapReference();
  if (reference != null) {
    reference.close();
  }
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:11,代码来源:CloseableStaticBitmap.java

示例10: testClosingOriginalReference

import com.facebook.common.references.CloseableReference; //导入方法依赖的package包/类
@Test
public void testClosingOriginalReference() {
  CloseableReference<Integer> originalRef = newReference(100);
  mCache.cache(KEY, originalRef);
  // cache should make its own copy and closing the original reference after caching
  // should not affect the cached value
  originalRef.close();
  assertTotalSize(1, 100);
  assertExclusivelyOwnedSize(0, 0);
  assertSharedWithCount(KEY, 100, 1);
  verify(mReleaser, never()).release(anyInt());
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:13,代码来源:CountingMemoryCacheTest.java

示例11: testGet_Realloc

import com.facebook.common.references.CloseableReference; //导入方法依赖的package包/类
@Test
public void testGet_Realloc() {
  CloseableReference<byte[]> arrayRef = mPool.get(1);
  final byte[] smallArray = arrayRef.get();
  arrayRef.close();

  arrayRef = mPool.get(7);
  assertEquals(8, arrayRef.get().length);
  assertNotSame(smallArray, arrayRef.get());
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:11,代码来源:FlexByteArrayPoolTest.java

示例12: testCantReuseNonExclusive

import com.facebook.common.references.CloseableReference; //导入方法依赖的package包/类
@Test
public void testCantReuseNonExclusive() {
  CloseableReference<Integer> cachedRef =
      mCache.cache(KEY, newReference(100), mEntryStateObserver);
  assertTotalSize(1, 100);
  assertExclusivelyOwnedSize(0, 0);
  CloseableReference<Integer> reusedRef = mCache.reuse(KEY);
  assertNull(reusedRef);
  assertTotalSize(1, 100);
  assertExclusivelyOwnedSize(0, 0);
  verify(mEntryStateObserver, never()).onExclusivityChanged(anyString(), anyBoolean());
  cachedRef.close();
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:14,代码来源:CountingMemoryCacheTest.java

示例13: testEviction_ByEvictionQueueSize

import com.facebook.common.references.CloseableReference; //导入方法依赖的package包/类
@Test
public void testEviction_ByEvictionQueueSize() {
  CloseableReference<Integer> originalRef1 = newReference(200);
  CloseableReference<Integer> valueRef1 = mCache.cache(KEYS[1], originalRef1);
  originalRef1.close();
  valueRef1.close();
  CloseableReference<Integer> originalRef2 = newReference(300);
  CloseableReference<Integer> valueRef2 = mCache.cache(KEYS[2], originalRef2);
  originalRef2.close();
  valueRef2.close();
  CloseableReference<Integer> originalRef3 = newReference(700);
  CloseableReference<Integer> valueRef3 = mCache.cache(KEYS[3], originalRef3);
  originalRef3.close();
  assertTotalSize(3, 1200);
  assertExclusivelyOwnedSize(2, 500);
  assertExclusivelyOwned(KEYS[1], 200);
  assertExclusivelyOwned(KEYS[2], 300);
  assertSharedWithCount(KEYS[3], 700, 1);
  verify(mReleaser, never()).release(anyInt());

  // closing the client reference for item3 will cause item1 to be evicted
  valueRef3.close();
  assertTotalSize(2, 1000);
  assertExclusivelyOwnedSize(2, 1000);
  assertNotCached(KEYS[1], 200);
  assertExclusivelyOwned(KEYS[2], 300);
  assertExclusivelyOwned(KEYS[3], 700);
  verify(mReleaser).release(200);
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:30,代码来源:CountingMemoryCacheTest.java

示例14: onNewResult

import com.facebook.common.references.CloseableReference; //导入方法依赖的package包/类
@Override
public void onNewResult(DataSource<CloseableReference<CloseableImage>> dataSource) {
  if (!dataSource.isFinished()) {
    // only interested in final image, no need to close the dataSource
    return;
  }

  try {
    if (mDataSource != dataSource) {
      // Shouldn't ever happen, but let's be safe (dataSource got closed by callback still fired?)
      return;
    }

    mDataSource = null;

    CloseableReference<CloseableImage> imageReference = dataSource.getResult();
    if (imageReference == null) {
      // Shouldn't ever happen, but let's be safe (dataSource got closed by callback still fired?)
      return;
    }

    CloseableImage image = imageReference.get();
    if (!(image instanceof CloseableBitmap)) {
      // only bitmaps are supported
      imageReference.close();
      return;
    }

    mImageRef = imageReference;

    Bitmap bitmap = getBitmap();
    if (bitmap == null) {
      // Shouldn't ever happen, but let's be safe.
      return;
    }

    BitmapUpdateListener listener = Assertions.assumeNotNull(mBitmapUpdateListener);
    listener.onBitmapReady(bitmap);
    listener.onImageLoadEvent(ImageLoadEvent.ON_LOAD);
    listener.onImageLoadEvent(ImageLoadEvent.ON_LOAD_END);
  } finally {
    dataSource.close();
  }
}
 
开发者ID:qq565999484,项目名称:RNLearn_Project1,代码行数:45,代码来源:PipelineRequestHelper.java

示例15: produceResults

import com.facebook.common.references.CloseableReference; //导入方法依赖的package包/类
@Override
public void produceResults(
    final Consumer<CloseableReference<CloseableImage>> consumer,
    final ProducerContext producerContext) {

  final ProducerListener listener = producerContext.getListener();
  final String requestId = producerContext.getId();
  final ImageRequest imageRequest = producerContext.getImageRequest();
  final Object callerContext = producerContext.getCallerContext();

  // If there's no postprocessor or the postprocessor doesn't require caching, forward results.
  final Postprocessor postprocessor = imageRequest.getPostprocessor();
  if (postprocessor == null || postprocessor.getPostprocessorCacheKey() == null) {
    mInputProducer.produceResults(consumer, producerContext);
    return;
  }
  listener.onProducerStart(requestId, getProducerName());
  final CacheKey cacheKey =
      mCacheKeyFactory.getPostprocessedBitmapCacheKey(imageRequest, callerContext);
  CloseableReference<CloseableImage> cachedReference = mMemoryCache.get(cacheKey);
  if (cachedReference != null) {
    listener.onProducerFinishWithSuccess(
        requestId,
        getProducerName(),
        listener.requiresExtraMap(requestId) ? ImmutableMap.of(VALUE_FOUND, "true") : null);
    listener.onUltimateProducerReached(requestId, PRODUCER_NAME, true);
    consumer.onProgressUpdate(1.0f);
    consumer.onNewResult(cachedReference, Consumer.IS_LAST);
    cachedReference.close();
  } else {
    final boolean isRepeatedProcessor = postprocessor instanceof RepeatedPostprocessor;
    Consumer<CloseableReference<CloseableImage>> cachedConsumer = new CachedPostprocessorConsumer(
        consumer,
        cacheKey,
        isRepeatedProcessor,
        mMemoryCache);
    listener.onProducerFinishWithSuccess(
        requestId,
        getProducerName(),
        listener.requiresExtraMap(requestId) ? ImmutableMap.of(VALUE_FOUND, "false") : null);
    mInputProducer.produceResults(cachedConsumer, producerContext);
  }
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:44,代码来源:PostprocessedBitmapMemoryCacheProducer.java


注:本文中的com.facebook.common.references.CloseableReference.close方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。