Merge branch 'master' of https://gitbox.apache.org/repos/asf/commons-vfs.git
diff --git a/commons-vfs2/src/main/java/org/apache/commons/vfs2/FileName.java b/commons-vfs2/src/main/java/org/apache/commons/vfs2/FileName.java
index 7c65782..e0cfa55 100644
--- a/commons-vfs2/src/main/java/org/apache/commons/vfs2/FileName.java
+++ b/commons-vfs2/src/main/java/org/apache/commons/vfs2/FileName.java
@@ -46,7 +46,7 @@
FileName[] EMPTY_ARRAY = new FileName[0];
/**
- * Returns the base name of this file. The base name is the last element of the file name. For example the base name
+ * Gets the base name of this file. The base name is the last element of the file name. For example the base name
* of {@code /somefolder/somefile} is {@code somefile}.
* <p>
* The root file of a file system has an empty base name.
@@ -57,7 +57,7 @@
String getBaseName();
/**
- * Returns the depth of this file name, within its file system. The depth of the root of a file system is 0. The
+ * Gets the depth of this file name, within its file system. The depth of the root of a file system is 0. The
* depth of any other file is 1 + the depth of its parent.
*
* @return The depth of this file name.
@@ -65,14 +65,14 @@
int getDepth();
/**
- * Returns the extension of this file name.
+ * Gets the extension of this file name.
*
* @return The extension. Returns an empty string if the name has no extension.
*/
String getExtension();
/**
- * Returns a "friendly path", this is a path without a password.
+ * Gets a "friendly path", this is a path without a password.
* <p>
* This path can not be used to resolve the path again.
* </p>
@@ -82,15 +82,15 @@
String getFriendlyURI();
/**
- * Returns the file name of the parent of this file. The root of a file system has no parent.
+ * Gets the file name of the parent of this file. The root of a file system has no parent.
*
* @return A {@link FileName} object representing the parent name. Returns null for the root of a file system.
*/
FileName getParent();
/**
- * Returns the absolute path of this file, within its file system. This path is normalized, so that {@code .} and
- * {@code ..} elements have been removed. Also, the path only contains {@code /} as its separator character. The
+ * Gets the absolute path string of this file, within its file system. This path is normalized, so that {@code .}
+ * and {@code ..} elements have been removed. Also, the path only contains {@code /} as its separator character. The
* path always starts with {@code /}
* <p>
* The root of a file system has {@code /} as its absolute path.
@@ -108,10 +108,11 @@
* The root of a file system has {@code /} as its absolute path.
* </p>
* <p>
- * In contrast to {@link #getPath()} the path is decoded i.e. all %nn stuff replaced by its character.
+ * In contrast to {@link #getPath()}, this path is decoded: All %nn escapes are replaced by their respective
+ * characters.
* </p>
*
- * @return The path. Never returns null.
+ * @return The decoded path. Never returns null.
* @throws FileSystemException if the path is not correctly encoded
*/
String getPathDecoded() throws FileSystemException;
@@ -126,28 +127,28 @@
String getRelativeName(FileName name) throws FileSystemException;
/**
- * Finds the root of the file system.
+ * Gets the root of the file system.
*
* @return the file system root.
*/
FileName getRoot();
/**
- * Returns the root URI of the file system this file belongs to.
+ * Gets the root URI string of the file system this file belongs to.
*
- * @return the root URI.
+ * @return the root URI string.
*/
String getRootURI();
/**
- * Returns the URI scheme of this file.
+ * Gets the URI scheme of this file.
*
* @return The URI scheme of this file.
*/
String getScheme();
/**
- * Returns the requested or current type of this name.
+ * Gets the requested or current type of this name.
* <p>
* The "requested" type is the one determined during resolving the name. In this case the name is a
* {@link FileType#FOLDER} if it ends with an "/" else it will be a {@link FileType#FILE}.
@@ -161,14 +162,14 @@
FileType getType();
/**
- * Returns the absolute URI of this file.
+ * Gets the absolute URI string of this file.
*
- * @return the absolute URI of this file.
+ * @return the absolute URI string of this file.
*/
String getURI();
/**
- * Determines if another file name is an ancestor of this file name.
+ * Tests if another file name is an ancestor of this file name.
*
* @param ancestor The FileName to check.
* @return true if another file name is an ancestor of this file name.
@@ -176,7 +177,7 @@
boolean isAncestor(FileName ancestor);
/**
- * Determines if another file name is a descendent of this file name.
+ * Tests if another file name is a descendent of this file name.
*
* @param descendent the FileName to check.
* @return true if the other FileName is a descendent of this file name.
@@ -184,7 +185,7 @@
boolean isDescendent(FileName descendent);
/**
- * Determines if another file name is a descendent of this file name.
+ * Tests if another file name is a descendent of this file name.
*
* @param descendent the FileName to check.
* @param nameScope the NameScope of the FileName.
@@ -193,7 +194,7 @@
boolean isDescendent(FileName descendent, NameScope nameScope);
/**
- * Checks if this file name is a name for a regular file.
+ * Tests if this file name is a name for a regular file.
*
* @return true if this file name is a name for a regular file.
* @throws FileSystemException if an error occurs.
diff --git a/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/local/DefaultLocalFileProvider.java b/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/local/DefaultLocalFileProvider.java
index ac18609..5c2dbe2 100644
--- a/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/local/DefaultLocalFileProvider.java
+++ b/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/local/DefaultLocalFileProvider.java
@@ -57,14 +57,27 @@
}
/**
- * Determines if a name is an absolute file name.
- *
- * @param name The file name.
- * @return true if the name is absolute, false otherwise.
+ * Creates the file system.
*/
@Override
- public boolean isAbsoluteLocalName(final String name) {
- return ((LocalFileNameParser) getFileNameParser()).isAbsoluteName(name);
+ protected FileSystem doCreateFileSystem(final FileName name, final FileSystemOptions fileSystemOptions)
+ throws FileSystemException {
+ // Create the file system
+ final LocalFileName rootName = (LocalFileName) name;
+ return new LocalFileSystem(rootName, rootName.getRootFile(), fileSystemOptions);
+ }
+
+ /**
+ * Finds a local file.
+ *
+ * @param file The File to locate.
+ * @return the located FileObject.
+ * @throws FileSystemException if an error occurs.
+ */
+ @Override
+ public FileObject findLocalFile(final File file) throws FileSystemException {
+ return findLocalFile(UriParser.encode(file.getAbsolutePath()));
+ // return findLocalFile(file.getAbsolutePath());
}
/**
@@ -84,32 +97,19 @@
return findFile(fileName, null);
}
- /**
- * Finds a local file.
- *
- * @param file The File to locate.
- * @return the located FileObject.
- * @throws FileSystemException if an error occurs.
- */
- @Override
- public FileObject findLocalFile(final File file) throws FileSystemException {
- return findLocalFile(UriParser.encode(file.getAbsolutePath()));
- // return findLocalFile(file.getAbsolutePath());
- }
-
- /**
- * Creates the file system.
- */
- @Override
- protected FileSystem doCreateFileSystem(final FileName name, final FileSystemOptions fileSystemOptions)
- throws FileSystemException {
- // Create the file system
- final LocalFileName rootName = (LocalFileName) name;
- return new LocalFileSystem(rootName, rootName.getRootFile(), fileSystemOptions);
- }
-
@Override
public Collection<Capability> getCapabilities() {
return capabilities;
}
+
+ /**
+ * Determines if a name is an absolute file name.
+ *
+ * @param name The file name.
+ * @return true if the name is absolute, false otherwise.
+ */
+ @Override
+ public boolean isAbsoluteLocalName(final String name) {
+ return ((LocalFileNameParser) getFileNameParser()).isAbsoluteName(name);
+ }
}
diff --git a/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/local/GenericFileNameParser.java b/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/local/GenericFileNameParser.java
index 2498f7f..519eb7a 100644
--- a/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/local/GenericFileNameParser.java
+++ b/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/local/GenericFileNameParser.java
@@ -29,16 +29,26 @@
private static final GenericFileNameParser INSTANCE = new GenericFileNameParser();
/**
- * retrieve a instance to this parser.
+ * Gets the singleton instance.
*
- * @return the parser
+ * @return the singleton instance.
*/
public static GenericFileNameParser getInstance() {
return INSTANCE;
}
+ /*
+ * ... this is why why need this: here the rootFilename can only be "/" (see above) put this "/" is also in the
+ * pathname so its of no value for the LocalFileName instance
+ */
+ @Override
+ protected FileName createFileName(final String scheme, final String rootFile, final String path,
+ final FileType type) {
+ return new LocalFileName(scheme, "", path, type);
+ }
+
/**
- * Pops the root prefix off a URI, which has had the scheme removed.
+ * Extracts the root prefix from a URI string, which has had the scheme removed.
*/
@Override
protected String extractRootPrefix(final String uri, final StringBuilder name) throws FileSystemException {
@@ -52,14 +62,4 @@
// do not strip the separator, BUT also return it ...
return "/";
}
-
- /*
- * ... this is why whe need this: here the rootFilename can only be "/" (see above) put this "/" is also in the
- * pathname so its of no value for the LocalFileName instance
- */
- @Override
- protected FileName createFileName(final String scheme, final String rootFile, final String path,
- final FileType type) {
- return new LocalFileName(scheme, "", path, type);
- }
}
diff --git a/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/local/LocalFile.java b/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/local/LocalFile.java
index 94eb6c2..d9f6c1d 100644
--- a/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/local/LocalFile.java
+++ b/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/local/LocalFile.java
@@ -199,14 +199,6 @@
}
/**
- * Determines if this file can be written to.
- */
- @Override
- protected boolean doIsWriteable() throws FileSystemException {
- return file.canWrite();
- }
-
- /**
* Determines if this file is a symbolic link.
* @since 2.4
*/
@@ -216,6 +208,14 @@
}
/**
+ * Determines if this file can be written to.
+ */
+ @Override
+ protected boolean doIsWriteable() throws FileSystemException {
+ return file.canWrite();
+ }
+
+ /**
* Returns the children of the file.
*/
@Override
diff --git a/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/local/LocalFileName.java b/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/local/LocalFileName.java
index fe479dd..ff86c02 100644
--- a/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/local/LocalFileName.java
+++ b/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/local/LocalFileName.java
@@ -35,12 +35,13 @@
}
/**
- * Returns the root file for this file.
- *
- * @return The root file name.
+ * Builds the root URI for this file name.
*/
- public String getRootFile() {
- return rootFile;
+ @Override
+ protected void appendRootUri(final StringBuilder buffer, final boolean addPassword) {
+ buffer.append(getScheme());
+ buffer.append("://");
+ buffer.append(rootFile);
}
/**
@@ -56,6 +57,15 @@
}
/**
+ * Returns the root file for this file.
+ *
+ * @return The root file name.
+ */
+ public String getRootFile() {
+ return rootFile;
+ }
+
+ /**
* Returns the decoded URI of the file.
*
* @return the FileName as a URI.
@@ -68,14 +78,4 @@
return super.getURI();
}
}
-
- /**
- * Builds the root URI for this file name.
- */
- @Override
- protected void appendRootUri(final StringBuilder buffer, final boolean addPassword) {
- buffer.append(getScheme());
- buffer.append("://");
- buffer.append(rootFile);
- }
}
diff --git a/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/local/LocalFileNameParser.java b/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/local/LocalFileNameParser.java
index 44c609c..b012932 100644
--- a/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/local/LocalFileNameParser.java
+++ b/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/local/LocalFileNameParser.java
@@ -30,6 +30,26 @@
*/
public abstract class LocalFileNameParser extends AbstractFileNameParser {
+ protected abstract FileName createFileName(String scheme, final String rootFile, final String path,
+ final FileType type);
+
+ /**
+ * Pops the root prefix off a URI, which has had the scheme removed.
+ *
+ * @param name the URI to modify.
+ * @param uri the whole URI for error reporting.
+ * @return the root prefix extracted.
+ * @throws FileSystemException if an error occurs.
+ */
+ protected abstract String extractRootPrefix(final String uri, final StringBuilder name) throws FileSystemException;
+
+ private String[] getSchemes(final VfsComponentContext context, final FileName base, final String uri) {
+ if (context == null) {
+ return new String[] { base != null ? base.getScheme() : URI.create(uri).getScheme() };
+ }
+ return context.getFileSystemManager().getSchemes();
+ }
+
/**
* Determines if a name is an absolute file name.
*
@@ -48,16 +68,6 @@
}
}
- /**
- * Pops the root prefix off a URI, which has had the scheme removed.
- *
- * @param name the URI to modify.
- * @param uri the whole URI for error reporting.
- * @return the root prefix extracted.
- * @throws FileSystemException if an error occurs.
- */
- protected abstract String extractRootPrefix(final String uri, final StringBuilder name) throws FileSystemException;
-
@Override
public FileName parseUri(final VfsComponentContext context, final FileName base, final String uri)
throws FileSystemException {
@@ -87,14 +97,4 @@
return createFileName(scheme, rootFile, path, fileType);
}
-
- private String[] getSchemes(final VfsComponentContext context, final FileName base, final String uri) {
- if (context == null) {
- return new String[] { base != null ? base.getScheme() : URI.create(uri).getScheme() };
- }
- return context.getFileSystemManager().getSchemes();
- }
-
- protected abstract FileName createFileName(String scheme, final String rootFile, final String path,
- final FileType type);
}
diff --git a/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/local/LocalFileRandomAccessContent.java b/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/local/LocalFileRandomAccessContent.java
index 3067377..edb353d 100644
--- a/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/local/LocalFileRandomAccessContent.java
+++ b/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/local/LocalFileRandomAccessContent.java
@@ -32,11 +32,11 @@
*/
final class LocalFileRandomAccessContent extends AbstractRandomAccessContent {
+ private final static int BYTE_VALUE_MASK = 0xFF;
// private final LocalFile localFile;
private final RandomAccessFile raf;
- private final InputStream rafis;
- private final static int BYTE_VALUE_MASK = 0xFF;
+ private final InputStream rafis;
LocalFileRandomAccessContent(final File localFile, final RandomAccessMode mode) throws FileSystemException {
super(mode);
@@ -45,6 +45,21 @@
raf = new RandomAccessFile(localFile, mode.getModeString());
rafis = new InputStream() {
@Override
+ public int available() throws IOException {
+ final long available = raf.length() - raf.getFilePointer();
+ if (available > Integer.MAX_VALUE) {
+ return Integer.MAX_VALUE;
+ }
+
+ return (int) available;
+ }
+
+ @Override
+ public void close() throws IOException {
+ raf.close();
+ }
+
+ @Override
public int read() throws IOException {
try {
return raf.readByte() & BYTE_VALUE_MASK;
@@ -54,17 +69,6 @@
}
@Override
- public long skip(final long n) throws IOException {
- raf.seek(raf.getFilePointer() + n);
- return n;
- }
-
- @Override
- public void close() throws IOException {
- raf.close();
- }
-
- @Override
public int read(final byte[] b) throws IOException {
return raf.read(b);
}
@@ -75,13 +79,9 @@
}
@Override
- public int available() throws IOException {
- final long available = raf.length() - raf.getFilePointer();
- if (available > Integer.MAX_VALUE) {
- return Integer.MAX_VALUE;
- }
-
- return (int) available;
+ public long skip(final long n) throws IOException {
+ raf.seek(raf.getFilePointer() + n);
+ return n;
}
};
} catch (final FileNotFoundException e) {
@@ -90,13 +90,18 @@
}
@Override
+ public void close() throws IOException {
+ raf.close();
+ }
+
+ @Override
public long getFilePointer() throws IOException {
return raf.getFilePointer();
}
@Override
- public void seek(final long pos) throws IOException {
- raf.seek(pos);
+ public InputStream getInputStream() throws IOException {
+ return rafis;
}
@Override
@@ -105,8 +110,8 @@
}
@Override
- public void close() throws IOException {
- raf.close();
+ public boolean readBoolean() throws IOException {
+ return raf.readBoolean();
}
@Override
@@ -130,21 +135,21 @@
}
@Override
+ public void readFully(final byte[] b) throws IOException {
+ raf.readFully(b);
+ }
+
+ @Override
+ public void readFully(final byte[] b, final int off, final int len) throws IOException {
+ raf.readFully(b, off, len);
+ }
+
+ @Override
public int readInt() throws IOException {
return raf.readInt();
}
@Override
- public int readUnsignedByte() throws IOException {
- return raf.readUnsignedByte();
- }
-
- @Override
- public int readUnsignedShort() throws IOException {
- return raf.readUnsignedShort();
- }
-
- @Override
public long readLong() throws IOException {
return raf.readLong();
}
@@ -155,23 +160,13 @@
}
@Override
- public boolean readBoolean() throws IOException {
- return raf.readBoolean();
+ public int readUnsignedByte() throws IOException {
+ return raf.readUnsignedByte();
}
@Override
- public int skipBytes(final int n) throws IOException {
- return raf.skipBytes(n);
- }
-
- @Override
- public void readFully(final byte[] b) throws IOException {
- raf.readFully(b);
- }
-
- @Override
- public void readFully(final byte[] b, final int off, final int len) throws IOException {
- raf.readFully(b, off, len);
+ public int readUnsignedShort() throws IOException {
+ return raf.readUnsignedShort();
}
@Override
@@ -180,48 +175,18 @@
}
@Override
- public void writeDouble(final double v) throws IOException {
- raf.writeDouble(v);
+ public void seek(final long pos) throws IOException {
+ raf.seek(pos);
}
@Override
- public void writeFloat(final float v) throws IOException {
- raf.writeFloat(v);
+ public void setLength(final long newLength) throws IOException {
+ raf.setLength(newLength);
}
@Override
- public void write(final int b) throws IOException {
- raf.write(b);
- }
-
- @Override
- public void writeByte(final int v) throws IOException {
- raf.writeByte(v);
- }
-
- @Override
- public void writeChar(final int v) throws IOException {
- raf.writeChar(v);
- }
-
- @Override
- public void writeInt(final int v) throws IOException {
- raf.writeInt(v);
- }
-
- @Override
- public void writeShort(final int v) throws IOException {
- raf.writeShort(v);
- }
-
- @Override
- public void writeLong(final long v) throws IOException {
- raf.writeLong(v);
- }
-
- @Override
- public void writeBoolean(final boolean v) throws IOException {
- raf.writeBoolean(v);
+ public int skipBytes(final int n) throws IOException {
+ return raf.skipBytes(n);
}
@Override
@@ -235,27 +200,62 @@
}
@Override
+ public void write(final int b) throws IOException {
+ raf.write(b);
+ }
+
+ @Override
+ public void writeBoolean(final boolean v) throws IOException {
+ raf.writeBoolean(v);
+ }
+
+ @Override
+ public void writeByte(final int v) throws IOException {
+ raf.writeByte(v);
+ }
+
+ @Override
public void writeBytes(final String s) throws IOException {
raf.writeBytes(s);
}
@Override
+ public void writeChar(final int v) throws IOException {
+ raf.writeChar(v);
+ }
+
+ @Override
public void writeChars(final String s) throws IOException {
raf.writeChars(s);
}
@Override
+ public void writeDouble(final double v) throws IOException {
+ raf.writeDouble(v);
+ }
+
+ @Override
+ public void writeFloat(final float v) throws IOException {
+ raf.writeFloat(v);
+ }
+
+ @Override
+ public void writeInt(final int v) throws IOException {
+ raf.writeInt(v);
+ }
+
+ @Override
+ public void writeLong(final long v) throws IOException {
+ raf.writeLong(v);
+ }
+
+ @Override
+ public void writeShort(final int v) throws IOException {
+ raf.writeShort(v);
+ }
+
+ @Override
public void writeUTF(final String str) throws IOException {
raf.writeUTF(str);
}
-
- @Override
- public InputStream getInputStream() throws IOException {
- return rafis;
- }
-
- @Override
- public void setLength(final long newLength) throws IOException {
- raf.setLength(newLength);
- }
}
diff --git a/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/local/LocalFileSystem.java b/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/local/LocalFileSystem.java
index 584e47d..9d1a8f4 100644
--- a/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/local/LocalFileSystem.java
+++ b/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/local/LocalFileSystem.java
@@ -43,6 +43,14 @@
}
/**
+ * Returns the capabilities of this file system.
+ */
+ @Override
+ protected void addCapabilities(final Collection<Capability> caps) {
+ caps.addAll(DefaultLocalFileProvider.capabilities);
+ }
+
+ /**
* Creates a file object.
*/
@Override
@@ -52,14 +60,6 @@
}
/**
- * Returns the capabilities of this file system.
- */
- @Override
- protected void addCapabilities(final Collection<Capability> caps) {
- caps.addAll(DefaultLocalFileProvider.capabilities);
- }
-
- /**
* Creates a temporary local copy of a file and its descendants.
*/
@Override
diff --git a/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/local/WindowsFileName.java b/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/local/WindowsFileName.java
index f35fbdb..e56f4ab 100644
--- a/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/local/WindowsFileName.java
+++ b/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/local/WindowsFileName.java
@@ -29,18 +29,6 @@
}
/**
- * Factory method for creating name instances.
- *
- * @param path The file path.
- * @param type The file type.
- * @return The FileName.
- */
- @Override
- public FileName createName(final String path, final FileType type) {
- return new WindowsFileName(getScheme(), getRootFile(), path, type);
- }
-
- /**
* Builds the root URI for this file name.
*/
@Override
@@ -53,4 +41,16 @@
}
buffer.append(getRootFile());
}
+
+ /**
+ * Factory method for creating name instances.
+ *
+ * @param path The file path.
+ * @param type The file type.
+ * @return The FileName.
+ */
+ @Override
+ public FileName createName(final String path, final FileType type) {
+ return new WindowsFileName(getScheme(), getRootFile(), path, type);
+ }
}
diff --git a/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/local/WindowsFileNameParser.java b/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/local/WindowsFileNameParser.java
index 5ab3da7..68a2939 100644
--- a/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/local/WindowsFileNameParser.java
+++ b/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/local/WindowsFileNameParser.java
@@ -25,6 +25,41 @@
*/
public class WindowsFileNameParser extends LocalFileNameParser {
+ @Override
+ protected FileName createFileName(final String scheme, final String rootFile, final String path,
+ final FileType type) {
+ return new WindowsFileName(scheme, rootFile, path, type);
+ }
+
+ /**
+ * Extracts a drive prefix from a path. Leading '/' chars have been removed.
+ */
+ private String extractDrivePrefix(final StringBuilder name) {
+ // Looking for <letter> ':' '/'
+ if (name.length() < 3) {
+ // Too short
+ return null;
+ }
+ final char ch = name.charAt(0);
+ if (ch == '/' || ch == ':') {
+ // Missing drive letter
+ return null;
+ }
+ if (name.charAt(1) != ':') {
+ // Missing ':'
+ return null;
+ }
+ if (name.charAt(2) != '/') {
+ // Missing separator
+ return null;
+ }
+
+ final String prefix = name.substring(0, 2);
+ name.delete(0, 2);
+
+ return prefix.intern();
+ }
+
/**
* Pops the root prefix off a URI, which has had the scheme removed.
*/
@@ -33,10 +68,34 @@
return extractWindowsRootPrefix(uri, name);
}
- @Override
- protected FileName createFileName(final String scheme, final String rootFile, final String path,
- final FileType type) {
- return new WindowsFileName(scheme, rootFile, path, type);
+ /**
+ * Extracts a UNC name from a path. Leading '/' chars have been removed.
+ */
+ private String extractUNCPrefix(final String uri, final StringBuilder name) throws FileSystemException {
+ // Looking for <name> '/' <name> ( '/' | <end> )
+
+ // Look for first separator
+ final int maxpos = name.length();
+ int pos = 0;
+ for (; pos < maxpos && name.charAt(pos) != '/'; pos++) {
+ }
+ pos++;
+ if (pos >= maxpos) {
+ throw new FileSystemException("vfs.provider.local/missing-share-name.error", uri);
+ }
+
+ // Now have <name> '/'
+ final int startShareName = pos;
+ for (; pos < maxpos && name.charAt(pos) != '/'; pos++) {
+ }
+ if (pos == startShareName) {
+ throw new FileSystemException("vfs.provider.local/missing-share-name.error", uri);
+ }
+
+ // Now have <name> '/' <name> ( '/' | <end> )
+ final String prefix = name.substring(0, pos);
+ name.delete(0, pos);
+ return prefix;
}
/**
@@ -71,63 +130,4 @@
return "//" + extractUNCPrefix(uri, name);
}
-
- /**
- * Extracts a drive prefix from a path. Leading '/' chars have been removed.
- */
- private String extractDrivePrefix(final StringBuilder name) {
- // Looking for <letter> ':' '/'
- if (name.length() < 3) {
- // Too short
- return null;
- }
- final char ch = name.charAt(0);
- if (ch == '/' || ch == ':') {
- // Missing drive letter
- return null;
- }
- if (name.charAt(1) != ':') {
- // Missing ':'
- return null;
- }
- if (name.charAt(2) != '/') {
- // Missing separator
- return null;
- }
-
- final String prefix = name.substring(0, 2);
- name.delete(0, 2);
-
- return prefix.intern();
- }
-
- /**
- * Extracts a UNC name from a path. Leading '/' chars have been removed.
- */
- private String extractUNCPrefix(final String uri, final StringBuilder name) throws FileSystemException {
- // Looking for <name> '/' <name> ( '/' | <end> )
-
- // Look for first separator
- final int maxpos = name.length();
- int pos = 0;
- for (; pos < maxpos && name.charAt(pos) != '/'; pos++) {
- }
- pos++;
- if (pos >= maxpos) {
- throw new FileSystemException("vfs.provider.local/missing-share-name.error", uri);
- }
-
- // Now have <name> '/'
- final int startShareName = pos;
- for (; pos < maxpos && name.charAt(pos) != '/'; pos++) {
- }
- if (pos == startShareName) {
- throw new FileSystemException("vfs.provider.local/missing-share-name.error", uri);
- }
-
- // Now have <name> '/' <name> ( '/' | <end> )
- final String prefix = name.substring(0, pos);
- name.delete(0, pos);
- return prefix;
- }
}
diff --git a/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/url/UrlFileNameParser.java b/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/url/UrlFileNameParser.java
index fe8c3ba..20d8ce1 100644
--- a/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/url/UrlFileNameParser.java
+++ b/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/url/UrlFileNameParser.java
@@ -31,8 +31,8 @@
*/
public class UrlFileNameParser extends AbstractFileNameParser {
- private final URLFileNameParser url = new URLFileNameParser(80);
- private final GenericFileNameParser generic = new GenericFileNameParser();
+ private final URLFileNameParser urlFileNameParser = new URLFileNameParser(80);
+ private final GenericFileNameParser genericFileNameParser = new GenericFileNameParser();
public UrlFileNameParser() {
}
@@ -55,14 +55,14 @@
public FileName parseUri(final VfsComponentContext context, final FileName base, final String uri)
throws FileSystemException {
if (isUrlBased(base, uri)) {
- return url.parseUri(context, base, uri);
+ return urlFileNameParser.parseUri(context, base, uri);
}
- return generic.parseUri(context, base, uri);
+ return genericFileNameParser.parseUri(context, base, uri);
}
/**
- * Guess if the given file name is an URL with host or not.
+ * Guess if the given file name is a URL with host or not.
* <p>
* VFS treats such URLs differently.
* </p>
diff --git a/commons-vfs2/src/test/java/org/apache/commons/vfs2/provider/url/UrlFileNameParserTest.java b/commons-vfs2/src/test/java/org/apache/commons/vfs2/provider/url/UrlFileNameParserTest.java
index 6baadda..d99faf6 100644
--- a/commons-vfs2/src/test/java/org/apache/commons/vfs2/provider/url/UrlFileNameParserTest.java
+++ b/commons-vfs2/src/test/java/org/apache/commons/vfs2/provider/url/UrlFileNameParserTest.java
@@ -25,9 +25,7 @@
public class UrlFileNameParserTest {
- @Test
- public void testJira739() throws Exception {
- final String uriStr = "maprfs:///";
+ private void testJira739(final String uriStr) throws Exception {
// Check that we have a valid URI
final URI uri = new URI(uriStr);
// VFS-739 shows that parseUri throws an NPE:
@@ -35,4 +33,19 @@
Assert.assertEquals(uriStr, fileName.getURI());
Assert.assertEquals(uri.getScheme(), fileName.getScheme());
}
+
+ @Test
+ public void testJira739_scheme_file() throws Exception {
+ testJira739("file:///");
+ }
+
+ @Test
+ public void testJira739_scheme_maprfs() throws Exception {
+ testJira739("maprfs:///");
+ }
+
+ @Test
+ public void testJira739_scheme_ram() throws Exception {
+ testJira739("ram:///");
+ }
}
diff --git a/commons-vfs2/src/test/resources/test-data/1 1.txt b/commons-vfs2/src/test/resources/test-data/1 1.txt
new file mode 100644
index 0000000..7c4a013
--- /dev/null
+++ b/commons-vfs2/src/test/resources/test-data/1 1.txt
@@ -0,0 +1 @@
+aaa
\ No newline at end of file
diff --git "a/commons-vfs2/src/test/resources/test-data/\345\245\275.txt" "b/commons-vfs2/src/test/resources/test-data/\345\245\275.txt"
new file mode 100644
index 0000000..7c4a013
--- /dev/null
+++ "b/commons-vfs2/src/test/resources/test-data/\345\245\275.txt"
@@ -0,0 +1 @@
+aaa
\ No newline at end of file