Package org.refcodes.filesystem.alt.s3
Class S3FileSystemImpl
- java.lang.Object
-
- org.refcodes.filesystem.alt.s3.S3FileSystemImpl
-
- All Implemented Interfaces:
org.refcodes.component.Component,org.refcodes.component.Destroyable,org.refcodes.filesystem.FileSystem
public class S3FileSystemImpl extends java.lang.Object implements org.refcodes.filesystem.FileSystemTODO Update the file handle size after writing. Provide a size argument for stream based operations.
-
-
Constructor Summary
Constructors Constructor Description S3FileSystemImpl(java.lang.String aBucketName, java.lang.String aAccessKey, java.lang.String aSecretKey)Instantiates a new s 3 file system impl.S3FileSystemImpl(java.lang.String aBucketName, java.lang.String aAccessKey, java.lang.String aSecretKey, java.lang.String aEndPoint)Instantiates a new s 3 file system impl.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description protected static voidclearBucket(com.amazonaws.services.s3.AmazonS3 aAmazonS3, java.lang.String aBucketId)Clears (removes all content from) an S3 bucket.protected static com.amazonaws.services.s3.AmazonS3createAmazonS3(java.lang.String aAccessKey, java.lang.String aSecretKey)Creates anAmazonS3"client".static voidcreateBucket(com.amazonaws.services.s3.AmazonS3 aAmazonS3, java.lang.String aBucketId)Creates an S3 bucket.org.refcodes.filesystem.FileHandlecreateFile(java.lang.String aKey)org.refcodes.filesystem.FileHandlecreateFile(java.lang.String aPath, java.lang.String aName)static voiddeleteBucket(com.amazonaws.services.s3.AmazonS3 aAmazonS3, java.lang.String aBucketId)Deletes an S3 bucket.voiddeleteFile(org.refcodes.filesystem.FileHandle aFileHandle)protected static voiddeleteS3Objects(com.amazonaws.services.s3.AmazonS3 aAmazonS3, java.lang.String aBucketId, java.util.List<com.amazonaws.services.s3.model.S3ObjectSummary> aS3SummaryObjects)Deletes the content described by the givenS3ObjectSummarylist from an S3 bucket.voiddestroy()java.io.InputStreamfromFile(org.refcodes.filesystem.FileHandle aFromFileHandle)voidfromFile(org.refcodes.filesystem.FileHandle aFileHandle, java.io.File aToFile)voidfromFile(org.refcodes.filesystem.FileHandle aFromFileHandle, java.io.OutputStream aOutputStream)protected java.lang.StringgetAmazonS3BucketName()Retrieves the bucket name to be used.protected com.amazonaws.services.s3.AmazonS3getAmazonS3Client()Retrieves the amazon S3 client to be used.protected static com.amazonaws.services.s3.AmazonS3getAmazonS3Client(java.io.File aConfigFile)Retrieves anAmazonS3Clientfrom a configuration file containing the access- and the secret key.org.refcodes.filesystem.FileHandlegetFileHandle(java.lang.String aKey)org.refcodes.filesystem.FileHandlegetFileHandle(java.lang.String aPath, java.lang.String aName)java.util.List<org.refcodes.filesystem.FileHandle>getFileHandles(java.lang.String aPath, boolean isRecursively)booleanhasFile(java.lang.String aKey)Checks for file.booleanhasFile(java.lang.String aPath, java.lang.String aName)booleanhasFile(org.refcodes.filesystem.FileHandle aFileHandle)booleanhasFiles(java.lang.String aPath, boolean isRecursively)org.refcodes.filesystem.FileHandlemoveFile(org.refcodes.filesystem.FileHandle aFileHandle, java.lang.String aNewKey)org.refcodes.filesystem.FileHandlerenameFile(org.refcodes.filesystem.FileHandle aFileHandle, java.lang.String aNewName)protected voidsetAmazonS3BucketName(java.lang.String aAmazonS3BucketName)Sets the bucket name to be used.java.io.OutputStreamtoFile(org.refcodes.filesystem.FileHandle aToFileHandle)voidtoFile(org.refcodes.filesystem.FileHandle aFileHandle, byte[] aBuffer)voidtoFile(org.refcodes.filesystem.FileHandle aFileHandle, java.io.File aFile)voidtoFile(org.refcodes.filesystem.FileHandle aToFileHandle, java.io.InputStream aInputStream)
-
-
-
Constructor Detail
-
S3FileSystemImpl
public S3FileSystemImpl(java.lang.String aBucketName, java.lang.String aAccessKey, java.lang.String aSecretKey)Instantiates a new s 3 file system impl.- Parameters:
aBucketName- the bucket nameaAccessKey- the access keyaSecretKey- the secret key
-
S3FileSystemImpl
public S3FileSystemImpl(java.lang.String aBucketName, java.lang.String aAccessKey, java.lang.String aSecretKey, java.lang.String aEndPoint)Instantiates a new s 3 file system impl.- Parameters:
aBucketName- the bucket nameaAccessKey- the access keyaSecretKey- the secret keyaEndPoint- the end point
-
-
Method Detail
-
hasFile
public boolean hasFile(java.lang.String aKey) throws org.refcodes.filesystem.IllegalKeyException, org.refcodes.filesystem.NoListAccessException, org.refcodes.filesystem.UnknownFileSystemException, java.io.IOExceptionChecks for file.- Specified by:
hasFilein interfaceorg.refcodes.filesystem.FileSystem- Parameters:
aKey- the key- Returns:
- true, if successful
- Throws:
org.refcodes.filesystem.IllegalKeyException- the illegal key exceptionorg.refcodes.filesystem.NoListAccessException- the no list access exceptionorg.refcodes.filesystem.UnknownFileSystemException- the unknown file system exceptionjava.io.IOException- Signals that an I/O exception has occurred.
-
hasFile
public boolean hasFile(java.lang.String aPath, java.lang.String aName) throws org.refcodes.filesystem.IllegalPathException, org.refcodes.filesystem.IllegalNameException, org.refcodes.filesystem.NoListAccessException, org.refcodes.filesystem.UnknownFileSystemException, java.io.IOException- Specified by:
hasFilein interfaceorg.refcodes.filesystem.FileSystem- Throws:
org.refcodes.filesystem.IllegalPathExceptionorg.refcodes.filesystem.IllegalNameExceptionorg.refcodes.filesystem.NoListAccessExceptionorg.refcodes.filesystem.UnknownFileSystemExceptionjava.io.IOException
-
hasFile
public boolean hasFile(org.refcodes.filesystem.FileHandle aFileHandle) throws org.refcodes.filesystem.NoListAccessException, org.refcodes.filesystem.UnknownFileSystemException, java.io.IOException, org.refcodes.filesystem.IllegalFileHandleException- Specified by:
hasFilein interfaceorg.refcodes.filesystem.FileSystem- Throws:
org.refcodes.filesystem.NoListAccessExceptionorg.refcodes.filesystem.UnknownFileSystemExceptionjava.io.IOExceptionorg.refcodes.filesystem.IllegalFileHandleException
-
createFile
public org.refcodes.filesystem.FileHandle createFile(java.lang.String aKey) throws org.refcodes.filesystem.FileAlreadyExistsException, org.refcodes.filesystem.NoCreateAccessException, org.refcodes.filesystem.IllegalKeyException, org.refcodes.filesystem.UnknownFileSystemException, java.io.IOException, org.refcodes.filesystem.NoListAccessException- Specified by:
createFilein interfaceorg.refcodes.filesystem.FileSystem- Throws:
org.refcodes.filesystem.FileAlreadyExistsExceptionorg.refcodes.filesystem.NoCreateAccessExceptionorg.refcodes.filesystem.IllegalKeyExceptionorg.refcodes.filesystem.UnknownFileSystemExceptionjava.io.IOExceptionorg.refcodes.filesystem.NoListAccessException
-
createFile
public org.refcodes.filesystem.FileHandle createFile(java.lang.String aPath, java.lang.String aName) throws org.refcodes.filesystem.FileAlreadyExistsException, org.refcodes.filesystem.NoCreateAccessException, org.refcodes.filesystem.IllegalNameException, org.refcodes.filesystem.IllegalPathException, org.refcodes.filesystem.UnknownFileSystemException, java.io.IOException, org.refcodes.filesystem.NoListAccessException- Specified by:
createFilein interfaceorg.refcodes.filesystem.FileSystem- Throws:
org.refcodes.filesystem.FileAlreadyExistsExceptionorg.refcodes.filesystem.NoCreateAccessExceptionorg.refcodes.filesystem.IllegalNameExceptionorg.refcodes.filesystem.IllegalPathExceptionorg.refcodes.filesystem.UnknownFileSystemExceptionjava.io.IOExceptionorg.refcodes.filesystem.NoListAccessException
-
getFileHandle
public org.refcodes.filesystem.FileHandle getFileHandle(java.lang.String aKey) throws org.refcodes.filesystem.NoListAccessException, org.refcodes.filesystem.IllegalKeyException, org.refcodes.filesystem.UnknownFileSystemException, java.io.IOException, org.refcodes.filesystem.UnknownKeyException- Specified by:
getFileHandlein interfaceorg.refcodes.filesystem.FileSystem- Throws:
org.refcodes.filesystem.NoListAccessExceptionorg.refcodes.filesystem.IllegalKeyExceptionorg.refcodes.filesystem.UnknownFileSystemExceptionjava.io.IOExceptionorg.refcodes.filesystem.UnknownKeyException
-
getFileHandle
public org.refcodes.filesystem.FileHandle getFileHandle(java.lang.String aPath, java.lang.String aName) throws org.refcodes.filesystem.NoListAccessException, org.refcodes.filesystem.IllegalNameException, org.refcodes.filesystem.IllegalPathException, org.refcodes.filesystem.UnknownFileSystemException, java.io.IOException, org.refcodes.filesystem.UnknownKeyException- Specified by:
getFileHandlein interfaceorg.refcodes.filesystem.FileSystem- Throws:
org.refcodes.filesystem.NoListAccessExceptionorg.refcodes.filesystem.IllegalNameExceptionorg.refcodes.filesystem.IllegalPathExceptionorg.refcodes.filesystem.UnknownFileSystemExceptionjava.io.IOExceptionorg.refcodes.filesystem.UnknownKeyException
-
fromFile
public void fromFile(org.refcodes.filesystem.FileHandle aFromFileHandle, java.io.OutputStream aOutputStream) throws org.refcodes.filesystem.ConcurrentAccessException, org.refcodes.filesystem.UnknownFileException, org.refcodes.filesystem.NoReadAccessException, org.refcodes.filesystem.UnknownFileSystemException, java.io.IOException, org.refcodes.filesystem.NoListAccessException, org.refcodes.filesystem.IllegalFileHandleException- Specified by:
fromFilein interfaceorg.refcodes.filesystem.FileSystem- Throws:
org.refcodes.filesystem.ConcurrentAccessExceptionorg.refcodes.filesystem.UnknownFileExceptionorg.refcodes.filesystem.NoReadAccessExceptionorg.refcodes.filesystem.UnknownFileSystemExceptionjava.io.IOExceptionorg.refcodes.filesystem.NoListAccessExceptionorg.refcodes.filesystem.IllegalFileHandleException
-
toFile
public void toFile(org.refcodes.filesystem.FileHandle aToFileHandle, java.io.InputStream aInputStream) throws org.refcodes.filesystem.ConcurrentAccessException, org.refcodes.filesystem.UnknownFileException, org.refcodes.filesystem.NoWriteAccessException, org.refcodes.filesystem.UnknownFileSystemException, java.io.IOException, org.refcodes.filesystem.NoListAccessException, org.refcodes.filesystem.IllegalFileHandleException- Specified by:
toFilein interfaceorg.refcodes.filesystem.FileSystem- Throws:
org.refcodes.filesystem.ConcurrentAccessExceptionorg.refcodes.filesystem.UnknownFileExceptionorg.refcodes.filesystem.NoWriteAccessExceptionorg.refcodes.filesystem.UnknownFileSystemExceptionjava.io.IOExceptionorg.refcodes.filesystem.NoListAccessExceptionorg.refcodes.filesystem.IllegalFileHandleException
-
fromFile
public java.io.InputStream fromFile(org.refcodes.filesystem.FileHandle aFromFileHandle) throws org.refcodes.filesystem.ConcurrentAccessException, org.refcodes.filesystem.UnknownFileException, org.refcodes.filesystem.UnknownFileException, org.refcodes.filesystem.NoReadAccessException, org.refcodes.filesystem.UnknownFileSystemException, java.io.IOException, org.refcodes.filesystem.NoListAccessException, org.refcodes.filesystem.IllegalFileHandleException- Specified by:
fromFilein interfaceorg.refcodes.filesystem.FileSystem- Throws:
org.refcodes.filesystem.ConcurrentAccessExceptionorg.refcodes.filesystem.UnknownFileExceptionorg.refcodes.filesystem.NoReadAccessExceptionorg.refcodes.filesystem.UnknownFileSystemExceptionjava.io.IOExceptionorg.refcodes.filesystem.NoListAccessExceptionorg.refcodes.filesystem.IllegalFileHandleException
-
toFile
public java.io.OutputStream toFile(org.refcodes.filesystem.FileHandle aToFileHandle) throws org.refcodes.filesystem.ConcurrentAccessException, org.refcodes.filesystem.UnknownFileException, org.refcodes.filesystem.NoWriteAccessException, org.refcodes.filesystem.UnknownFileSystemException, java.io.IOException, org.refcodes.filesystem.IllegalFileHandleException- Specified by:
toFilein interfaceorg.refcodes.filesystem.FileSystem- Throws:
org.refcodes.filesystem.ConcurrentAccessExceptionorg.refcodes.filesystem.UnknownFileExceptionorg.refcodes.filesystem.NoWriteAccessExceptionorg.refcodes.filesystem.UnknownFileSystemExceptionjava.io.IOExceptionorg.refcodes.filesystem.IllegalFileHandleException
-
fromFile
public void fromFile(org.refcodes.filesystem.FileHandle aFileHandle, java.io.File aToFile) throws org.refcodes.filesystem.ConcurrentAccessException, org.refcodes.filesystem.UnknownFileException, org.refcodes.filesystem.NoReadAccessException, org.refcodes.filesystem.UnknownFileSystemException, java.io.IOException, org.refcodes.filesystem.NoListAccessException, org.refcodes.filesystem.IllegalFileHandleException- Specified by:
fromFilein interfaceorg.refcodes.filesystem.FileSystem- Throws:
org.refcodes.filesystem.ConcurrentAccessExceptionorg.refcodes.filesystem.UnknownFileExceptionorg.refcodes.filesystem.NoReadAccessExceptionorg.refcodes.filesystem.UnknownFileSystemExceptionjava.io.IOExceptionorg.refcodes.filesystem.NoListAccessExceptionorg.refcodes.filesystem.IllegalFileHandleException
-
toFile
public void toFile(org.refcodes.filesystem.FileHandle aFileHandle, java.io.File aFile) throws org.refcodes.filesystem.ConcurrentAccessException, org.refcodes.filesystem.UnknownFileException, org.refcodes.filesystem.NoWriteAccessException, org.refcodes.filesystem.UnknownFileSystemException, java.io.IOException, org.refcodes.filesystem.NoListAccessException, org.refcodes.filesystem.IllegalFileHandleException- Specified by:
toFilein interfaceorg.refcodes.filesystem.FileSystem- Throws:
org.refcodes.filesystem.ConcurrentAccessExceptionorg.refcodes.filesystem.UnknownFileExceptionorg.refcodes.filesystem.NoWriteAccessExceptionorg.refcodes.filesystem.UnknownFileSystemExceptionjava.io.IOExceptionorg.refcodes.filesystem.NoListAccessExceptionorg.refcodes.filesystem.IllegalFileHandleException
-
toFile
public void toFile(org.refcodes.filesystem.FileHandle aFileHandle, byte[] aBuffer) throws org.refcodes.filesystem.ConcurrentAccessException, org.refcodes.filesystem.UnknownFileException, org.refcodes.filesystem.NoWriteAccessException, org.refcodes.filesystem.UnknownFileSystemException, java.io.IOException, org.refcodes.filesystem.NoListAccessException, org.refcodes.filesystem.IllegalFileHandleException- Specified by:
toFilein interfaceorg.refcodes.filesystem.FileSystem- Throws:
org.refcodes.filesystem.ConcurrentAccessExceptionorg.refcodes.filesystem.UnknownFileExceptionorg.refcodes.filesystem.NoWriteAccessExceptionorg.refcodes.filesystem.UnknownFileSystemExceptionjava.io.IOExceptionorg.refcodes.filesystem.NoListAccessExceptionorg.refcodes.filesystem.IllegalFileHandleException
-
renameFile
public org.refcodes.filesystem.FileHandle renameFile(org.refcodes.filesystem.FileHandle aFileHandle, java.lang.String aNewName) throws org.refcodes.filesystem.UnknownFileException, org.refcodes.filesystem.ConcurrentAccessException, org.refcodes.filesystem.FileAlreadyExistsException, org.refcodes.filesystem.NoCreateAccessException, org.refcodes.filesystem.NoDeleteAccessException, org.refcodes.filesystem.IllegalNameException, org.refcodes.filesystem.UnknownFileSystemException, java.io.IOException, org.refcodes.filesystem.NoListAccessException, org.refcodes.filesystem.IllegalFileHandleException- Specified by:
renameFilein interfaceorg.refcodes.filesystem.FileSystem- Throws:
org.refcodes.filesystem.UnknownFileExceptionorg.refcodes.filesystem.ConcurrentAccessExceptionorg.refcodes.filesystem.FileAlreadyExistsExceptionorg.refcodes.filesystem.NoCreateAccessExceptionorg.refcodes.filesystem.NoDeleteAccessExceptionorg.refcodes.filesystem.IllegalNameExceptionorg.refcodes.filesystem.UnknownFileSystemExceptionjava.io.IOExceptionorg.refcodes.filesystem.NoListAccessExceptionorg.refcodes.filesystem.IllegalFileHandleException
-
moveFile
public org.refcodes.filesystem.FileHandle moveFile(org.refcodes.filesystem.FileHandle aFileHandle, java.lang.String aNewKey) throws org.refcodes.filesystem.UnknownFileException, org.refcodes.filesystem.ConcurrentAccessException, org.refcodes.filesystem.FileAlreadyExistsException, org.refcodes.filesystem.NoCreateAccessException, org.refcodes.filesystem.NoDeleteAccessException, org.refcodes.filesystem.IllegalKeyException, org.refcodes.filesystem.UnknownFileSystemException, java.io.IOException, org.refcodes.filesystem.NoListAccessException, org.refcodes.filesystem.IllegalFileHandleException- Specified by:
moveFilein interfaceorg.refcodes.filesystem.FileSystem- Throws:
org.refcodes.filesystem.UnknownFileExceptionorg.refcodes.filesystem.ConcurrentAccessExceptionorg.refcodes.filesystem.FileAlreadyExistsExceptionorg.refcodes.filesystem.NoCreateAccessExceptionorg.refcodes.filesystem.NoDeleteAccessExceptionorg.refcodes.filesystem.IllegalKeyExceptionorg.refcodes.filesystem.UnknownFileSystemExceptionjava.io.IOExceptionorg.refcodes.filesystem.NoListAccessExceptionorg.refcodes.filesystem.IllegalFileHandleException
-
deleteFile
public void deleteFile(org.refcodes.filesystem.FileHandle aFileHandle) throws org.refcodes.filesystem.ConcurrentAccessException, org.refcodes.filesystem.UnknownFileException, org.refcodes.filesystem.NoDeleteAccessException, org.refcodes.filesystem.UnknownFileSystemException, java.io.IOException, org.refcodes.filesystem.NoListAccessException, org.refcodes.filesystem.IllegalFileHandleException- Specified by:
deleteFilein interfaceorg.refcodes.filesystem.FileSystem- Throws:
org.refcodes.filesystem.ConcurrentAccessExceptionorg.refcodes.filesystem.UnknownFileExceptionorg.refcodes.filesystem.NoDeleteAccessExceptionorg.refcodes.filesystem.UnknownFileSystemExceptionjava.io.IOExceptionorg.refcodes.filesystem.NoListAccessExceptionorg.refcodes.filesystem.IllegalFileHandleException
-
hasFiles
public boolean hasFiles(java.lang.String aPath, boolean isRecursively) throws org.refcodes.filesystem.NoListAccessException, org.refcodes.filesystem.IllegalPathException, org.refcodes.filesystem.UnknownFileSystemException, java.io.IOException- Specified by:
hasFilesin interfaceorg.refcodes.filesystem.FileSystem- Throws:
org.refcodes.filesystem.NoListAccessExceptionorg.refcodes.filesystem.IllegalPathExceptionorg.refcodes.filesystem.UnknownFileSystemExceptionjava.io.IOException
-
getFileHandles
public java.util.List<org.refcodes.filesystem.FileHandle> getFileHandles(java.lang.String aPath, boolean isRecursively) throws org.refcodes.filesystem.NoListAccessException, org.refcodes.filesystem.UnknownPathException, org.refcodes.filesystem.IllegalPathException, org.refcodes.filesystem.UnknownFileSystemException, java.io.IOException- Specified by:
getFileHandlesin interfaceorg.refcodes.filesystem.FileSystem- Throws:
org.refcodes.filesystem.NoListAccessExceptionorg.refcodes.filesystem.UnknownPathExceptionorg.refcodes.filesystem.IllegalPathExceptionorg.refcodes.filesystem.UnknownFileSystemExceptionjava.io.IOException
-
destroy
public void destroy()
- Specified by:
destroyin interfaceorg.refcodes.component.Destroyable
-
getAmazonS3BucketName
protected java.lang.String getAmazonS3BucketName()
Retrieves the bucket name to be used.- Returns:
- The bucket name.
-
setAmazonS3BucketName
protected void setAmazonS3BucketName(java.lang.String aAmazonS3BucketName)
Sets the bucket name to be used.- Parameters:
aAmazonS3BucketName- The bucket name to be used.
-
getAmazonS3Client
protected com.amazonaws.services.s3.AmazonS3 getAmazonS3Client()
Retrieves the amazon S3 client to be used.- Returns:
- The S3 client to be used.
-
createBucket
public static void createBucket(com.amazonaws.services.s3.AmazonS3 aAmazonS3, java.lang.String aBucketId)Creates an S3 bucket.- Parameters:
aAmazonS3- TheAmazonS3client.aBucketId- The ID of the bucket to be created.
-
clearBucket
protected static void clearBucket(com.amazonaws.services.s3.AmazonS3 aAmazonS3, java.lang.String aBucketId)Clears (removes all content from) an S3 bucket.- Parameters:
aAmazonS3- TheAmazonS3client.aBucketId- The ID of the bucket to be cleared.
-
deleteBucket
public static void deleteBucket(com.amazonaws.services.s3.AmazonS3 aAmazonS3, java.lang.String aBucketId)Deletes an S3 bucket.- Parameters:
aAmazonS3- TheAmazonS3client.aBucketId- The ID of the bucket to be deleted.
-
createAmazonS3
protected static com.amazonaws.services.s3.AmazonS3 createAmazonS3(java.lang.String aAccessKey, java.lang.String aSecretKey)Creates anAmazonS3"client".- Parameters:
aAccessKey- The according access key for accessing amazon AWS.aSecretKey- The secret access key for accessing amazon AWS.- Returns:
- The client represented by an
AmazonS3instance.
-
deleteS3Objects
protected static void deleteS3Objects(com.amazonaws.services.s3.AmazonS3 aAmazonS3, java.lang.String aBucketId, java.util.List<com.amazonaws.services.s3.model.S3ObjectSummary> aS3SummaryObjects)Deletes the content described by the givenS3ObjectSummarylist from an S3 bucket.- Parameters:
aAmazonS3- TheAmazonS3client.aBucketId- The ID of the bucket from which the objects are to be deleted.aS3SummaryObjects- TheS3ObjectSummarylist describing the objects to be deleted.
-
getAmazonS3Client
protected static com.amazonaws.services.s3.AmazonS3 getAmazonS3Client(java.io.File aConfigFile) throws java.io.IOExceptionRetrieves anAmazonS3Clientfrom a configuration file containing the access- and the secret key.- Parameters:
aConfigFile- The configuration file used to configure theAmazonS3Client.- Returns:
- An
AmazonS3Client. - Throws:
java.io.IOException- In case there were problems reading the configuration file.
-
-