java.lang.Object
org.refcodes.filesystem.alt.s3.S3FileSystem
All Implemented Interfaces:
org.refcodes.component.Component, org.refcodes.component.Destroyable, org.refcodes.filesystem.FileSystem

public class S3FileSystem extends Object implements org.refcodes.filesystem.FileSystem
A FileSystem implementation for S3.
  • Nested Class Summary

    Nested classes/interfaces inherited from interface org.refcodes.component.Destroyable

    org.refcodes.component.Destroyable.DestroyAutomaton
  • Field Summary

    Fields inherited from interface org.refcodes.filesystem.FileSystem

    PATH_DELIMITER
  • Constructor Summary

    Constructors
    Constructor
    Description
    S3FileSystem(String aBucketName, String aAccessKey, String aSecretKey)
    Instantiates a new s 3 file system impl.
    S3FileSystem(String aBucketName, String aAccessKey, String aSecretKey, String aEndPoint)
    Instantiates a new s 3 file system impl.
  • Method Summary

    Modifier and Type
    Method
    Description
    protected static void
    clearBucket(software.amazon.awssdk.services.s3.S3Client aAmazonS3, String aBucketId)
    Clears (removes all content from) an S3 bucket.
    protected static software.amazon.awssdk.services.s3.S3Client
    createAmazonS3(String aAccessKey, String aSecretKey)
    Creates an S3Client "client".
    static void
    createBucket(software.amazon.awssdk.services.s3.S3Client aAmazonS3, String aBucketId)
    Creates an S3 bucket.
    org.refcodes.filesystem.FileHandle
    org.refcodes.filesystem.FileHandle
    createFile(String aPath, String aName)
    static void
    deleteBucket(software.amazon.awssdk.services.s3.S3Client aAmazonS3, String aBucketId)
    Deletes an S3 bucket.
    void
    deleteFile(org.refcodes.filesystem.FileHandle aFileHandle)
    protected static void
    deleteS3Objects(software.amazon.awssdk.services.s3.S3Client aAmazonS3, String aBucketId, List<software.amazon.awssdk.services.s3.model.S3Object> aS3SummaryObjects)
    Deletes the content described by the given S3Object list from an S3 bucket.
    void
    fromFile(org.refcodes.filesystem.FileHandle aFromFileHandle)
    void
    fromFile(org.refcodes.filesystem.FileHandle aFileHandle, File aToFile)
    void
    fromFile(org.refcodes.filesystem.FileHandle aFromFileHandle, OutputStream aOutputStream)
    protected String
    Retrieves the bucket name to be used.
    protected software.amazon.awssdk.services.s3.S3Client
    Retrieves the amazon S3 client to be used.
    protected static software.amazon.awssdk.services.s3.S3Client
    getAmazonS3Client(File aConfigFile)
    Retrieves an S3Client from a configuration file containing the access- and the secret key.
    org.refcodes.filesystem.FileHandle
    org.refcodes.filesystem.FileHandle
    getFileHandle(String aPath, String aName)
    List<org.refcodes.filesystem.FileHandle>
    getFileHandles(String aPath, boolean isRecursively)
    boolean
    Checks for file.
    boolean
    hasFile(String aPath, String aName)
    boolean
    hasFile(org.refcodes.filesystem.FileHandle aFileHandle)
    boolean
    hasFiles(String aPath, boolean isRecursively)
    org.refcodes.filesystem.FileHandle
    moveFile(org.refcodes.filesystem.FileHandle aFileHandle, String aNewKey)
    org.refcodes.filesystem.FileHandle
    renameFile(org.refcodes.filesystem.FileHandle aFileHandle, String aNewName)
    protected void
    setAmazonS3BucketName(String aAmazonS3BucketName)
    Sets the bucket name to be used.
    toFile(org.refcodes.filesystem.FileHandle aToFileHandle)
    void
    toFile(org.refcodes.filesystem.FileHandle aFileHandle, byte[] aBuffer)
    void
    toFile(org.refcodes.filesystem.FileHandle aFileHandle, File aFile)
    void
    toFile(org.refcodes.filesystem.FileHandle aToFileHandle, InputStream aInputStream)

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • S3FileSystem

      public S3FileSystem(String aBucketName, String aAccessKey, String aSecretKey)
      Instantiates a new s 3 file system impl.
      Parameters:
      aBucketName - the bucket name
      aAccessKey - the access key
      aSecretKey - the secret key
    • S3FileSystem

      public S3FileSystem(String aBucketName, String aAccessKey, String aSecretKey, String aEndPoint)
      Instantiates a new s 3 file system impl.
      Parameters:
      aBucketName - the bucket name
      aAccessKey - the access key
      aSecretKey - the secret key
      aEndPoint - the end point
  • Method Details

    • hasFile

      public boolean hasFile(String aKey) throws org.refcodes.filesystem.IllegalKeyException, org.refcodes.filesystem.NoListAccessException, org.refcodes.filesystem.UnknownFileSystemException, IOException
      Checks for file.
      Specified by:
      hasFile in interface org.refcodes.filesystem.FileSystem
      Parameters:
      aKey - the key
      Returns:
      true, if successful
      Throws:
      org.refcodes.filesystem.IllegalKeyException - the illegal key exception
      org.refcodes.filesystem.NoListAccessException - the no list access exception
      org.refcodes.filesystem.UnknownFileSystemException - the unknown file system exception
      IOException - Signals that an I/O exception has occurred.
    • hasFile

      public boolean hasFile(String aPath, String aName) throws org.refcodes.filesystem.IllegalPathException, org.refcodes.filesystem.IllegalNameException, org.refcodes.filesystem.NoListAccessException, org.refcodes.filesystem.UnknownFileSystemException, IOException
      Specified by:
      hasFile in interface org.refcodes.filesystem.FileSystem
      Throws:
      org.refcodes.filesystem.IllegalPathException
      org.refcodes.filesystem.IllegalNameException
      org.refcodes.filesystem.NoListAccessException
      org.refcodes.filesystem.UnknownFileSystemException
      IOException
    • hasFile

      public boolean hasFile(org.refcodes.filesystem.FileHandle aFileHandle) throws org.refcodes.filesystem.NoListAccessException, org.refcodes.filesystem.UnknownFileSystemException, IOException, org.refcodes.filesystem.IllegalFileHandleException
      Specified by:
      hasFile in interface org.refcodes.filesystem.FileSystem
      Throws:
      org.refcodes.filesystem.NoListAccessException
      org.refcodes.filesystem.UnknownFileSystemException
      IOException
      org.refcodes.filesystem.IllegalFileHandleException
    • createFile

      public org.refcodes.filesystem.FileHandle createFile(String aKey) throws org.refcodes.filesystem.FileAlreadyExistsException, org.refcodes.filesystem.NoCreateAccessException, org.refcodes.filesystem.IllegalKeyException, org.refcodes.filesystem.UnknownFileSystemException, IOException, org.refcodes.filesystem.NoListAccessException
      Specified by:
      createFile in interface org.refcodes.filesystem.FileSystem
      Throws:
      org.refcodes.filesystem.FileAlreadyExistsException
      org.refcodes.filesystem.NoCreateAccessException
      org.refcodes.filesystem.IllegalKeyException
      org.refcodes.filesystem.UnknownFileSystemException
      IOException
      org.refcodes.filesystem.NoListAccessException
    • createFile

      public org.refcodes.filesystem.FileHandle createFile(String aPath, String aName) throws org.refcodes.filesystem.FileAlreadyExistsException, org.refcodes.filesystem.NoCreateAccessException, org.refcodes.filesystem.IllegalNameException, org.refcodes.filesystem.IllegalPathException, org.refcodes.filesystem.UnknownFileSystemException, IOException, org.refcodes.filesystem.NoListAccessException
      Specified by:
      createFile in interface org.refcodes.filesystem.FileSystem
      Throws:
      org.refcodes.filesystem.FileAlreadyExistsException
      org.refcodes.filesystem.NoCreateAccessException
      org.refcodes.filesystem.IllegalNameException
      org.refcodes.filesystem.IllegalPathException
      org.refcodes.filesystem.UnknownFileSystemException
      IOException
      org.refcodes.filesystem.NoListAccessException
    • getFileHandle

      public org.refcodes.filesystem.FileHandle getFileHandle(String aKey) throws org.refcodes.filesystem.NoListAccessException, org.refcodes.filesystem.IllegalKeyException, org.refcodes.filesystem.UnknownFileSystemException, IOException, org.refcodes.filesystem.UnknownKeyException
      Specified by:
      getFileHandle in interface org.refcodes.filesystem.FileSystem
      Throws:
      org.refcodes.filesystem.NoListAccessException
      org.refcodes.filesystem.IllegalKeyException
      org.refcodes.filesystem.UnknownFileSystemException
      IOException
      org.refcodes.filesystem.UnknownKeyException
    • getFileHandle

      public org.refcodes.filesystem.FileHandle getFileHandle(String aPath, String aName) throws org.refcodes.filesystem.NoListAccessException, org.refcodes.filesystem.IllegalNameException, org.refcodes.filesystem.IllegalPathException, org.refcodes.filesystem.UnknownFileSystemException, IOException, org.refcodes.filesystem.UnknownKeyException
      Specified by:
      getFileHandle in interface org.refcodes.filesystem.FileSystem
      Throws:
      org.refcodes.filesystem.NoListAccessException
      org.refcodes.filesystem.IllegalNameException
      org.refcodes.filesystem.IllegalPathException
      org.refcodes.filesystem.UnknownFileSystemException
      IOException
      org.refcodes.filesystem.UnknownKeyException
    • fromFile

      public void fromFile(org.refcodes.filesystem.FileHandle aFromFileHandle, OutputStream aOutputStream) throws org.refcodes.filesystem.ConcurrentAccessException, org.refcodes.filesystem.UnknownFileException, org.refcodes.filesystem.NoReadAccessException, org.refcodes.filesystem.UnknownFileSystemException, IOException, org.refcodes.filesystem.NoListAccessException, org.refcodes.filesystem.IllegalFileHandleException
      Specified by:
      fromFile in interface org.refcodes.filesystem.FileSystem
      Throws:
      org.refcodes.filesystem.ConcurrentAccessException
      org.refcodes.filesystem.UnknownFileException
      org.refcodes.filesystem.NoReadAccessException
      org.refcodes.filesystem.UnknownFileSystemException
      IOException
      org.refcodes.filesystem.NoListAccessException
      org.refcodes.filesystem.IllegalFileHandleException
    • toFile

      public void toFile(org.refcodes.filesystem.FileHandle aToFileHandle, InputStream aInputStream) throws org.refcodes.filesystem.ConcurrentAccessException, org.refcodes.filesystem.UnknownFileException, org.refcodes.filesystem.NoWriteAccessException, org.refcodes.filesystem.UnknownFileSystemException, IOException, org.refcodes.filesystem.NoListAccessException, org.refcodes.filesystem.IllegalFileHandleException
      Specified by:
      toFile in interface org.refcodes.filesystem.FileSystem
      Throws:
      org.refcodes.filesystem.ConcurrentAccessException
      org.refcodes.filesystem.UnknownFileException
      org.refcodes.filesystem.NoWriteAccessException
      org.refcodes.filesystem.UnknownFileSystemException
      IOException
      org.refcodes.filesystem.NoListAccessException
      org.refcodes.filesystem.IllegalFileHandleException
    • fromFile

      public 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, IOException, org.refcodes.filesystem.NoListAccessException, org.refcodes.filesystem.IllegalFileHandleException
      Specified by:
      fromFile in interface org.refcodes.filesystem.FileSystem
      Throws:
      org.refcodes.filesystem.ConcurrentAccessException
      org.refcodes.filesystem.UnknownFileException
      org.refcodes.filesystem.UnknownFileException
      org.refcodes.filesystem.NoReadAccessException
      org.refcodes.filesystem.UnknownFileSystemException
      IOException
      org.refcodes.filesystem.NoListAccessException
      org.refcodes.filesystem.IllegalFileHandleException
    • toFile

      public OutputStream toFile(org.refcodes.filesystem.FileHandle aToFileHandle) throws org.refcodes.filesystem.ConcurrentAccessException, org.refcodes.filesystem.UnknownFileException, org.refcodes.filesystem.NoWriteAccessException, org.refcodes.filesystem.UnknownFileSystemException, IOException, org.refcodes.filesystem.IllegalFileHandleException
      Specified by:
      toFile in interface org.refcodes.filesystem.FileSystem
      Throws:
      org.refcodes.filesystem.ConcurrentAccessException
      org.refcodes.filesystem.UnknownFileException
      org.refcodes.filesystem.NoWriteAccessException
      org.refcodes.filesystem.UnknownFileSystemException
      IOException
      org.refcodes.filesystem.IllegalFileHandleException
    • fromFile

      public void fromFile(org.refcodes.filesystem.FileHandle aFileHandle, File aToFile) throws org.refcodes.filesystem.ConcurrentAccessException, org.refcodes.filesystem.UnknownFileException, org.refcodes.filesystem.NoReadAccessException, org.refcodes.filesystem.UnknownFileSystemException, IOException, org.refcodes.filesystem.NoListAccessException, org.refcodes.filesystem.IllegalFileHandleException
      Specified by:
      fromFile in interface org.refcodes.filesystem.FileSystem
      Throws:
      org.refcodes.filesystem.ConcurrentAccessException
      org.refcodes.filesystem.UnknownFileException
      org.refcodes.filesystem.NoReadAccessException
      org.refcodes.filesystem.UnknownFileSystemException
      IOException
      org.refcodes.filesystem.NoListAccessException
      org.refcodes.filesystem.IllegalFileHandleException
    • toFile

      public void toFile(org.refcodes.filesystem.FileHandle aFileHandle, File aFile) throws org.refcodes.filesystem.ConcurrentAccessException, org.refcodes.filesystem.UnknownFileException, org.refcodes.filesystem.NoWriteAccessException, org.refcodes.filesystem.UnknownFileSystemException, IOException, org.refcodes.filesystem.NoListAccessException, org.refcodes.filesystem.IllegalFileHandleException
      Specified by:
      toFile in interface org.refcodes.filesystem.FileSystem
      Throws:
      org.refcodes.filesystem.ConcurrentAccessException
      org.refcodes.filesystem.UnknownFileException
      org.refcodes.filesystem.NoWriteAccessException
      org.refcodes.filesystem.UnknownFileSystemException
      IOException
      org.refcodes.filesystem.NoListAccessException
      org.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, IOException, org.refcodes.filesystem.NoListAccessException, org.refcodes.filesystem.IllegalFileHandleException
      Specified by:
      toFile in interface org.refcodes.filesystem.FileSystem
      Throws:
      org.refcodes.filesystem.ConcurrentAccessException
      org.refcodes.filesystem.UnknownFileException
      org.refcodes.filesystem.NoWriteAccessException
      org.refcodes.filesystem.UnknownFileSystemException
      IOException
      org.refcodes.filesystem.NoListAccessException
      org.refcodes.filesystem.IllegalFileHandleException
    • renameFile

      public org.refcodes.filesystem.FileHandle renameFile(org.refcodes.filesystem.FileHandle aFileHandle, 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, IOException, org.refcodes.filesystem.NoListAccessException, org.refcodes.filesystem.IllegalFileHandleException
      Specified by:
      renameFile in interface org.refcodes.filesystem.FileSystem
      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
      IOException
      org.refcodes.filesystem.NoListAccessException
      org.refcodes.filesystem.IllegalFileHandleException
    • moveFile

      public org.refcodes.filesystem.FileHandle moveFile(org.refcodes.filesystem.FileHandle aFileHandle, 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, IOException, org.refcodes.filesystem.NoListAccessException, org.refcodes.filesystem.IllegalFileHandleException
      Specified by:
      moveFile in interface org.refcodes.filesystem.FileSystem
      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
      IOException
      org.refcodes.filesystem.NoListAccessException
      org.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, IOException, org.refcodes.filesystem.NoListAccessException, org.refcodes.filesystem.IllegalFileHandleException
      Specified by:
      deleteFile in interface org.refcodes.filesystem.FileSystem
      Throws:
      org.refcodes.filesystem.ConcurrentAccessException
      org.refcodes.filesystem.UnknownFileException
      org.refcodes.filesystem.NoDeleteAccessException
      org.refcodes.filesystem.UnknownFileSystemException
      IOException
      org.refcodes.filesystem.NoListAccessException
      org.refcodes.filesystem.IllegalFileHandleException
    • hasFiles

      public boolean hasFiles(String aPath, boolean isRecursively) throws org.refcodes.filesystem.NoListAccessException, org.refcodes.filesystem.IllegalPathException, org.refcodes.filesystem.UnknownFileSystemException, IOException
      Specified by:
      hasFiles in interface org.refcodes.filesystem.FileSystem
      Throws:
      org.refcodes.filesystem.NoListAccessException
      org.refcodes.filesystem.IllegalPathException
      org.refcodes.filesystem.UnknownFileSystemException
      IOException
    • getFileHandles

      public List<org.refcodes.filesystem.FileHandle> getFileHandles(String aPath, boolean isRecursively) throws org.refcodes.filesystem.NoListAccessException, org.refcodes.filesystem.UnknownPathException, org.refcodes.filesystem.IllegalPathException, org.refcodes.filesystem.UnknownFileSystemException, IOException
      Specified by:
      getFileHandles in interface org.refcodes.filesystem.FileSystem
      Throws:
      org.refcodes.filesystem.NoListAccessException
      org.refcodes.filesystem.UnknownPathException
      org.refcodes.filesystem.IllegalPathException
      org.refcodes.filesystem.UnknownFileSystemException
      IOException
    • destroy

      public void destroy()
      Specified by:
      destroy in interface org.refcodes.component.Destroyable
    • getAmazonS3BucketName

      protected String getAmazonS3BucketName()
      Retrieves the bucket name to be used.
      Returns:
      The bucket name.
    • setAmazonS3BucketName

      protected void setAmazonS3BucketName(String aAmazonS3BucketName)
      Sets the bucket name to be used.
      Parameters:
      aAmazonS3BucketName - The bucket name to be used.
    • getAmazonS3Client

      protected software.amazon.awssdk.services.s3.S3Client getAmazonS3Client()
      Retrieves the amazon S3 client to be used.
      Returns:
      The S3 client to be used.
    • createBucket

      public static void createBucket(software.amazon.awssdk.services.s3.S3Client aAmazonS3, String aBucketId)
      Creates an S3 bucket.
      Parameters:
      aAmazonS3 - The S3Client client.
      aBucketId - The TID of the bucket to be created.
    • clearBucket

      protected static void clearBucket(software.amazon.awssdk.services.s3.S3Client aAmazonS3, String aBucketId)
      Clears (removes all content from) an S3 bucket.
      Parameters:
      aAmazonS3 - The S3Client client.
      aBucketId - The TID of the bucket to be cleared.
    • deleteBucket

      public static void deleteBucket(software.amazon.awssdk.services.s3.S3Client aAmazonS3, String aBucketId)
      Deletes an S3 bucket.
      Parameters:
      aAmazonS3 - The S3Client client.
      aBucketId - The TID of the bucket to be deleted.
    • createAmazonS3

      protected static software.amazon.awssdk.services.s3.S3Client createAmazonS3(String aAccessKey, String aSecretKey)
      Creates an S3Client "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 S3Client instance.
    • deleteS3Objects

      protected static void deleteS3Objects(software.amazon.awssdk.services.s3.S3Client aAmazonS3, String aBucketId, List<software.amazon.awssdk.services.s3.model.S3Object> aS3SummaryObjects)
      Deletes the content described by the given S3Object list from an S3 bucket.
      Parameters:
      aAmazonS3 - The S3Client client.
      aBucketId - The TID of the bucket from which the objects are to be deleted.
      aS3SummaryObjects - The S3Object list describing the objects to be deleted.
    • getAmazonS3Client

      protected static software.amazon.awssdk.services.s3.S3Client getAmazonS3Client(File aConfigFile) throws IOException
      Retrieves an S3Client from a configuration file containing the access- and the secret key.
      Parameters:
      aConfigFile - The configuration file used to configure the S3Client.
      Returns:
      An S3Client.
      Throws:
      IOException - In case there were problems reading the configuration file.