public class S3FileSystemProvider extends FileSystemProvider
URI: s3://[endpoint]/{bucket}/{key} If endpoint is missing, it's assumed to be the default S3 endpoint (s3.amazonaws.com)
FileSystem roots: /{bucket}/
Treatment of S3 objects: - If a key ends in "/" it's considered a directory *and* a regular file. Otherwise, it's just a regular file. - It is legal for a key "xyz" and "xyz/" to exist at the same time. The latter is treated as a directory. - If a file "a/b/c" exists but there's no "a" or "a/b/", these are considered "implicit" directories. They can be listed, traversed and deleted.
Deviations from FileSystem provider API: - Deleting a file or directory always succeeds, regardless of whether the file/directory existed before the operation was issued i.e. Files.delete() and Files.deleteIfExists() are equivalent.
Future versions of this provider might allow for a strict mode that mimics the semantics of the FileSystem provider API on a best effort basis, at an increased processing cost.
| Modifier and Type | Field and Description |
|---|---|
static String |
AMAZON_S3_FACTORY_CLASS |
static String |
CHARSET_KEY |
| Constructor and Description |
|---|
S3FileSystemProvider() |
| Modifier and Type | Method and Description |
|---|---|
protected void |
addEnvProperties(Properties props,
Map<String,?> env) |
void |
checkAccess(Path path,
AccessMode... modes) |
void |
close(S3FileSystem fileSystem) |
void |
copy(Path source,
Path target,
CopyOption... options) |
void |
createDirectory(Path dir,
FileAttribute<?>... attrs)
Deviations from spec: Does not perform atomic check-and-create.
|
S3FileSystem |
createFileSystem(URI uri,
Properties props)
Create the fileSystem
|
void |
delete(Path path) |
protected com.amazonaws.services.s3.AmazonS3 |
getAmazonS3(URI uri,
Properties props) |
protected AmazonS3Factory |
getAmazonS3Factory(Properties props) |
Cache |
getCache() |
<V extends FileAttributeView> |
getFileAttributeView(Path path,
Class<V> type,
LinkOption... options) |
FileStore |
getFileStore(Path path) |
S3FileSystem |
getFileSystem(URI uri) |
FileSystem |
getFileSystem(URI uri,
Map<String,?> env)
Get existing filesystem based on a combination of URI and env settings.
|
protected String |
getFileSystemKey(URI uri,
Properties props)
get the file system key represented by: the access key @ endpoint.
|
protected static ConcurrentMap<String,S3FileSystem> |
getFilesystems()
only 4 testing
|
Path |
getPath(URI uri)
Deviation from spec: throws FileSystemNotFoundException if FileSystem
hasn't yet been initialized.
|
String |
getScheme() |
boolean |
isHidden(Path path) |
boolean |
isOpen(S3FileSystem s3FileSystem) |
boolean |
isSameFile(Path path1,
Path path2) |
Properties |
loadAmazonProperties()
find /amazon.properties in the classpath
|
void |
move(Path source,
Path target,
CopyOption... options) |
SeekableByteChannel |
newByteChannel(Path path,
Set<? extends OpenOption> options,
FileAttribute<?>... attrs) |
DirectoryStream<Path> |
newDirectoryStream(Path dir,
DirectoryStream.Filter<? super Path> filter) |
FileChannel |
newFileChannel(Path path,
Set<? extends OpenOption> options,
FileAttribute<?>... attrs) |
FileSystem |
newFileSystem(URI uri,
Map<String,?> env) |
InputStream |
newInputStream(Path path,
OpenOption... options) |
protected boolean |
overloadPropertiesWithEnv(Properties props,
Map<String,?> env,
String key) |
boolean |
overloadPropertiesWithSystemEnv(Properties props,
String key)
The system envs have preference over the properties files.
|
boolean |
overloadPropertiesWithSystemProps(Properties props,
String key) |
<A extends BasicFileAttributes> |
readAttributes(Path path,
Class<A> type,
LinkOption... options) |
Map<String,Object> |
readAttributes(Path path,
String attributes,
LinkOption... options) |
void |
setAttribute(Path path,
String attribute,
Object value,
LinkOption... options) |
void |
setCache(Cache cache) |
String |
systemGetEnv(String key)
Get the system env with the key param
|
protected void |
validateUri(URI uri) |
createLink, createSymbolicLink, deleteIfExists, installedProviders, newAsynchronousFileChannel, newFileSystem, newOutputStream, readSymbolicLinkpublic static final String CHARSET_KEY
public static final String AMAZON_S3_FACTORY_CLASS
public String getScheme()
getScheme in class FileSystemProviderpublic FileSystem newFileSystem(URI uri, Map<String,?> env)
newFileSystem in class FileSystemProviderprotected String getFileSystemKey(URI uri, Properties props)
uri - URI with the endpointprops - with the access key propertyprotected void validateUri(URI uri)
protected void addEnvProperties(Properties props, Map<String,?> env)
protected boolean overloadPropertiesWithEnv(Properties props, Map<String,?> env, String key)
public boolean overloadPropertiesWithSystemProps(Properties props, String key)
public boolean overloadPropertiesWithSystemEnv(Properties props, String key)
props - Propertieskey - Stringpublic String systemGetEnv(String key)
key - Stringpublic FileSystem getFileSystem(URI uri, Map<String,?> env)
uri - URI of existing, or to be created filesystem.env - environment settings.public S3FileSystem getFileSystem(URI uri)
getFileSystem in class FileSystemProviderpublic Path getPath(URI uri)
getPath in class FileSystemProviderpublic DirectoryStream<Path> newDirectoryStream(Path dir, DirectoryStream.Filter<? super Path> filter) throws IOException
newDirectoryStream in class FileSystemProviderIOExceptionpublic InputStream newInputStream(Path path, OpenOption... options) throws IOException
newInputStream in class FileSystemProviderIOExceptionpublic SeekableByteChannel newByteChannel(Path path, Set<? extends OpenOption> options, FileAttribute<?>... attrs) throws IOException
newByteChannel in class FileSystemProviderIOExceptionpublic FileChannel newFileChannel(Path path, Set<? extends OpenOption> options, FileAttribute<?>... attrs) throws IOException
newFileChannel in class FileSystemProviderIOExceptionpublic void createDirectory(Path dir, FileAttribute<?>... attrs) throws IOException
createDirectory in class FileSystemProviderIOExceptionpublic void delete(Path path) throws IOException
delete in class FileSystemProviderIOExceptionpublic void copy(Path source, Path target, CopyOption... options) throws IOException
copy in class FileSystemProviderIOExceptionpublic void move(Path source, Path target, CopyOption... options) throws IOException
move in class FileSystemProviderIOExceptionpublic boolean isSameFile(Path path1, Path path2) throws IOException
isSameFile in class FileSystemProviderIOExceptionpublic boolean isHidden(Path path) throws IOException
isHidden in class FileSystemProviderIOExceptionpublic FileStore getFileStore(Path path) throws IOException
getFileStore in class FileSystemProviderIOExceptionpublic void checkAccess(Path path, AccessMode... modes) throws IOException
checkAccess in class FileSystemProviderIOExceptionpublic <V extends FileAttributeView> V getFileAttributeView(Path path, Class<V> type, LinkOption... options)
getFileAttributeView in class FileSystemProviderpublic <A extends BasicFileAttributes> A readAttributes(Path path, Class<A> type, LinkOption... options) throws IOException
readAttributes in class FileSystemProviderIOExceptionpublic Map<String,Object> readAttributes(Path path, String attributes, LinkOption... options) throws IOException
readAttributes in class FileSystemProviderIOExceptionpublic void setAttribute(Path path, String attribute, Object value, LinkOption... options) throws IOException
setAttribute in class FileSystemProviderIOExceptionpublic S3FileSystem createFileSystem(URI uri, Properties props)
uri - URIprops - Propertiesprotected com.amazonaws.services.s3.AmazonS3 getAmazonS3(URI uri, Properties props)
protected AmazonS3Factory getAmazonS3Factory(Properties props)
public Properties loadAmazonProperties()
public void close(S3FileSystem fileSystem)
public boolean isOpen(S3FileSystem s3FileSystem)
protected static ConcurrentMap<String,S3FileSystem> getFilesystems()
public Cache getCache()
public void setCache(Cache cache)
Copyright © 2018. All rights reserved.