This is an automated email from the ASF dual-hosted git repository. ggregory pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/commons-vfs.git
commit 923190f961d1db1ac633c59c319c0dcd2f902011 Author: Gary Gregory <[email protected]> AuthorDate: Tue Mar 23 09:04:21 2021 -0400 Sort members. --- .../provider/local/DefaultLocalFileProvider.java | 52 ++++---- .../vfs2/provider/local/GenericFileNameParser.java | 20 +-- .../commons/vfs2/provider/local/LocalFile.java | 14 +- .../commons/vfs2/provider/local/LocalFileName.java | 30 ++--- .../vfs2/provider/local/LocalFileNameParser.java | 40 +++--- .../local/LocalFileRandomAccessContent.java | 146 ++++++++++----------- .../vfs2/provider/local/LocalFileSystem.java | 14 +- .../vfs2/provider/local/WindowsFileName.java | 24 ++-- .../vfs2/provider/local/WindowsFileNameParser.java | 82 ++++++------ 9 files changed, 211 insertions(+), 211 deletions(-) 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 @@ public class DefaultLocalFileProvider extends AbstractOriginatingFileProvider im } /** - * Determines if a name is an absolute file name. + * 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); + } + + /** + * Finds a local file. * - * @param name The file name. - * @return true if the name is absolute, false otherwise. + * @param file The File to locate. + * @return the located FileObject. + * @throws FileSystemException if an error occurs. */ @Override - public boolean isAbsoluteLocalName(final String name) { - return ((LocalFileNameParser) getFileNameParser()).isAbsoluteName(name); + public FileObject findLocalFile(final File file) throws FileSystemException { + return findLocalFile(UriParser.encode(file.getAbsolutePath())); + // return findLocalFile(file.getAbsolutePath()); } /** @@ -84,32 +97,19 @@ public class DefaultLocalFileProvider extends AbstractOriginatingFileProvider im 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()); + public Collection<Capability> getCapabilities() { + return capabilities; } /** - * Creates the file system. + * Determines if a name is an absolute file name. + * + * @param name The file name. + * @return true if the name is absolute, false otherwise. */ @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; + 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..3cdf9d9 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 @@ -37,6 +37,16 @@ public class GenericFileNameParser extends LocalFileNameParser { return INSTANCE; } + /* + * ... 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); + } + /** * Pops the root prefix off a URI, which has had the scheme removed. */ @@ -52,14 +62,4 @@ public class GenericFileNameParser extends LocalFileNameParser { // 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,20 +199,20 @@ public class LocalFile extends AbstractFileObject<LocalFileSystem> { } /** - * Determines if this file can be written to. + * Determines if this file is a symbolic link. + * @since 2.4 */ @Override - protected boolean doIsWriteable() throws FileSystemException { - return file.canWrite(); + protected boolean doIsSymbolicLink() throws FileSystemException { + return Files.isSymbolicLink(file.toPath()); } /** - * Determines if this file is a symbolic link. - * @since 2.4 + * Determines if this file can be written to. */ @Override - protected boolean doIsSymbolicLink() throws FileSystemException { - return Files.isSymbolicLink(file.toPath()); + protected boolean doIsWriteable() throws FileSystemException { + return file.canWrite(); } /** 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 @@ public class LocalFileName extends AbstractFileName { } /** - * 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 @@ public class LocalFileName extends AbstractFileName { } /** + * 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 @@ public class LocalFileName extends AbstractFileName { 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 @@ import org.apache.commons.vfs2.provider.VfsComponentContext; */ 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 @@ public abstract class LocalFileNameParser extends AbstractFileNameParser { } } - /** - * 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 @@ public abstract class LocalFileNameParser extends AbstractFileNameParser { 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 @@ import org.apache.commons.vfs2.util.RandomAccessMode; */ 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,18 +45,13 @@ final class LocalFileRandomAccessContent extends AbstractRandomAccessContent { raf = new RandomAccessFile(localFile, mode.getModeString()); rafis = new InputStream() { @Override - public int read() throws IOException { - try { - return raf.readByte() & BYTE_VALUE_MASK; - } catch (final EOFException e) { - return -1; + public int available() throws IOException { + final long available = raf.length() - raf.getFilePointer(); + if (available > Integer.MAX_VALUE) { + return Integer.MAX_VALUE; } - } - @Override - public long skip(final long n) throws IOException { - raf.seek(raf.getFilePointer() + n); - return n; + return (int) available; } @Override @@ -65,6 +60,15 @@ final class LocalFileRandomAccessContent extends AbstractRandomAccessContent { } @Override + public int read() throws IOException { + try { + return raf.readByte() & BYTE_VALUE_MASK; + } catch (final EOFException e) { + return -1; + } + } + + @Override public int read(final byte[] b) throws IOException { return raf.read(b); } @@ -75,13 +79,9 @@ final class LocalFileRandomAccessContent extends AbstractRandomAccessContent { } @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 @@ final class LocalFileRandomAccessContent extends AbstractRandomAccessContent { } @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 @@ final class LocalFileRandomAccessContent extends AbstractRandomAccessContent { } @Override - public void close() throws IOException { - raf.close(); + public boolean readBoolean() throws IOException { + return raf.readBoolean(); } @Override @@ -130,18 +135,18 @@ final class LocalFileRandomAccessContent extends AbstractRandomAccessContent { } @Override - public int readInt() throws IOException { - return raf.readInt(); + public void readFully(final byte[] b) throws IOException { + raf.readFully(b); } @Override - public int readUnsignedByte() throws IOException { - return raf.readUnsignedByte(); + public void readFully(final byte[] b, final int off, final int len) throws IOException { + raf.readFully(b, off, len); } @Override - public int readUnsignedShort() throws IOException { - return raf.readUnsignedShort(); + public int readInt() throws IOException { + return raf.readInt(); } @Override @@ -155,107 +160,102 @@ final class LocalFileRandomAccessContent extends AbstractRandomAccessContent { } @Override - public boolean readBoolean() throws IOException { - return raf.readBoolean(); - } - - @Override - public int skipBytes(final int n) throws IOException { - return raf.skipBytes(n); + public int readUnsignedByte() throws IOException { + return raf.readUnsignedByte(); } @Override - public void readFully(final byte[] b) throws IOException { - raf.readFully(b); + public int readUnsignedShort() throws IOException { + return raf.readUnsignedShort(); } @Override - public void readFully(final byte[] b, final int off, final int len) throws IOException { - raf.readFully(b, off, len); + public String readUTF() throws IOException { + return raf.readUTF(); } @Override - public String readUTF() throws IOException { - return raf.readUTF(); + public void seek(final long pos) throws IOException { + raf.seek(pos); } @Override - public void writeDouble(final double v) throws IOException { - raf.writeDouble(v); + public void setLength(final long newLength) throws IOException { + raf.setLength(newLength); } @Override - public void writeFloat(final float v) throws IOException { - raf.writeFloat(v); + public int skipBytes(final int n) throws IOException { + return raf.skipBytes(n); } @Override - public void write(final int b) throws IOException { + public void write(final byte[] b) throws IOException { raf.write(b); } @Override - public void writeByte(final int v) throws IOException { - raf.writeByte(v); + public void write(final byte[] b, final int off, final int len) throws IOException { + raf.write(b, off, len); } @Override - public void writeChar(final int v) throws IOException { - raf.writeChar(v); + public void write(final int b) throws IOException { + raf.write(b); } @Override - public void writeInt(final int v) throws IOException { - raf.writeInt(v); + public void writeBoolean(final boolean v) throws IOException { + raf.writeBoolean(v); } @Override - public void writeShort(final int v) throws IOException { - raf.writeShort(v); + public void writeByte(final int v) throws IOException { + raf.writeByte(v); } @Override - public void writeLong(final long v) throws IOException { - raf.writeLong(v); + public void writeBytes(final String s) throws IOException { + raf.writeBytes(s); } @Override - public void writeBoolean(final boolean v) throws IOException { - raf.writeBoolean(v); + public void writeChar(final int v) throws IOException { + raf.writeChar(v); } @Override - public void write(final byte[] b) throws IOException { - raf.write(b); + public void writeChars(final String s) throws IOException { + raf.writeChars(s); } @Override - public void write(final byte[] b, final int off, final int len) throws IOException { - raf.write(b, off, len); + public void writeDouble(final double v) throws IOException { + raf.writeDouble(v); } @Override - public void writeBytes(final String s) throws IOException { - raf.writeBytes(s); + public void writeFloat(final float v) throws IOException { + raf.writeFloat(v); } @Override - public void writeChars(final String s) throws IOException { - raf.writeChars(s); + public void writeInt(final int v) throws IOException { + raf.writeInt(v); } @Override - public void writeUTF(final String str) throws IOException { - raf.writeUTF(str); + public void writeLong(final long v) throws IOException { + raf.writeLong(v); } @Override - public InputStream getInputStream() throws IOException { - return rafis; + public void writeShort(final int v) throws IOException { + raf.writeShort(v); } @Override - public void setLength(final long newLength) throws IOException { - raf.setLength(newLength); + public void writeUTF(final String str) throws IOException { + raf.writeUTF(str); } } 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,20 +43,20 @@ public class LocalFileSystem extends AbstractFileSystem { } /** - * Creates a file object. + * Returns the capabilities of this file system. */ @Override - protected FileObject createFile(final AbstractFileName name) throws FileSystemException { - // Create the file - return new LocalFile(this, rootFile, name); + protected void addCapabilities(final Collection<Capability> caps) { + caps.addAll(DefaultLocalFileProvider.capabilities); } /** - * Returns the capabilities of this file system. + * Creates a file object. */ @Override - protected void addCapabilities(final Collection<Capability> caps) { - caps.addAll(DefaultLocalFileProvider.capabilities); + protected FileObject createFile(final AbstractFileName name) throws FileSystemException { + // Create the file + return new LocalFile(this, rootFile, name); } /** 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 @@ public class WindowsFileName extends LocalFileName { } /** - * 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 @@ public class WindowsFileName extends LocalFileName { } 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,14 +25,6 @@ import org.apache.commons.vfs2.FileType; */ public class WindowsFileNameParser extends LocalFileNameParser { - /** - * Pops the root prefix off a URI, which has had the scheme removed. - */ - @Override - protected String extractRootPrefix(final String uri, final StringBuilder name) throws FileSystemException { - return extractWindowsRootPrefix(uri, name); - } - @Override protected FileName createFileName(final String scheme, final String rootFile, final String path, final FileType type) { @@ -40,39 +32,6 @@ public class WindowsFileNameParser extends LocalFileNameParser { } /** - * Extracts a Windows root prefix from a name. - */ - private String extractWindowsRootPrefix(final String uri, final StringBuilder name) throws FileSystemException { - // Looking for: - // ('/'){0, 3} <letter> ':' '/' - // ['/'] '//' <name> '/' <name> ( '/' | <end> ) - - // Skip over first 4 (unc) leading '/' chars - int startPos = 0; - final int maxlen = Math.min(4, name.length()); - for (; startPos < maxlen && name.charAt(startPos) == '/'; startPos++) { - } - if (startPos == maxlen && name.length() > (startPos + 1) && name.charAt(startPos + 1) == '/') { - // Too many '/' - throw new FileSystemException("vfs.provider.local/not-absolute-file-name.error", uri); - } - name.delete(0, startPos); - - // Look for drive name - final String driveName = extractDrivePrefix(name); - if (driveName != null) { - return driveName; - } - - // Look for UNC name - if (startPos < 2) { - throw new FileSystemException("vfs.provider.local/not-absolute-file-name.error", uri); - } - - return "//" + extractUNCPrefix(uri, name); - } - - /** * Extracts a drive prefix from a path. Leading '/' chars have been removed. */ private String extractDrivePrefix(final StringBuilder name) { @@ -102,6 +61,14 @@ public class WindowsFileNameParser extends LocalFileNameParser { } /** + * Pops the root prefix off a URI, which has had the scheme removed. + */ + @Override + protected String extractRootPrefix(final String uri, final StringBuilder name) throws FileSystemException { + return extractWindowsRootPrefix(uri, name); + } + + /** * Extracts a UNC name from a path. Leading '/' chars have been removed. */ private String extractUNCPrefix(final String uri, final StringBuilder name) throws FileSystemException { @@ -130,4 +97,37 @@ public class WindowsFileNameParser extends LocalFileNameParser { name.delete(0, pos); return prefix; } + + /** + * Extracts a Windows root prefix from a name. + */ + private String extractWindowsRootPrefix(final String uri, final StringBuilder name) throws FileSystemException { + // Looking for: + // ('/'){0, 3} <letter> ':' '/' + // ['/'] '//' <name> '/' <name> ( '/' | <end> ) + + // Skip over first 4 (unc) leading '/' chars + int startPos = 0; + final int maxlen = Math.min(4, name.length()); + for (; startPos < maxlen && name.charAt(startPos) == '/'; startPos++) { + } + if (startPos == maxlen && name.length() > (startPos + 1) && name.charAt(startPos + 1) == '/') { + // Too many '/' + throw new FileSystemException("vfs.provider.local/not-absolute-file-name.error", uri); + } + name.delete(0, startPos); + + // Look for drive name + final String driveName = extractDrivePrefix(name); + if (driveName != null) { + return driveName; + } + + // Look for UNC name + if (startPos < 2) { + throw new FileSystemException("vfs.provider.local/not-absolute-file-name.error", uri); + } + + return "//" + extractUNCPrefix(uri, name); + } }
