當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。