Class S3FileSystem
- java.lang.Object
-
- java.nio.file.FileSystem
-
- software.amazon.nio.spi.s3.S3FileSystem
-
- All Implemented Interfaces:
java.io.Closeable,java.lang.AutoCloseable
public class S3FileSystem extends java.nio.file.FileSystemA Java NIO FileSystem for an S3 bucket as seen through the lens of the AWS Principal calling the class.
-
-
Field Summary
Fields Modifier and Type Field Description static java.lang.StringBASIC_FILE_ATTRIBUTE_VIEWView required by Java NIO
-
Constructor Summary
Constructors Modifier Constructor Description protectedS3FileSystem(java.lang.String bucketName)Create a filesystem that represents the named bucket.protectedS3FileSystem(java.lang.String uriString, S3FileSystemProvider s3FileSystemProvider)Create a filesystem that represents the bucket specified by the URIprotectedS3FileSystem(java.net.URI uri, S3FileSystemProvider s3FileSystemProvider)Create a filesystem that represents the bucket specified by the URI
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description java.lang.StringbucketName()Obtain the name of the bucket represented by this FileSystem instancevoidclose()Closes this file system.protected booleanderegisterClosedChannel(S3SeekableByteChannel closedChannel)booleanequals(java.lang.Object o)Tests if two S3 filesystems are equaljava.lang.Iterable<java.nio.file.FileStore>getFileStores()An S3 bucket has no partitions, size limits or limits on the number of objects stored so there are no FileStores.protected java.util.Set<java.nio.channels.Channel>getOpenChannels()The list of currently open channels.S3PathgetPath(java.lang.String first, java.lang.String... more)Converts an S3 object path string, or a sequence of strings that when joined form a path string, to aS3Path.java.nio.file.PathMatchergetPathMatcher(java.lang.String syntaxAndPattern)Returns aPathMatcherthat performs match operations on theStringrepresentation ofPathobjects by interpreting a given pattern.java.lang.Iterable<java.nio.file.Path>getRootDirectories()Returns an object to iterate over the paths of the root directories.java.lang.StringgetSeparator()Returns the name separator '/', represented as a string.java.nio.file.attribute.UserPrincipalLookupServicegetUserPrincipalLookupService()Currently Not ImplementedinthashCode()booleanisOpen()Tells whether this file system is open.booleanisReadOnly()Tells whether this file system allows only read-only access to its file stores.java.nio.file.WatchServicenewWatchService()Currently not implementedjava.nio.file.spi.FileSystemProviderprovider()Returns the provider that created this file system.protected voidregisterOpenChannel(S3SeekableByteChannel channel)java.util.Set<java.lang.String>supportedFileAttributeViews()Returns the set of the file attribute views supported by thisFileSystem.
-
-
-
Field Detail
-
BASIC_FILE_ATTRIBUTE_VIEW
public static final java.lang.String BASIC_FILE_ATTRIBUTE_VIEW
View required by Java NIO- See Also:
- Constant Field Values
-
-
Constructor Detail
-
S3FileSystem
protected S3FileSystem(java.lang.String uriString, S3FileSystemProvider s3FileSystemProvider)Create a filesystem that represents the bucket specified by the URI- Parameters:
uriString- a valid S3 URI to a bucket, e.g "s3://mybucket"s3FileSystemProvider- the provider to be used with this fileSystem
-
S3FileSystem
protected S3FileSystem(java.net.URI uri, S3FileSystemProvider s3FileSystemProvider)Create a filesystem that represents the bucket specified by the URI- Parameters:
uri- a valid S3 URI to a bucket, e.gURI.create("s3://mybucket")s3FileSystemProvider- the provider to be used with this fileSystem
-
S3FileSystem
protected S3FileSystem(java.lang.String bucketName)
Create a filesystem that represents the named bucket.- Parameters:
bucketName- the name of the bucket. Must not be null or empty
-
-
Method Detail
-
provider
public java.nio.file.spi.FileSystemProvider provider()
Returns the provider that created this file system.- Specified by:
providerin classjava.nio.file.FileSystem- Returns:
- The provider that created this file system.
-
bucketName
public java.lang.String bucketName()
Obtain the name of the bucket represented by this FileSystem instance- Returns:
- the bucket name
-
close
public void close() throws java.io.IOExceptionCloses this file system.After a file system is closed then all subsequent access to the file system, either by methods defined by this class or on objects associated with this file system, throw
ClosedFileSystemException. If the file system is already closed then invoking this method has no effect.Closing a file system will close all open
channels,directory-streams,watch-service, and other closeable objects associated with this file system. Thedefaultfile system cannot be closed.- Specified by:
closein interfacejava.lang.AutoCloseable- Specified by:
closein interfacejava.io.Closeable- Specified by:
closein classjava.nio.file.FileSystem- Throws:
java.io.IOException
-
isOpen
public boolean isOpen()
Tells whether this file system is open.File systems created by the default provider are always open.
- Specified by:
isOpenin classjava.nio.file.FileSystem- Returns:
trueif, and only if, this file system is open
-
isReadOnly
public boolean isReadOnly()
Tells whether this file system allows only read-only access to its file stores.
This is currently always false. The ability to write an individual object depend on the IAM role that is used by the principal and the ACL of the bucket, but S3 itself is not inherently read only.- Specified by:
isReadOnlyin classjava.nio.file.FileSystem- Returns:
false
-
getSeparator
public java.lang.String getSeparator()
Returns the name separator '/', represented as a string.The name separator is used to separate names in a path string. An implementation may support multiple name separators in which case this method returns an implementation specific default name separator. This separator is used when creating path strings by invoking the
toString()method.In the case of the default provider, this method returns the same separator as
File.separator.- Specified by:
getSeparatorin classjava.nio.file.FileSystem- Returns:
- The name separator "/"
-
getRootDirectories
public java.lang.Iterable<java.nio.file.Path> getRootDirectories()
Returns an object to iterate over the paths of the root directories.A file system provides access to a file store that may be composed of a number of distinct file hierarchies, each with its own top-level root directory. Unless denied by the security manager, each element in the returned iterator corresponds to the root directory of a distinct file hierarchy. The order of the elements is not defined. The file hierarchies may change during the lifetime of the Java virtual machine. For example, in some implementations, the insertion of removable media may result in the creation of a new file hierarchy with its own top-level directory.
When a security manager is installed, it is invoked to check access to the root directory. If denied, the root directory is not returned by the iterator. In the case of the default provider, the
SecurityManager.checkRead(String)method is invoked to check read access to each root directory. It is system dependent if the permission checks are done when the iterator is obtained or during iteration.- Specified by:
getRootDirectoriesin classjava.nio.file.FileSystem- Returns:
- An object to iterate over the root directories
-
getFileStores
public java.lang.Iterable<java.nio.file.FileStore> getFileStores()
An S3 bucket has no partitions, size limits or limits on the number of objects stored so there are no FileStores.- Specified by:
getFileStoresin classjava.nio.file.FileSystem- Returns:
- An immutable empty set
-
supportedFileAttributeViews
public java.util.Set<java.lang.String> supportedFileAttributeViews()
Returns the set of the file attribute views supported by thisFileSystem.
This FileSystem currently supports only the "basic" file attribute view.- Specified by:
supportedFileAttributeViewsin classjava.nio.file.FileSystem- Returns:
- An unmodifiable set of the names of the supported file attribute views
-
getPath
public S3Path getPath(java.lang.String first, java.lang.String... more)
Converts an S3 object path string, or a sequence of strings that when joined form a path string, to aS3Path.If
moredoes not specify any elements then the value of thefirstparameter is the path string to convert. Ifmorespecifies one or more elements, then each non-empty string, includingfirst, is considered to be a sequence of name elements (seePath) and is joined to form a path string. The details as to how the Strings are joined is provider specific, but typically they will be joined using thename-separatoras the separator. For example, if the name separator is "/" andgetPath("/foo","bar","gus")is invoked, then the path string"/foo/bar/gus"is converted to aPath. APathrepresenting an empty path is returned iffirstis the empty string andmoredoes not contain any non-empty strings.The parsing and conversion to a path object is inherently implementation dependent. In the simplest case, the path string is rejected, and
InvalidPathExceptionthrown, if the path string contains characters that cannot be converted to characters that are legal to the file store. For example, on UNIX systems, the NUL (\u0000) character is not allowed to be present in a path. An implementation may choose to reject path strings that contain names that are longer than those allowed by any file store, and where an implementation supports a complex path syntax, it may choose to reject path strings that are badly formed.In the case of the default provider, path strings are parsed based on the definition of paths at the platform or virtual file system level. For example, an operating system may not allow specific characters to be present in a file name, but a specific underlying file store may impose different or additional restrictions on the set of legal characters.
This method throws
InvalidPathExceptionwhen the path string cannot be converted to a path. Where possible, and where applicable, the exception is created with anindexvalue indicating the first position in thepathparameter that caused the path string to be rejected.- Specified by:
getPathin classjava.nio.file.FileSystem- Parameters:
first- the path string or initial part of the path stringmore- additional strings to be joined to form the path string- Returns:
- the resulting
Path - Throws:
java.nio.file.InvalidPathException- If the path string cannot be converted
-
getPathMatcher
public java.nio.file.PathMatcher getPathMatcher(java.lang.String syntaxAndPattern)
Returns aPathMatcherthat performs match operations on theStringrepresentation ofPathobjects by interpreting a given pattern.The
syntaxAndPatternparameter identifies the syntax and the pattern and takes the form:
wheresyntax:pattern
':'stands for itself.A
FileSystemimplementation supports the "glob" and "regex" syntax's. The value of the syntax component is compared without regard to case.When the syntax is "
glob" then theStringrepresentation of the path is matched using a limited pattern language that resembles regular expressions but with a simpler syntax.The following rules are used to interpret glob patterns:
The
*character matches zero or morecharactersof anamecomponent without crossing directory boundaries.The
**characters matches zero or morecharacterscrossing directory boundaries.The
?character matches exactly one character of a name component.The backslash character (
\) is used to escape characters that would otherwise be interpreted as special characters. The expression\\matches a single backslash and "\{" matches a left brace for example.The
[ ]characters are a bracket expression that match a single character of a name component out of a set of characters. For example,[abc]matches"a","b", or"c". The hyphen (-) may be used to specify a range so[a-z]specifies a range that matches from"a"to"z"(inclusive). These forms can be mixed so [abce-g] matches"a","b","c","e","f"or"g". If the character after the[is a!then it is used for negation so[!a-c]matches any character except"a","b", or"c".Within a bracket expression the
*,?and\characters match themselves. The (-) character matches itself if it is the first character within the brackets, or the first character after the!if negating.The
{ }characters are a group of sub-patterns, where the group matches if any subpattern in the group matches. The","character is used to separate the sub-patterns. Groups cannot be nested.Leading period dot characters in file name are treated as regular characters in match operations. For example, the
"*"glob pattern matches file name".login". TheFiles.isHidden(java.nio.file.Path)method may be used to test whether a file is considered hidden.All other characters match themselves in an implementation dependent manner. This includes characters representing any
name-separators.The matching of
rootcomponents is highly implementation-dependent and is not specified.
When the syntax is "
regex" then the pattern component is a regular expression as defined by thePatternclass.For both the glob and regex syntaxes, the matching details, such as whether the matching is case-sensitive, are implementation-dependent and therefore not specified.
- Specified by:
getPathMatcherin classjava.nio.file.FileSystem- Parameters:
syntaxAndPattern- The syntax and pattern- Returns:
- A path matcher that may be used to match paths against the pattern
- Throws:
java.lang.IllegalArgumentException- If the parameter does not take the form:syntax:patternjava.util.regex.PatternSyntaxException- If the pattern is invalidjava.lang.UnsupportedOperationException- If the pattern syntax is not known to the implementation- See Also:
Files.newDirectoryStream(Path, String)
-
getUserPrincipalLookupService
public java.nio.file.attribute.UserPrincipalLookupService getUserPrincipalLookupService()
Currently Not Implemented- Specified by:
getUserPrincipalLookupServicein classjava.nio.file.FileSystem- Returns:
- The
UserPrincipalLookupServicefor this file system - Throws:
java.lang.UnsupportedOperationException- If thisFileSystemdoes not does have a lookup service
-
newWatchService
public java.nio.file.WatchService newWatchService()
Currently not implemented- Specified by:
newWatchServicein classjava.nio.file.FileSystem- Returns:
- a new watch service
- Throws:
java.lang.UnsupportedOperationException- If thisFileSystemdoes not support watching file system objects for changes and events. This exception is not thrown byFileSystemscreated by the default provider.
-
getOpenChannels
protected java.util.Set<java.nio.channels.Channel> getOpenChannels()
The list of currently open channels. Exposed mainly for testing- Returns:
- a read only view wrapping the set of currently open channels.
-
registerOpenChannel
protected void registerOpenChannel(S3SeekableByteChannel channel)
-
deregisterClosedChannel
protected boolean deregisterClosedChannel(S3SeekableByteChannel closedChannel)
-
equals
public boolean equals(java.lang.Object o)
Tests if two S3 filesystems are equal- Overrides:
equalsin classjava.lang.Object- Parameters:
o- the object to test for equality- Returns:
- true if
ois not null, is anS3FileSystemand uses the sameS3FileSystemProviderclass
-
hashCode
public int hashCode()
- Overrides:
hashCodein classjava.lang.Object
-
-