Package org.apache.sis.cloud.aws.s3
Class FileService
Object
FileSystemProvider
FileService
A provider of file system services as wrappers around Amazon Simple Storage Service (AWS S3).
 This provider accepts URIs of the following forms:
 
- S3://bucket/key
- S3://accessKey@bucket/key(password not allowed)
'/' separator.
 The password and the region can be specified at file system initialization time.
 The endpoint (e.g. "s3.eu-central-1.amazonaws.com") shall not be specified in the URI.
 In particular the region ("eu-central-1" in above example) can depend on the server location
 instead of the data to access, and can be a global configuration for the server.- Since:
- 1.2
Defined in the sis-cloud-aws module
- 
Field SummaryFields
- 
Constructor SummaryConstructors
- 
Method SummaryModifier and TypeMethodDescriptionvoidcheckAccess(Path path, AccessMode... modes) Checks the existence, and optionally the accessibility, of a file.voidcopy(Path source, Path target, CopyOption... options) Copies a file.voidcreateDirectory(Path directory, FileAttribute<?>... attributes) Creates a new pseudo-directory.voidDeletes a file.<V extends FileAttributeView>
 VgetFileAttributeView(Path path, Class<V> type, LinkOption... options) Returns a read-only or updatable view of a set of file attributes.getFileStore(Path path) Returns the store where a file is located.getFileSystem(URI uri) Returns a reference to a file system that was created by thenewFileSystem(URI, Map)method.Return aPathobject by converting the givenURI.Returns the URI scheme that identifies this provider, which is"S3".booleanTells whether a file is considered hidden.booleanisSameFile(Path path1, Path path2) Tests if two paths locate the same file.voidmove(Path source, Path target, CopyOption... options) Copies a file.newByteChannel(Path path, Set<? extends OpenOption> options, FileAttribute<?>... attributes) Returns a seekable byte channel to access a file.newDirectoryStream(Path directory, DirectoryStream.Filter<? super Path> filter) Opens a directory and returns aDirectoryStreamto iterate over its entries.newFileSystem(URI uri, Map<String, ?> properties) Initializes and returns a new file system identified by a URI.ResponseInputStream<GetObjectResponse>newInputStream(Path path, OpenOption... options) Opens an input stream to read from the path.<A extends BasicFileAttributes>
 AreadAttributes(Path path, Class<A> type, LinkOption... options) Reads a file's attributes as a bulk operation.readAttributes(Path path, String attributes, LinkOption... options) Reads a set of file attributes as a bulk operation.voidsetAttribute(Path path, String attribute, Object value, LinkOption... options) Methods inherited from class FileSystemProvidercreateLink, createSymbolicLink, deleteIfExists, installedProviders, newAsynchronousFileChannel, newFileChannel, newFileSystem, newOutputStream, readSymbolicLink
- 
Field Details- 
AWS_SECRET_ACCESS_KEYThe property for the secret access key (password). Values shall be instances ofString. If not specified, the AWS SDK default mechanism searches for the first of the following:- AWS_SECRET_ACCESS_KEYenvironment variable.
- ~/.aws/credentialsand- ~/.aws/configfiles.
 
- 
AWS_REGIONThe property for the secret access key (password). Values shall be instances ofRegion. If not specified, the AWS SDK default mechanism searches for the first of the following:- AWS_REGIONenvironment variable.
- ~/.aws/credentialsand- ~/.aws/configfiles.
 
- 
SEPARATORThe property for the name-separator characters. The default value is "/" for simulating Unix paths. The separator must contain at least one character. They usually have only one character, but longer separators are accepted. The separator can contain any characters which are valid in a S3 object name.- See Also:
 
 
- 
- 
Constructor Details- 
FileServicepublic FileService()Creates a new provider of file systems for Amazon S3.
 
- 
- 
Method Details- 
getSchemeReturns the URI scheme that identifies this provider, which is"S3".- Specified by:
- getSchemein class- FileSystemProvider
- Returns:
- the "S3"URI scheme.
 
- 
newFileSystemInitializes and returns a new file system identified by a URI. The given URI shall have the following pattern:
 In current version all path components afterS3://accessKey@bucket/key accessKeyare ignored. A future version may allow finer grain control.AuthenticationThe access key is a kind of login (not a password). The password (also called "secret access key") shall not be specified in the URI; syntax likeaccessKey:passwordwill not be parsed by this package. Instead the password can be specified in the given map as aStringvalue associated to the "aws.secretAccessKey" key.Recognized propertiesThe following properties are accepted:- "aws.secretAccessKey" with Stringvalue.
- "aws.region" with Regionvalue.
 - Specified by:
- newFileSystemin class- FileSystemProvider
- Parameters:
- uri- a URI of the form- "s3://accessKey@bucket/key".
- properties- properties to configure the file system, or- nullif none.
- Returns:
- the new file system.
- Throws:
- IllegalArgumentException- if the URI or the map contains invalid values.
- IOException- if an I/O error occurs while creating the file system.
- FileSystemAlreadyExistsException- if a file system has already been created for the given URI and has not yet been closed.
 
- "aws.secretAccessKey" with 
- 
getFileSystemReturns a reference to a file system that was created by thenewFileSystem(URI, Map)method. If the file system has not been created or has been closed, then this method throwsFileSystemNotFoundException.- Specified by:
- getFileSystemin class- FileSystemProvider
- Parameters:
- uri- a URI of the form- "s3://accessKey@bucket/key".
- Returns:
- the file system previously created by newFileSystem(URI, Map).
- Throws:
- IllegalArgumentException- if the URI is not supported by this provider.
- FileSystemNotFoundException- if the file system does not exist or has been closed.
 
- 
getPathReturn aPathobject by converting the givenURI. The resultingPathis associated with aFileSystemthat already exists or is constructed automatically.- Specified by:
- getPathin class- FileSystemProvider
- Parameters:
- uri- a URI of the form- "s3://accessKey@bucket/key".
- Returns:
- the resulting Path.
- Throws:
- IllegalArgumentException- if the URI is not supported by this provider.
- FileSystemNotFoundException- if the file system does not exist and cannot be created automatically.
 
- 
isSameFileTests if two paths locate the same file.- Specified by:
- isSameFilein class- FileSystemProvider
- Parameters:
- path1- one path to the file.
- path2- the other path.
- Returns:
- trueif the two paths locate the same file.
- Throws:
- IOException- if an I/O error occurs.
 
- 
isHiddenTells whether a file is considered hidden. Current implementation always returnfalse.- Specified by:
- isHiddenin class- FileSystemProvider
- Parameters:
- path- the path to the file to test.
- Returns:
- trueif the file is considered hidden.
- Throws:
- IOException- if an I/O error occurs.
 
- 
getFileStoreReturns the store where a file is located.- Specified by:
- getFileStorein class- FileSystemProvider
- Parameters:
- path- the path to the file.
- Returns:
- the store where the file is stored.
- Throws:
- IOException- if an I/O error occurs.
 
- 
newDirectoryStreampublic DirectoryStream<Path> newDirectoryStream(Path directory, DirectoryStream.Filter<? super Path> filter) throws IOException Opens a directory and returns aDirectoryStreamto iterate over its entries. S3 does not formally has directories. Instead directories are simulated by handling the'/'character in a special way.- Specified by:
- newDirectoryStreamin class- FileSystemProvider
- Parameters:
- directory- the path to the directory.
- filter- the directory stream filter.
- Returns:
- a new and open stream on directory entries.
- Throws:
- NotDirectoryException- if the file is not a directory.
- IOException- if an I/O error occurs.
 
- 
createDirectoryCreates a new pseudo-directory. S3 does not formally has directories, so the current operation does nothing. Instead a pseudo-directory will appear after the first file or sub-directory is added in the directory.- Specified by:
- createDirectoryin class- FileSystemProvider
- Parameters:
- directory- the directory to create.
- attributes- an optional list of file attributes to set when creating the directory.
- Throws:
- IOException- if an I/O error occurs or the parent directory does not exist.
 
- 
copyCopies a file. This method is not yet supported.- Specified by:
- copyin class- FileSystemProvider
- Parameters:
- source- the path to the file to copy.
- target- the path to the target file.
- options- options specifying how the copy should be done
- Throws:
- IOException- if an I/O error occurs.
 
- 
moveCopies a file. This method is not yet supported.- Specified by:
- movein class- FileSystemProvider
- Parameters:
- source- the path to the file to move.
- target- the path to the target file.
- options- options specifying how the move should be done
- Throws:
- IOException- if an I/O error occurs.
 
- 
deleteDeletes a file. This method is not yet supported.- Specified by:
- deletein class- FileSystemProvider
- Parameters:
- path- the path to the file to delete.
- Throws:
- IOException- if an I/O error occurs.
 
- 
newInputStreampublic ResponseInputStream<GetObjectResponse> newInputStream(Path path, OpenOption... options) throws IOException Opens an input stream to read from the path. It is important to close the input stream after usage for avoiding exhaustion of connection pool.- Overrides:
- newInputStreamin class- FileSystemProvider
- Parameters:
- path- the path to the file to open.
- options- options specifying how the file is opened.
- Returns:
- a new input stream for the specified path.
- Throws:
- UnsupportedOperationException- if an unsupported option is specified.
- IOException- if an I/O error occurs.
 
- 
newByteChannelpublic SeekableByteChannel newByteChannel(Path path, Set<? extends OpenOption> options, FileAttribute<?>... attributes) throws IOException Returns a seekable byte channel to access a file.- Specified by:
- newByteChannelin class- FileSystemProvider
- Parameters:
- path- the path to the file to open.
- options- options specifying how the file is opened.
- attributes- an optional list of file attributes to set when creating the file.
- Returns:
- a new seekable byte channel for the specified path.
- Throws:
- UnsupportedOperationException- if an unsupported open option is specified.
- IOException- if an I/O error occurs.
 
- 
checkAccessChecks the existence, and optionally the accessibility, of a file.- Specified by:
- checkAccessin class- FileSystemProvider
- Parameters:
- path- the path to the file to check.
- modes- the access modes to check; may have zero elements.
- Throws:
- NoSuchFileException- if a file does not exist (optional specific exception).
- AccessDeniedException- the requested access would be denied.
- IOException- if an I/O error occurs
 
- 
getFileAttributeViewpublic <V extends FileAttributeView> V getFileAttributeView(Path path, Class<V> type, LinkOption... options) Returns a read-only or updatable view of a set of file attributes.- Specified by:
- getFileAttributeViewin class- FileSystemProvider
- Type Parameters:
- V- the view type.
- Parameters:
- path- the path to the file.
- type- the class of the file attribute view.
- options- options indicating how symbolic links are handled.
- Returns:
- a file attribute view of the specified type, or nullif not available.
 
- 
readAttributespublic <A extends BasicFileAttributes> A readAttributes(Path path, Class<A> type, LinkOption... options) throws IOException Reads a file's attributes as a bulk operation.- Specified by:
- readAttributesin class- FileSystemProvider
- Type Parameters:
- A- the- BasicFileAttributestype.
- Parameters:
- path- the path to the file.
- type- the class of the file attributes to read.
- options- options indicating how symbolic links are handled.
- Returns:
- the file attributes.
- Throws:
- UnsupportedOperationException- if attributes of the given type are not supported.
- IOException- if an I/O error occurs.
 
- 
readAttributespublic Map<String,Object> readAttributes(Path path, String attributes, LinkOption... options) throws IOException Reads a set of file attributes as a bulk operation. See NIO javadoc for details about theattributesargument.- Specified by:
- readAttributesin class- FileSystemProvider
- Parameters:
- path- the path to the file.
- attributes- the attributes to read.
- options- options indicating how symbolic links are handled
- Returns:
- a map of the attributes returned; may be empty. The map's keys are the attribute names, its values are the attribute values.
- Throws:
- IOException- if an I/O error occurs.
- See Also:
 
- 
setAttributepublic void setAttribute(Path path, String attribute, Object value, LinkOption... options) throws IOException - Specified by:
- setAttributein class- FileSystemProvider
- Throws:
- IOException
 
 
-