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


Java CloseableReference.closeSafely方法代码示例

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


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

示例1: verifyState

import com.facebook.common.references.CloseableReference; //导入方法依赖的package包/类
private void verifyState(
    boolean isFinished,
    boolean hasResult,
    CloseableReference<Object> resultRef,
    boolean hasFailed,
    Throwable failureCause) {
  DataSource<CloseableReference<Object>> dataSource = mDataSource;
  assertEquals("isFinished", isFinished, dataSource.isFinished());
  assertEquals("hasResult", hasResult, dataSource.hasResult());
  CloseableReference<Object> dataSourceRef = dataSource.getResult();
  assertReferencesSame("getResult", resultRef, dataSourceRef);
  CloseableReference.closeSafely(dataSourceRef);
  assertEquals("hasFailed", hasFailed, dataSource.hasFailed());
  if (failureCause == NPE) {
    assertNotNull("failure", dataSource.getFailureCause());
    assertSame("failure", NullPointerException.class, dataSource.getFailureCause().getClass());
  } else {
    assertSame("failure", failureCause, dataSource.getFailureCause());
  }
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:21,代码来源:CloseableProducerToDataSourceAdapterTest.java

示例2: onFrameRendered

import com.facebook.common.references.CloseableReference; //导入方法依赖的package包/类
@Override
public synchronized void onFrameRendered(
    int frameNumber,
    CloseableReference<Bitmap> bitmapReference,
    @BitmapAnimationBackend.FrameType int frameType) {
  Preconditions.checkNotNull(bitmapReference);

  // Close up prepared references.
  removePreparedReference(frameNumber);

  // Create the new image reference and cache it.
  CloseableReference<CloseableImage> closableReference = null;
  try {
    closableReference = createImageReference(bitmapReference);
    if (closableReference != null) {
      CloseableReference.closeSafely(mLastRenderedItem);
      mLastRenderedItem = mAnimatedFrameCache.cache(frameNumber, closableReference);
    }
  } finally {
    CloseableReference.closeSafely(closableReference);
  }
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:23,代码来源:FrescoFrameCache.java

示例3: getInputStream

import com.facebook.common.references.CloseableReference; //导入方法依赖的package包/类
/**
 * Returns an InputStream from the internal InputStream Supplier if it's not null. Otherwise
 * returns an InputStream for the internal buffer reference if valid and null otherwise.
 *
 * <p>The caller has to close the InputStream after using it.
 */
public InputStream getInputStream() {
  if (mInputStreamSupplier != null) {
    return mInputStreamSupplier.get();
  }
  CloseableReference<PooledByteBuffer> pooledByteBufferRef =
      CloseableReference.cloneOrNull(mPooledByteBufferRef);
  if (pooledByteBufferRef != null) {
    try {
      return new PooledByteBufferInputStream(pooledByteBufferRef.get());
    } finally {
      CloseableReference.closeSafely(pooledByteBufferRef);
    }
  }
  return null;
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:22,代码来源:EncodedImage.java

示例4: convertToBitmapReferenceAndClose

import com.facebook.common.references.CloseableReference; //导入方法依赖的package包/类
/**
 * Converts the given image reference to a bitmap reference
 * and closes the original image reference.
 *
 * @param closeableImage the image to convert. It will be closed afterwards and will be invalid
 * @return the closeable bitmap reference to be used
 */
@VisibleForTesting
@Nullable
static CloseableReference<Bitmap> convertToBitmapReferenceAndClose(
    final @Nullable CloseableReference<CloseableImage> closeableImage) {
  try {
    if (CloseableReference.isValid(closeableImage) &&
        closeableImage.get() instanceof CloseableStaticBitmap) {

      CloseableStaticBitmap closeableStaticBitmap = (CloseableStaticBitmap) closeableImage.get();
      if (closeableStaticBitmap != null) {
        // We return a clone of the underlying bitmap reference that has to be manually closed
        // and then close the passed CloseableStaticBitmap in order to preserve correct
        // cache size calculations.
        return closeableStaticBitmap.cloneUnderlyingBitmapReference();
      }
    }
    // Not a bitmap reference, so we return null
    return null;
  } finally {
    CloseableReference.closeSafely(closeableImage);
  }
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:30,代码来源:FrescoFrameCache.java

示例5: process

import com.facebook.common.references.CloseableReference; //导入方法依赖的package包/类
@Override
public CloseableReference<Bitmap> process(Bitmap sourceBitmap, PlatformBitmapFactory bitmapFactory) {
    float scale = 1.0f * width / sourceBitmap.getWidth();
    Log.e("ReScalePostprocessor", "scale:" + scale);

    scaledWidth = (int) (sourceBitmap.getWidth() * scale);
    scaledHeight = (int) (sourceBitmap.getHeight() * scale);

    listener.onProcessFinished(scaledWidth, scaledHeight);

    Matrix matrix = new Matrix();
    matrix.postScale(scale, scale);
    Bitmap bitmap = Bitmap.createBitmap(sourceBitmap, 0, 0, sourceBitmap.getWidth(), sourceBitmap.getHeight(), matrix, true);
    CloseableReference<Bitmap> bitmapRef = bitmapFactory.createBitmap(bitmap);
    try {
        return CloseableReference.cloneOrNull(bitmapRef);
    } finally {
        CloseableReference.closeSafely(bitmapRef);
    }
}
 
开发者ID:Bleoo,项目名称:WindowImageView,代码行数:21,代码来源:ReScalePostprocessor.java

示例6: onNewResultImpl

import com.facebook.common.references.CloseableReference; //导入方法依赖的package包/类
@Override
public void onNewResultImpl(DataSource<CloseableReference<CloseableImage>> dataSource) {
  if (!dataSource.isFinished()) {
    return;
  }

  CloseableReference<CloseableImage> closeableImageRef = dataSource.getResult();
  Bitmap bitmap = null;
  if (closeableImageRef != null &&
      closeableImageRef.get() instanceof CloseableBitmap) {
    bitmap = ((CloseableBitmap) closeableImageRef.get()).getUnderlyingBitmap();
  }

  try {
    onNewResultImpl(bitmap);
  } finally {
    CloseableReference.closeSafely(closeableImageRef);
  }
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:20,代码来源:BaseBitmapDataSubscriber.java

示例7: decodeJPEGFromEncodedImage

import com.facebook.common.references.CloseableReference; //导入方法依赖的package包/类
/**
 * Creates a bitmap from encoded JPEG bytes. Supports a partial JPEG image.
 *
 * @param encodedImage the encoded image with reference to the encoded bytes
 * @param bitmapConfig the {@link android.graphics.Bitmap.Config} used to create the decoded
 *     Bitmap
 * @param regionToDecode optional image region to decode. currently not supported.
 * @param length the number of encoded bytes in the buffer
 * @return the bitmap
 * @throws TooManyBitmapsException if the pool is full
 * @throws java.lang.OutOfMemoryError if the Bitmap cannot be allocated
 */
@Override
public CloseableReference<Bitmap> decodeJPEGFromEncodedImage(
    final EncodedImage encodedImage,
    Bitmap.Config bitmapConfig,
    @Nullable Rect regionToDecode,
    int length) {
  BitmapFactory.Options options = getBitmapFactoryOptions(
      encodedImage.getSampleSize(),
      bitmapConfig);
  final CloseableReference<PooledByteBuffer> bytesRef = encodedImage.getByteBufferRef();
  Preconditions.checkNotNull(bytesRef);
  try {
    Bitmap bitmap = decodeJPEGByteArrayAsPurgeable(bytesRef, length, options);
    return pinBitmap(bitmap);
  } finally {
    CloseableReference.closeSafely(bytesRef);
  }
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:31,代码来源:DalvikPurgeableDecoder.java

示例8: cloneOrNull

import com.facebook.common.references.CloseableReference; //导入方法依赖的package包/类
public EncodedImage cloneOrNull() {
  EncodedImage encodedImage;
  if (mInputStreamSupplier != null) {
      encodedImage = new EncodedImage(mInputStreamSupplier, mStreamSize);
  } else {
    CloseableReference<PooledByteBuffer> pooledByteBufferRef =
        CloseableReference.cloneOrNull(mPooledByteBufferRef);
    try {
      encodedImage = (pooledByteBufferRef == null) ? null : new EncodedImage(pooledByteBufferRef);
    } finally {
      // Close the recently created reference since it will be cloned again in the constructor.
      CloseableReference.closeSafely(pooledByteBufferRef);
    }
  }
  if (encodedImage != null) {
    encodedImage.copyMetaDataFrom(this);
  }
  return encodedImage;
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:20,代码来源:EncodedImage.java

示例9: releaseCloseReference

import com.facebook.common.references.CloseableReference; //导入方法依赖的package包/类
/**
 * 释放引用
 *
 * @param reference    需要被释放的引用
 * @param isReleaseAll 当前释放请求是否在释放全部引用时调用
 */
public void releaseCloseReference(CloseableReference reference, boolean isReleaseAll) {
    if (mFrescoListener != null && !isReleaseAll) {
        //独自通知功能只在单独释放某个引用时才调用
        mFrescoListener.onReferenceRelease(reference);
    }
    CloseableReference.closeSafely(reference);
    reference = null;
}
 
开发者ID:6ag,项目名称:LiuAGeAndroid,代码行数:15,代码来源:FrescoBitmapUtils.java

示例10: postprocessInternal

import com.facebook.common.references.CloseableReference; //导入方法依赖的package包/类
private CloseableReference<CloseableImage> postprocessInternal(CloseableImage sourceImage) {
  CloseableStaticBitmap staticBitmap = (CloseableStaticBitmap) sourceImage;
  Bitmap sourceBitmap = staticBitmap.getUnderlyingBitmap();
  CloseableReference<Bitmap> bitmapRef = mPostprocessor.process(sourceBitmap, mBitmapFactory);
  int rotationAngle = staticBitmap.getRotationAngle();
  int exifOrientation = staticBitmap.getExifOrientation();
  try {
    return CloseableReference.<CloseableImage>of(
        new CloseableStaticBitmap(
            bitmapRef, sourceImage.getQualityInfo(), rotationAngle, exifOrientation));
  } finally {
    CloseableReference.closeSafely(bitmapRef);
  }
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:15,代码来源:PostprocessorProducer.java

示例11: close

import com.facebook.common.references.CloseableReference; //导入方法依赖的package包/类
private boolean close() {
  CloseableReference<CloseableImage> oldSourceImageRef;
  synchronized (RepeatedPostprocessorConsumer.this) {
    if (mIsClosed) {
      return false;
    }
    oldSourceImageRef = mSourceImageRef;
    mSourceImageRef = null;
    mIsClosed = true;
  }
  CloseableReference.closeSafely(oldSourceImageRef);
  return true;
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:14,代码来源:PostprocessorProducer.java

示例12: closeAndResetLastBitmapReference

import com.facebook.common.references.CloseableReference; //导入方法依赖的package包/类
private synchronized void closeAndResetLastBitmapReference() {
  if (mFrameCacheListener != null && mLastFrameNumber != FRAME_NUMBER_UNSET) {
    mFrameCacheListener.onFrameEvicted(this, mLastFrameNumber);
  }
  CloseableReference.closeSafely(mLastBitmapReference);
  mLastBitmapReference = null;
  mLastFrameNumber = FRAME_NUMBER_UNSET;
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:9,代码来源:KeepLastFrameCache.java

示例13: clear

import com.facebook.common.references.CloseableReference; //导入方法依赖的package包/类
@Override
public synchronized void clear() {
  CloseableReference.closeSafely(mLastRenderedItem);
  mLastRenderedItem = null;
  for (int i = 0; i < mPreparedPendingFrames.size(); i++) {
    CloseableReference.closeSafely(mPreparedPendingFrames.valueAt(i));
  }
  mPreparedPendingFrames.clear();
  // The frame cache will free items when needed
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:11,代码来源:FrescoFrameCache.java

示例14: removePreparedReference

import com.facebook.common.references.CloseableReference; //导入方法依赖的package包/类
private synchronized void removePreparedReference(int frameNumber) {
  CloseableReference<CloseableImage> existingPendingReference =
      mPreparedPendingFrames.get(frameNumber);
  if (existingPendingReference != null) {
    mPreparedPendingFrames.delete(frameNumber);
    CloseableReference.closeSafely(existingPendingReference);
    FLog.v(
        TAG,
        "removePreparedReference(%d) removed. Pending frames: %s",
        frameNumber,
        mPreparedPendingFrames);
  }
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:14,代码来源:FrescoFrameCache.java

示例15: close

import com.facebook.common.references.CloseableReference; //导入方法依赖的package包/类
/**
 * Closes the stream. Owned resources are released back to the pool. It is not allowed to call
 * toByteBuffer after call to this method.
 * @throws IOException
 */
@Override
public void close() {
  CloseableReference.closeSafely(mBufRef);
  mBufRef = null;
  mCount = -1;
  super.close();
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:13,代码来源:NativePooledByteBufferOutputStream.java


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