private Exception getExceptionIfNoSpace( final String filePath, final long fileSize, final long sizeTransferring) { // if this file can't fit in our cache. if (fileSize > localContentCache.getMaxCacheSize()) { return new IllegalStateException( String.format( "Adding '%s' of size %s would exceed the cache size by %s bytes.", filePath, StringFormatUtils.getBytesString(fileSize, true), StringFormatUtils.getBytesString( fileSize - localContentCache.getMaxCacheSize(), true))); } final long bytesOverSize = (sizeTransferring + fileSize) - localContentCache.getMaxCacheSize(); if (bytesOverSize > 0) { Log.w( LOG_TAG, String.format( "Adding '%s' of size %s causes in progress transfers to" + " exceed the cache size by %s bytes. Content that completes downloading first" + " will be dropped.", filePath, StringFormatUtils.getBytesString(fileSize, true), StringFormatUtils.getBytesString(bytesOverSize, true))); } return null; }
/* package */ ContentState getContentStateForTransfer(final String filePath) { if (!transferHelper.isTransferring(filePath)) { return ContentState.REMOTE; } boolean localContentAvailable = localContentCache.contains(filePath); if (transferHelper.isTransferWaiting(filePath)) { if (localContentAvailable) { return ContentState.CACHED_NEW_VERSION_TRANSFER_WAITING; } return ContentState.TRANSFER_WAITING; } if (localContentAvailable) { return ContentState.CACHED_TRANSFERRING_NEW_VERSION; } return ContentState.TRANSFERRING; }
/** * Checks whether a file has been pinned. * * @param filePath the relative path and file name. * @return true if content has been marked to be kept by calling {@link #pinContent(String)}, * otherwise returns false. */ public boolean isContentPinned(final String filePath) { return localContentCache.shouldPinFile(filePath); }
/** * Set a listener for any content removed from the cache managed by this content manager. * * @param listener the listening handler. */ public void setContentRemovedListener(final ContentRemovedListener listener) { localContentCache.setContentRemovedListener(listener); }
/** Clears all listeners associated with this content manager. */ public void clearAllListeners() { clearProgressListeners(); localContentCache.setContentRemovedListener(null); }
/** * Remove local content from the cache. * * @param filePath the path to the content to remove. * @return true if file will be removed asyncronously, false if the file could not be removed. */ public boolean removeLocal(final String filePath) { return localContentCache.removeFile(filePath); }
/** * Set the cache size to be used by this content manager. This immediately removes the oldest * content by last modified time until the new cache size is not exceeded. * * @param maxCacheSize the new max cache size. */ public void setContentCacheSize(final long maxCacheSize) { localContentCache.setMaxCacheSize(maxCacheSize); }
/** Number of bytes pinned to the cache. */ public long getPinnedSize() { return localContentCache.getBytesPinned(); }
/** @return the number of bytes used by the cache. */ public long getCacheUsedSize() { return localContentCache.getCacheSizeUsed(); }
/** @return the maximum number of bytes this cache may hold. */ public long getContentCacheSize() { return localContentCache.getMaxCacheSize(); }