Package com.couchbase.lite.internal.core
Class C4BlobStore
- java.lang.Object
-
- com.couchbase.lite.internal.core.C4NativePeer
-
- com.couchbase.lite.internal.core.C4BlobStore
-
- All Implemented Interfaces:
AutoCloseable
public abstract class C4BlobStore extends C4NativePeer
Blob Store API
-
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description abstract void
close()
C4BlobKey
create(byte[] contents)
Stores a blob.void
delete()
void
delete(C4BlobKey blobKey)
Deletes a blob from the store given its key.FLSliceResult
getContents(C4BlobKey blobKey)
Reads the entire contents of a blob into memory.String
getFilePath(C4BlobKey blobKey)
Returns the path of the file that stores the blob, if possible.long
getSize(C4BlobKey blobKey)
Gets the content size of a blob given its key.static C4BlobStore
getUnmanagedBlobStore(long peer)
static C4BlobStore
open(String dirPath, long flags)
C4BlobReadStream
openReadStream(C4BlobKey blobKey)
Opens a blob for reading, as a random-access byte stream.C4BlobWriteStream
openWriteStream()
Opens a write stream for creating a new blob.-
Methods inherited from class com.couchbase.lite.internal.core.C4NativePeer
toString
-
-
-
-
Method Detail
-
getUnmanagedBlobStore
@NonNull public static C4BlobStore getUnmanagedBlobStore(long peer) throws LiteCoreException
- Throws:
LiteCoreException
-
open
@NonNull public static C4BlobStore open(@NonNull String dirPath, long flags) throws LiteCoreException
- Throws:
LiteCoreException
-
getSize
public long getSize(@NonNull C4BlobKey blobKey)
Gets the content size of a blob given its key. Returns -1 if it doesn't exist. WARNING: If the blob is encrypted, the return value is a conservative estimate that may be up to 16 bytes larger than the actual size.
-
getContents
@NonNull public FLSliceResult getContents(@NonNull C4BlobKey blobKey) throws LiteCoreException
Reads the entire contents of a blob into memory. Caller is responsible for freeing it.- Throws:
LiteCoreException
-
getFilePath
@Nullable public String getFilePath(@NonNull C4BlobKey blobKey) throws LiteCoreException
Returns the path of the file that stores the blob, if possible. This call may fail with error kC4ErrorWrongFormat if the blob is encrypted (in which case the file would be unreadable by the caller) or with kC4ErrorUnsupported if for some implementation reason the blob isn't stored as a standalone file. Thus, the caller MUST use this function only as an optimization, and fall back to reading he contents via the API if it fails. Also, it goes without saying that the caller MUST not modify the file!- Throws:
LiteCoreException
-
create
@NonNull public C4BlobKey create(@NonNull byte[] contents) throws LiteCoreException
Stores a blob. The associated key will be written to `outKey`.- Throws:
LiteCoreException
-
delete
public void delete(@NonNull C4BlobKey blobKey) throws LiteCoreException
Deletes a blob from the store given its key.- Throws:
LiteCoreException
-
openReadStream
@NonNull public C4BlobReadStream openReadStream(@NonNull C4BlobKey blobKey) throws LiteCoreException
Opens a blob for reading, as a random-access byte stream.- Throws:
LiteCoreException
-
openWriteStream
@NonNull public C4BlobWriteStream openWriteStream() throws LiteCoreException
Opens a write stream for creating a new blob. You should then call c4stream_write to write the data, ending with c4stream_install to compute the blob's key and add it to the store, and then c4stream_closeWriter.- Throws:
LiteCoreException
-
close
public abstract void close()
-
delete
public void delete() throws LiteCoreException
- Throws:
LiteCoreException
-
-