Package org.openhab.core.cache.lru
Class LRUMediaCacheEntry<V>
java.lang.Object
org.openhab.core.cache.lru.LRUMediaCacheEntry<V>
A cached media entry resulting from a call to a supplier or a load from disk
 This class also adds the capability to serve multiple InputStream concurrently
 without asking already retrieved data to the wrapped stream.
- Author:
- Gwendal Roulleau - Initial contribution
- 
Field SummaryFields
- 
Constructor SummaryConstructorsConstructorDescriptionLRUMediaCacheEntry(String key) This constructor is used when the file is fully cached on disk.LRUMediaCacheEntry(String key, InputStream inputStream, @Nullable V metadata) This constructor is used when the file is not yet cached on disk.
- 
Method SummaryModifier and TypeMethodDescriptionprotected intavailableFrom(int offset) Return the number of bytes that we can actually read without calling the underlying streamprotected voidThis method is called by a wrapper when it has been closed by a client The file and the inner stream could then be closed, if and only if no other client are accessing it.protected voidDelete the cache file linked to this entryprotected longGet the current sizeOpen an InputStream wrapped around the file There could be several clients InputStream on the same cache resultprotected StringgetKey()Get the key identifying this cache entry@Nullable VGet metadata for this cache result.protected longGet total size of the underlying stream.booleanisFaulty()protected byte[]read(int start, int sizeToRead) Read from the cached file.protected voidsetCacheContext(Path cacheDirectory, Storage<V> storage) Link this cache entry to the underlying storage facility (disk for data, storage service for metadata)
- 
Field Details- 
currentSizeprotected long currentSize
 
- 
- 
Constructor Details- 
LRUMediaCacheEntryThis constructor is used when the file is fully cached on disk. The file on disk will provide the data, and the storage will provide metadata.- Parameters:
- key- A unique key to identify the produced data
 
- 
LRUMediaCacheEntryThis constructor is used when the file is not yet cached on disk. Data is provided by the arguments- Parameters:
- key- A unique key to identify the produced data
- inputStream- The data stream
- metadata- optional metadata to store along the stream
 
 
- 
- 
Method Details- 
setCacheContextLink this cache entry to the underlying storage facility (disk for data, storage service for metadata)- Parameters:
- cacheDirectory-
- storage-
 
- 
getTotalSizeprotected long getTotalSize()Get total size of the underlying stream. If not already completed, will query the stream inside, or get all the data.- Returns:
 
- 
getCurrentSizeprotected long getCurrentSize()Get the current size- Returns:
 
- 
getKeyGet the key identifying this cache entry- Returns:
 
- 
getInputStreamOpen an InputStream wrapped around the file There could be several clients InputStream on the same cache result- Returns:
- A new InputStream with data from the cache
- Throws:
- IOException
 
- 
closeStreamClientThis method is called by a wrapper when it has been closed by a client The file and the inner stream could then be closed, if and only if no other client are accessing it.- Throws:
- IOException
 
- 
getMetadataGet metadata for this cache result.- Returns:
- metadata
 
- 
readRead from the cached file. If there is not enough bytes to read in the file, the supplier will be queried.- Parameters:
- start- The offset to read the file from
- sizeToRead- the number of byte to read
- Returns:
- A byte array from the file. The size may or may not be the sizeToRead requested
- Throws:
- IOException
 
- 
availableFromprotected int availableFrom(int offset) Return the number of bytes that we can actually read without calling the underlying stream- Parameters:
- offset-
- Returns:
 
- 
deleteFileprotected void deleteFile()Delete the cache file linked to this entry
- 
isFaultypublic boolean isFaulty()
 
-