Class FsBlobContainer
- java.lang.Object
-
- org.elasticsearch.common.blobstore.support.AbstractBlobContainer
-
- org.elasticsearch.common.blobstore.fs.FsBlobContainer
-
- All Implemented Interfaces:
BlobContainer
public class FsBlobContainer extends AbstractBlobContainer
A file system based implementation ofBlobContainer. All blobs in the container are stored on a file system, the location of which is specified by theBlobPath. Note that the methods in this implementation ofBlobContainermay additionally throw aSecurityExceptionif the configuredSecurityManagerdoes not permit read and/or write access to the underlying files.
-
-
Field Summary
Fields Modifier and Type Field Description protected FsBlobStoreblobStoreprotected java.nio.file.Pathpath
-
Constructor Summary
Constructors Constructor Description FsBlobContainer(FsBlobStore blobStore, BlobPath blobPath, java.nio.file.Path path)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description booleanblobExists(java.lang.String blobName)Tests whether a blob with the given blob name exists in the container.voiddeleteBlob(java.lang.String blobName)Deletes a blob with giving name, if the blob exists.static booleanisTempBlobName(java.lang.String blobName)Returns true if the blob is a leftover temporary blob.java.util.Map<java.lang.String,BlobMetaData>listBlobs()Lists all blobs in the container.java.util.Map<java.lang.String,BlobMetaData>listBlobsByPrefix(java.lang.String blobNamePrefix)Lists all blobs in the container that match the specified prefix.voidmoveBlobAtomic(java.lang.String sourceBlobName, java.lang.String targetBlobName, boolean failIfAlreadyExists)java.io.InputStreamreadBlob(java.lang.String name)Creates a newInputStreamfor the given blob name.static java.lang.StringtempBlobName(java.lang.String blobName)voidwriteBlob(java.lang.String blobName, java.io.InputStream inputStream, long blobSize, boolean failIfAlreadyExists)Reads blob content from the input stream and writes it to the container in a new blob with the given name.voidwriteBlobAtomic(java.lang.String blobName, java.io.InputStream inputStream, long blobSize, boolean failIfAlreadyExists)Reads blob content from the input stream and writes it to the container in a new blob with the given name, using an atomic write operation if the implementation supports it.-
Methods inherited from class org.elasticsearch.common.blobstore.support.AbstractBlobContainer
path
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface org.elasticsearch.common.blobstore.BlobContainer
deleteBlobIgnoringIfNotExists
-
-
-
-
Field Detail
-
blobStore
protected final FsBlobStore blobStore
-
path
protected final java.nio.file.Path path
-
-
Constructor Detail
-
FsBlobContainer
public FsBlobContainer(FsBlobStore blobStore, BlobPath blobPath, java.nio.file.Path path)
-
-
Method Detail
-
listBlobs
public java.util.Map<java.lang.String,BlobMetaData> listBlobs() throws java.io.IOException
Description copied from interface:BlobContainerLists all blobs in the container.- Returns:
- A map of all the blobs in the container. The keys in the map are the names of the blobs and
the values are
BlobMetaData, containing basic information about each blob. - Throws:
java.io.IOException- if there were any failures in reading from the blob container.
-
listBlobsByPrefix
public java.util.Map<java.lang.String,BlobMetaData> listBlobsByPrefix(java.lang.String blobNamePrefix) throws java.io.IOException
Description copied from interface:BlobContainerLists all blobs in the container that match the specified prefix.- Parameters:
blobNamePrefix- The prefix to match against blob names in the container.- Returns:
- A map of the matching blobs in the container. The keys in the map are the names of the blobs
and the values are
BlobMetaData, containing basic information about each blob. - Throws:
java.io.IOException- if there were any failures in reading from the blob container.
-
deleteBlob
public void deleteBlob(java.lang.String blobName) throws java.io.IOExceptionDescription copied from interface:BlobContainerDeletes a blob with giving name, if the blob exists. If the blob does not exist, this method throws a NoSuchFileException.- Parameters:
blobName- The name of the blob to delete.- Throws:
java.nio.file.NoSuchFileException- if the blob does not existjava.io.IOException- if the blob exists but could not be deleted.
-
blobExists
public boolean blobExists(java.lang.String blobName)
Description copied from interface:BlobContainerTests whether a blob with the given blob name exists in the container.- Parameters:
blobName- The name of the blob whose existence is to be determined.- Returns:
trueif a blob exists in theBlobContainerwith the given name, andfalseotherwise.
-
readBlob
public java.io.InputStream readBlob(java.lang.String name) throws java.io.IOExceptionDescription copied from interface:BlobContainerCreates a newInputStreamfor the given blob name.- Parameters:
name- The name of the blob to get anInputStreamfor.- Returns:
- The
InputStreamto read the blob. - Throws:
java.nio.file.NoSuchFileException- if the blob does not existjava.io.IOException- if the blob can not be read.
-
writeBlob
public void writeBlob(java.lang.String blobName, java.io.InputStream inputStream, long blobSize, boolean failIfAlreadyExists) throws java.io.IOExceptionDescription copied from interface:BlobContainerReads blob content from the input stream and writes it to the container in a new blob with the given name. This method assumes the container does not already contain a blob of the same blobName. If a blob by the same name already exists, the operation will fail and anIOExceptionwill be thrown.- Parameters:
blobName- The name of the blob to write the contents of the input stream to.inputStream- The input stream from which to retrieve the bytes to write to the blob.blobSize- The size of the blob to be written, in bytes. It is implementation dependent whether this value is used in writing the blob to the repository.failIfAlreadyExists- whether to throw a FileAlreadyExistsException if the given blob already exists- Throws:
java.nio.file.FileAlreadyExistsException- if failIfAlreadyExists is true and a blob by the same name already existsjava.io.IOException- if the input stream could not be read, or the target blob could not be written to.
-
writeBlobAtomic
public void writeBlobAtomic(java.lang.String blobName, java.io.InputStream inputStream, long blobSize, boolean failIfAlreadyExists) throws java.io.IOExceptionDescription copied from interface:BlobContainerReads blob content from the input stream and writes it to the container in a new blob with the given name, using an atomic write operation if the implementation supports it. When the BlobContainer implementation does not provide a specific implementation of writeBlobAtomic(String, InputStream, long), then theBlobContainer.writeBlob(String, InputStream, long, boolean)method is used. This method assumes the container does not already contain a blob of the same blobName. If a blob by the same name already exists, the operation will fail and anIOExceptionwill be thrown.- Parameters:
blobName- The name of the blob to write the contents of the input stream to.inputStream- The input stream from which to retrieve the bytes to write to the blob.blobSize- The size of the blob to be written, in bytes. It is implementation dependent whether this value is used in writing the blob to the repository.failIfAlreadyExists- whether to throw a FileAlreadyExistsException if the given blob already exists- Throws:
java.nio.file.FileAlreadyExistsException- if failIfAlreadyExists is true and a blob by the same name already existsjava.io.IOException- if the input stream could not be read, or the target blob could not be written to.
-
moveBlobAtomic
public void moveBlobAtomic(java.lang.String sourceBlobName, java.lang.String targetBlobName, boolean failIfAlreadyExists) throws java.io.IOException- Throws:
java.io.IOException
-
tempBlobName
public static java.lang.String tempBlobName(java.lang.String blobName)
-
isTempBlobName
public static boolean isTempBlobName(java.lang.String blobName)
Returns true if the blob is a leftover temporary blob. The temporary blobs might be left after failed atomic write operation.
-
-