|
|
|
@ -48,7 +48,7 @@ import java.util.regex.Pattern;
|
|
|
|
|
/**
|
|
|
|
|
* An FTP file system.
|
|
|
|
|
*/
|
|
|
|
|
class FTPFileSystem extends FileSystem {
|
|
|
|
|
public class FTPFileSystem extends FileSystem {
|
|
|
|
|
|
|
|
|
|
static final String CURRENT_DIR = ".";
|
|
|
|
|
static final String PARENT_DIR = "..";
|
|
|
|
@ -74,7 +74,7 @@ class FTPFileSystem extends FileSystem {
|
|
|
|
|
private final FTPFileStrategy ftpFileStrategy;
|
|
|
|
|
private final AtomicBoolean open = new AtomicBoolean(true);
|
|
|
|
|
|
|
|
|
|
FTPFileSystem(FTPFileSystemProvider provider, URI uri, FTPEnvironment env) throws IOException {
|
|
|
|
|
public FTPFileSystem(FTPFileSystemProvider provider, URI uri, FTPEnvironment env) throws IOException {
|
|
|
|
|
this.provider = Objects.requireNonNull(provider);
|
|
|
|
|
this.rootDirectories = Collections.<Path>singleton(new FTPPath(this, "/"));
|
|
|
|
|
this.fileStore = new FTPFileStore(this);
|
|
|
|
@ -90,7 +90,7 @@ class FTPFileSystem extends FileSystem {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static String getFileName(FTPFile ftpFile) {
|
|
|
|
|
public static String getFileName(FTPFile ftpFile) {
|
|
|
|
|
String fileName = ftpFile.getName();
|
|
|
|
|
if (fileName == null) {
|
|
|
|
|
return null;
|
|
|
|
@ -172,27 +172,27 @@ class FTPFileSystem extends FileSystem {
|
|
|
|
|
throw Messages.unsupportedOperation(FileSystem.class, "newWatchService");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void keepAlive() throws IOException {
|
|
|
|
|
public void keepAlive() throws IOException {
|
|
|
|
|
clientPool.keepAlive();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
URI toUri(FTPPath path) {
|
|
|
|
|
public URI toUri(FTPPath path) {
|
|
|
|
|
FTPPath absPath = toAbsolutePath(path).normalize();
|
|
|
|
|
return toUri(absPath.path());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
URI toUri(String path) {
|
|
|
|
|
public URI toUri(String path) {
|
|
|
|
|
return URISupport.create(uri.getScheme(), uri.getUserInfo(), uri.getHost(), uri.getPort(), path, null, null);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
FTPPath toAbsolutePath(FTPPath path) {
|
|
|
|
|
public FTPPath toAbsolutePath(FTPPath path) {
|
|
|
|
|
if (path.isAbsolute()) {
|
|
|
|
|
return path;
|
|
|
|
|
}
|
|
|
|
|
return new FTPPath(this, defaultDirectory + "/" + path.path());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
FTPPath toRealPath(FTPPath path, LinkOption... options) throws IOException {
|
|
|
|
|
public FTPPath toRealPath(FTPPath path, LinkOption... options) throws IOException {
|
|
|
|
|
boolean followLinks = LinkOptionSupport.followLinks(options);
|
|
|
|
|
try (FTPClientPool.Client client = clientPool.get()) {
|
|
|
|
|
return toRealPath(client, path, followLinks).ftpPath;
|
|
|
|
@ -221,7 +221,7 @@ class FTPFileSystem extends FileSystem {
|
|
|
|
|
return path.path();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
InputStream newInputStream(FTPPath path, OpenOption... options) throws IOException {
|
|
|
|
|
public InputStream newInputStream(FTPPath path, OpenOption... options) throws IOException {
|
|
|
|
|
OpenOptions openOptions = OpenOptions.forNewInputStream(options);
|
|
|
|
|
|
|
|
|
|
try (FTPClientPool.Client client = clientPool.get()) {
|
|
|
|
@ -235,7 +235,7 @@ class FTPFileSystem extends FileSystem {
|
|
|
|
|
return client.newInputStream(path.path(), options);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
OutputStream newOutputStream(FTPPath path, OpenOption... options) throws IOException {
|
|
|
|
|
public OutputStream newOutputStream(FTPPath path, OpenOption... options) throws IOException {
|
|
|
|
|
OpenOptions openOptions = OpenOptions.forNewOutputStream(options);
|
|
|
|
|
|
|
|
|
|
try (FTPClientPool.Client client = clientPool.get()) {
|
|
|
|
@ -268,7 +268,7 @@ class FTPFileSystem extends FileSystem {
|
|
|
|
|
return new FTPFileAndOutputStreamPair(ftpFile, out);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
SeekableByteChannel newByteChannel(FTPPath path, Set<? extends OpenOption> options, FileAttribute<?>... attrs) throws IOException {
|
|
|
|
|
public SeekableByteChannel newByteChannel(FTPPath path, Set<? extends OpenOption> options, FileAttribute<?>... attrs) throws IOException {
|
|
|
|
|
if (attrs.length > 0) {
|
|
|
|
|
throw Messages.fileSystemProvider().unsupportedCreateFileAttribute(attrs[0].name());
|
|
|
|
|
}
|
|
|
|
@ -292,7 +292,7 @@ class FTPFileSystem extends FileSystem {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
DirectoryStream<Path> newDirectoryStream(final FTPPath path, Filter<? super Path> filter) throws IOException {
|
|
|
|
|
public DirectoryStream<Path> newDirectoryStream(final FTPPath path, Filter<? super Path> filter) throws IOException {
|
|
|
|
|
List<FTPFile> children;
|
|
|
|
|
try (FTPClientPool.Client client = clientPool.get()) {
|
|
|
|
|
children = ftpFileStrategy.getChildren(client, path);
|
|
|
|
@ -300,7 +300,7 @@ class FTPFileSystem extends FileSystem {
|
|
|
|
|
return new FTPPathDirectoryStream(path, children, filter);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void createDirectory(FTPPath path, FileAttribute<?>... attrs) throws IOException {
|
|
|
|
|
public void createDirectory(FTPPath path, FileAttribute<?>... attrs) throws IOException {
|
|
|
|
|
if (attrs.length > 0) {
|
|
|
|
|
throw Messages.fileSystemProvider().unsupportedCreateFileAttribute(attrs[0].name());
|
|
|
|
|
}
|
|
|
|
@ -309,7 +309,7 @@ class FTPFileSystem extends FileSystem {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void delete(FTPPath path) throws IOException {
|
|
|
|
|
public void delete(FTPPath path) throws IOException {
|
|
|
|
|
try (FTPClientPool.Client client = clientPool.get()) {
|
|
|
|
|
FTPFile ftpFile = getFTPFile(client, path);
|
|
|
|
|
boolean isDirectory = ftpFile.isDirectory();
|
|
|
|
@ -317,7 +317,7 @@ class FTPFileSystem extends FileSystem {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
FTPPath readSymbolicLink(FTPPath path) throws IOException {
|
|
|
|
|
public FTPPath readSymbolicLink(FTPPath path) throws IOException {
|
|
|
|
|
try (FTPClientPool.Client client = clientPool.get()) {
|
|
|
|
|
FTPFile ftpFile = getFTPFile(client, path);
|
|
|
|
|
FTPFile link = getLink(client, ftpFile, path);
|
|
|
|
@ -328,7 +328,7 @@ class FTPFileSystem extends FileSystem {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void copy(FTPPath source, FTPPath target, CopyOption... options) throws IOException {
|
|
|
|
|
public void copy(FTPPath source, FTPPath target, CopyOption... options) throws IOException {
|
|
|
|
|
boolean sameFileSystem = source.getFileSystem() == target.getFileSystem();
|
|
|
|
|
CopyOptions copyOptions = CopyOptions.forCopy(options);
|
|
|
|
|
|
|
|
|
@ -403,7 +403,7 @@ class FTPFileSystem extends FileSystem {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void move(FTPPath source, FTPPath target, CopyOption... options) throws IOException {
|
|
|
|
|
public void move(FTPPath source, FTPPath target, CopyOption... options) throws IOException {
|
|
|
|
|
boolean sameFileSystem = source.getFileSystem() == target.getFileSystem();
|
|
|
|
|
CopyOptions copyOptions = CopyOptions.forMove(sameFileSystem, options);
|
|
|
|
|
|
|
|
|
@ -444,7 +444,7 @@ class FTPFileSystem extends FileSystem {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
boolean isSameFile(FTPPath path, FTPPath path2) throws IOException {
|
|
|
|
|
public boolean isSameFile(FTPPath path, FTPPath path2) throws IOException {
|
|
|
|
|
if (path.getFileSystem() != path2.getFileSystem()) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
@ -463,7 +463,7 @@ class FTPFileSystem extends FileSystem {
|
|
|
|
|
return toRealPath(client, path, true).ftpPath.path().equals(toRealPath(client, path2, true).ftpPath.path());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
boolean isHidden(FTPPath path) throws IOException {
|
|
|
|
|
public boolean isHidden(FTPPath path) throws IOException {
|
|
|
|
|
// call getFTPFile to check for existence
|
|
|
|
|
try (FTPClientPool.Client client = clientPool.get()) {
|
|
|
|
|
getFTPFile(client, path);
|
|
|
|
@ -472,7 +472,7 @@ class FTPFileSystem extends FileSystem {
|
|
|
|
|
return !CURRENT_DIR.equals(fileName) && !PARENT_DIR.equals(fileName) && fileName.startsWith(".");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
FileStore getFileStore(FTPPath path) throws IOException {
|
|
|
|
|
public FileStore getFileStore(FTPPath path) throws IOException {
|
|
|
|
|
// call getFTPFile to check existence of the path
|
|
|
|
|
try (FTPClientPool.Client client = clientPool.get()) {
|
|
|
|
|
getFTPFile(client, path);
|
|
|
|
@ -480,7 +480,7 @@ class FTPFileSystem extends FileSystem {
|
|
|
|
|
return fileStore;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void checkAccess(FTPPath path, AccessMode... modes) throws IOException {
|
|
|
|
|
public void checkAccess(FTPPath path, AccessMode... modes) throws IOException {
|
|
|
|
|
try (FTPClientPool.Client client = clientPool.get()) {
|
|
|
|
|
FTPFile ftpFile = getFTPFile(client, path);
|
|
|
|
|
for (AccessMode mode : modes) {
|
|
|
|
@ -504,7 +504,7 @@ class FTPFileSystem extends FileSystem {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
PosixFileAttributes readAttributes(FTPPath path, LinkOption... options) throws IOException {
|
|
|
|
|
public PosixFileAttributes readAttributes(FTPPath path, LinkOption... options) throws IOException {
|
|
|
|
|
boolean followLinks = LinkOptionSupport.followLinks(options);
|
|
|
|
|
try (FTPClientPool.Client client = clientPool.get()) {
|
|
|
|
|
FTPPathAndFilePair pair = toRealPath(client, path, followLinks);
|
|
|
|
@ -515,7 +515,7 @@ class FTPFileSystem extends FileSystem {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Map<String, Object> readAttributes(FTPPath path, String attributes, LinkOption... options) throws IOException {
|
|
|
|
|
public Map<String, Object> readAttributes(FTPPath path, String attributes, LinkOption... options) throws IOException {
|
|
|
|
|
String view;
|
|
|
|
|
int pos = attributes.indexOf(':');
|
|
|
|
|
if (pos == -1) {
|
|
|
|
@ -622,7 +622,7 @@ class FTPFileSystem extends FileSystem {
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
FTPFile getFTPFile(FTPPath path) throws IOException {
|
|
|
|
|
public FTPFile getFTPFile(FTPPath path) throws IOException {
|
|
|
|
|
try (FTPClientPool.Client client = clientPool.get()) {
|
|
|
|
|
return getFTPFile(client, path);
|
|
|
|
|
}
|
|
|
|
|