Modified: commons/proper/vfs/trunk/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/LocalFileProvider.java URL: http://svn.apache.org/viewvc/commons/proper/vfs/trunk/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/LocalFileProvider.java?rev=1808381&r1=1808380&r2=1808381&view=diff ============================================================================== --- commons/proper/vfs/trunk/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/LocalFileProvider.java (original) +++ commons/proper/vfs/trunk/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/LocalFileProvider.java Thu Sep 14 19:26:39 2017 @@ -24,9 +24,7 @@ import org.apache.commons.vfs2.FileSyste /** * A file provider which handles local files. */ -public interface LocalFileProvider - extends FileProvider -{ +public interface LocalFileProvider extends FileProvider { /** * Determines if a name is an absolute file name. * <p> @@ -39,19 +37,19 @@ public interface LocalFileProvider /** * Finds a local file, from its local name. + * * @param name The name of the file to locate. * @return The FileObject for the file. * @throws FileSystemException if an error occurs. */ - FileObject findLocalFile(final String name) - throws FileSystemException; + FileObject findLocalFile(final String name) throws FileSystemException; /** * Converts from java.io.File to FileObject. + * * @param file The File for the file. * @return The FileObject for the file. * @throws FileSystemException if an error occurs. */ - FileObject findLocalFile(final File file) - throws FileSystemException; + FileObject findLocalFile(final File file) throws FileSystemException; }
Modified: commons/proper/vfs/trunk/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/TemporaryFileStore.java URL: http://svn.apache.org/viewvc/commons/proper/vfs/trunk/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/TemporaryFileStore.java?rev=1808381&r1=1808380&r2=1808381&view=diff ============================================================================== --- commons/proper/vfs/trunk/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/TemporaryFileStore.java (original) +++ commons/proper/vfs/trunk/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/TemporaryFileStore.java Thu Sep 14 19:26:39 2017 @@ -23,11 +23,9 @@ import org.apache.commons.vfs2.FileSyste /** * Manages a repository of temporary local files. */ -public interface TemporaryFileStore -{ +public interface TemporaryFileStore { /** - * Allocates a new temporary file. The file (and all its descendants) - * will be deleted when this store is closed. + * Allocates a new temporary file. The file (and all its descendants) will be deleted when this store is closed. * * @param basename The name of the file. * @return The temporary file. Modified: commons/proper/vfs/trunk/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/URLFileName.java URL: http://svn.apache.org/viewvc/commons/proper/vfs/trunk/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/URLFileName.java?rev=1808381&r1=1808380&r2=1808381&view=diff ============================================================================== --- commons/proper/vfs/trunk/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/URLFileName.java (original) +++ commons/proper/vfs/trunk/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/URLFileName.java Thu Sep 14 19:26:39 2017 @@ -25,22 +25,14 @@ import org.apache.commons.vfs2.FileType; /** * A file name that represents URL. */ -public class URLFileName extends GenericFileName -{ +public class URLFileName extends GenericFileName { private static final int BUFFER_SIZE = 250; private final String queryString; - public URLFileName(final String scheme, - final String hostName, - final int port, - final int defaultPort, - final String userName, - final String password, - final String path, - final FileType type, - final String queryString) - { + public URLFileName(final String scheme, final String hostName, final int port, final int defaultPort, + final String userName, final String password, final String path, final FileType type, + final String queryString) { super(scheme, hostName, port, defaultPort, userName, password, path, type); this.queryString = queryString; } @@ -50,8 +42,7 @@ public class URLFileName extends Generic * * @return the query string part of the filename */ - public String getQueryString() - { + public String getQueryString() { return queryString; } @@ -60,8 +51,7 @@ public class URLFileName extends Generic * * @return the path and its query string */ - public String getPathQuery() - { + public String getPathQuery() { final StringBuilder sb = new StringBuilder(BUFFER_SIZE); sb.append(getPath()); sb.append("?"); @@ -78,24 +68,18 @@ public class URLFileName extends Generic * @throws URIException If an error occurs encoding the URI. * @throws FileSystemException If some other error occurs. */ - public String getPathQueryEncoded(final String charset) throws URIException, FileSystemException - { - if (getQueryString() == null) - { - if (charset != null) - { + public String getPathQueryEncoded(final String charset) throws URIException, FileSystemException { + if (getQueryString() == null) { + if (charset != null) { return URIUtil.encodePath(getPathDecoded(), charset); } return URIUtil.encodePath(getPathDecoded()); } final StringBuilder sb = new StringBuilder(BUFFER_SIZE); - if (charset != null) - { + if (charset != null) { sb.append(URIUtil.encodePath(getPathDecoded(), charset)); - } - else - { + } else { sb.append(URIUtil.encodePath(getPathDecoded())); } sb.append("?"); @@ -105,22 +89,15 @@ public class URLFileName extends Generic /** * Create a FileName. + * * @param absPath The absolute path. * @param type The FileType. * @return The FileName */ @Override - public FileName createName(final String absPath, final FileType type) - { - return new URLFileName(getScheme(), - getHostName(), - getPort(), - getDefaultPort(), - getUserName(), - getPassword(), - absPath, - type, - getQueryString()); + public FileName createName(final String absPath, final FileType type) { + return new URLFileName(getScheme(), getHostName(), getPort(), getDefaultPort(), getUserName(), getPassword(), + absPath, type, getQueryString()); } /** @@ -129,10 +106,8 @@ public class URLFileName extends Generic * @return the uri */ @Override - protected String createURI() - { - if (getQueryString() != null) - { + protected String createURI() { + if (getQueryString() != null) { final StringBuilder sb = new StringBuilder(BUFFER_SIZE); sb.append(super.createURI()); sb.append("?"); @@ -146,13 +121,13 @@ public class URLFileName extends Generic /** * Encode a URI. + * * @param charset The character set. * @return The encoded URI * @throws FileSystemException if some other exception occurs. * @throws URIException if an exception occurs encoding the URI. */ - public String getURIEncoded(final String charset) throws FileSystemException, URIException - { + public String getURIEncoded(final String charset) throws FileSystemException, URIException { final StringBuilder sb = new StringBuilder(BUFFER_SIZE); appendRootUri(sb, true); sb.append(getPathQueryEncoded(charset)); Modified: commons/proper/vfs/trunk/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/URLFileNameParser.java URL: http://svn.apache.org/viewvc/commons/proper/vfs/trunk/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/URLFileNameParser.java?rev=1808381&r1=1808380&r2=1808381&view=diff ============================================================================== --- commons/proper/vfs/trunk/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/URLFileNameParser.java (original) +++ commons/proper/vfs/trunk/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/URLFileNameParser.java Thu Sep 14 19:26:39 2017 @@ -25,23 +25,19 @@ import org.apache.commons.vfs2.FileType; * <p> * Parses the url into user/password/host/port/path/queryString. */ -public class URLFileNameParser extends HostFileNameParser -{ - public URLFileNameParser(final int defaultPort) - { +public class URLFileNameParser extends HostFileNameParser { + public URLFileNameParser(final int defaultPort) { super(defaultPort); } @Override - public boolean encodeCharacter(final char ch) - { + public boolean encodeCharacter(final char ch) { return super.encodeCharacter(ch) || ch == '?'; } @Override public FileName parseUri(final VfsComponentContext context, final FileName base, final String filename) - throws FileSystemException - { + throws FileSystemException { // FTP URI are generic URI (as per RFC 2396) final StringBuilder name = new StringBuilder(); @@ -57,15 +53,7 @@ public class URLFileNameParser extends H final FileType fileType = UriParser.normalisePath(name); final String path = name.toString(); - return new URLFileName( - auth.getScheme(), - auth.getHostName(), - auth.getPort(), - getDefaultPort(), - auth.getUserName(), - auth.getPassword(), - path, - fileType, - queryString); + return new URLFileName(auth.getScheme(), auth.getHostName(), auth.getPort(), getDefaultPort(), + auth.getUserName(), auth.getPassword(), path, fileType, queryString); } } Modified: commons/proper/vfs/trunk/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/UriParser.java URL: http://svn.apache.org/viewvc/commons/proper/vfs/trunk/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/UriParser.java?rev=1808381&r1=1808380&r2=1808381&view=diff ============================================================================== --- commons/proper/vfs/trunk/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/UriParser.java (original) +++ commons/proper/vfs/trunk/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/UriParser.java Thu Sep 14 19:26:39 2017 @@ -25,13 +25,12 @@ import org.apache.commons.vfs2.util.Os; /** * Utilities for dealing with URIs. See RFC 2396 for details. * - * 2005) $ + * 2005) $ */ -public final class UriParser -{ +public final class UriParser { /** - * The set of valid separators. These are all converted to the normalized - * one. Does <i>not</i> contain the normalized separator + * The set of valid separators. These are all converted to the normalized one. Does <i>not</i> contain the + * normalized separator */ // public static final char[] separators = {'\\'}; public static final char TRANS_SEPARATOR = '\\'; @@ -47,31 +46,26 @@ public final class UriParser private static final char LOW_MASK = 0x0F; - private UriParser() - { + private UriParser() { } /** * Extracts the first element of a path. + * * @param name StringBuilder containing the path. * @return The first element of the path. */ - public static String extractFirstElement(final StringBuilder name) - { + public static String extractFirstElement(final StringBuilder name) { final int len = name.length(); - if (len < 1) - { + if (len < 1) { return null; } int startPos = 0; - if (name.charAt(0) == SEPARATOR_CHAR) - { + if (name.charAt(0) == SEPARATOR_CHAR) { startPos = 1; } - for (int pos = startPos; pos < len; pos++) - { - if (name.charAt(pos) == SEPARATOR_CHAR) - { + for (int pos = startPos; pos < len; pos++) { + if (name.charAt(pos) == SEPARATOR_CHAR) { // Found a separator final String elem = name.substring(startPos, pos); name.delete(startPos, pos + 1); @@ -99,19 +93,15 @@ public final class UriParser * @return The FileType. * @throws FileSystemException if an error occurs. * - * @see #fixSeparators + * @see #fixSeparators */ - public static FileType normalisePath(final StringBuilder path) - throws FileSystemException - { + public static FileType normalisePath(final StringBuilder path) throws FileSystemException { FileType fileType = FileType.FOLDER; - if (path.length() == 0) - { + if (path.length() == 0) { return fileType; } - if (path.charAt(path.length() - 1) != '/') - { + if (path.charAt(path.length() - 1) != '/') { fileType = FileType.FILE; } @@ -120,10 +110,8 @@ public final class UriParser // Determine the start of the first element int startFirstElem = 0; - if (path.charAt(0) == SEPARATOR_CHAR) - { - if (path.length() == 1) - { + if (path.charAt(0) == SEPARATOR_CHAR) { + if (path.length() == 1) { return fileType; } startFirstElem = 1; @@ -132,44 +120,35 @@ public final class UriParser // Iterate over each element int startElem = startFirstElem; int maxlen = path.length(); - while (startElem < maxlen) - { + while (startElem < maxlen) { // Find the end of the element int endElem = startElem; - for (; endElem < maxlen && path.charAt(endElem) != SEPARATOR_CHAR; endElem++) - { + for (; endElem < maxlen && path.charAt(endElem) != SEPARATOR_CHAR; endElem++) { } final int elemLen = endElem - startElem; - if (elemLen == 0) - { + if (elemLen == 0) { // An empty element - axe it path.delete(endElem, endElem + 1); maxlen = path.length(); continue; } - if (elemLen == 1 && path.charAt(startElem) == '.') - { + if (elemLen == 1 && path.charAt(startElem) == '.') { // A '.' element - axe it path.delete(startElem, endElem + 1); maxlen = path.length(); continue; } - if (elemLen == 2 && path.charAt(startElem) == '.' - && path.charAt(startElem + 1) == '.') - { + if (elemLen == 2 && path.charAt(startElem) == '.' && path.charAt(startElem + 1) == '.') { // A '..' element - remove the previous element - if (startElem == startFirstElem) - { + if (startElem == startFirstElem) { // Previous element is missing - throw new FileSystemException( - "vfs.provider/invalid-relative-path.error"); + throw new FileSystemException("vfs.provider/invalid-relative-path.error"); } // Find start of previous element int pos = startElem - 2; - for (; pos >= 0 && path.charAt(pos) != SEPARATOR_CHAR; pos--) - { + for (; pos >= 0 && path.charAt(pos) != SEPARATOR_CHAR; pos--) { } startElem = pos + 1; @@ -183,8 +162,7 @@ public final class UriParser } // Remove trailing separator - if (!VFS.isUriStyle() && maxlen > 1 && path.charAt(maxlen - 1) == SEPARATOR_CHAR) - { + if (!VFS.isUriStyle() && maxlen > 1 && path.charAt(maxlen - 1) == SEPARATOR_CHAR) { path.delete(maxlen - 1, maxlen); } @@ -193,18 +171,16 @@ public final class UriParser /** * Normalises the separators in a name. + * * @param name The StringBuilder containing the name * @return true if the StringBuilder was modified. */ - public static boolean fixSeparators(final StringBuilder name) - { + public static boolean fixSeparators(final StringBuilder name) { boolean changed = false; final int maxlen = name.length(); - for (int i = 0; i < maxlen; i++) - { + for (int i = 0; i < maxlen; i++) { final char ch = name.charAt(i); - if (ch == TRANS_SEPARATOR) - { + if (ch == TRANS_SEPARATOR) { name.setCharAt(i, SEPARATOR_CHAR); changed = true; } @@ -218,56 +194,45 @@ public final class UriParser * @param uri The URI. * @return The scheme name. Returns null if there is no scheme. */ - public static String extractScheme(final String uri) - { + public static String extractScheme(final String uri) { return extractScheme(uri, null); } /** - * Extracts the scheme from a URI. Removes the scheme and ':' delimiter from - * the front of the URI. + * Extracts the scheme from a URI. Removes the scheme and ':' delimiter from the front of the URI. * * @param uri The URI. * @param buffer Returns the remainder of the URI. * @return The scheme name. Returns null if there is no scheme. */ - public static String extractScheme(final String uri, final StringBuilder buffer) - { - if (buffer != null) - { + public static String extractScheme(final String uri, final StringBuilder buffer) { + if (buffer != null) { buffer.setLength(0); buffer.append(uri); } final int maxPos = uri.length(); - for (int pos = 0; pos < maxPos; pos++) - { + for (int pos = 0; pos < maxPos; pos++) { final char ch = uri.charAt(pos); - if (ch == ':') - { + if (ch == ':') { // Found the end of the scheme final String scheme = uri.substring(0, pos); - if (scheme.length() <= 1 && Os.isFamily(Os.OS_FAMILY_WINDOWS)) - { + if (scheme.length() <= 1 && Os.isFamily(Os.OS_FAMILY_WINDOWS)) { // This is not a scheme, but a Windows drive letter return null; } - if (buffer != null) - { + if (buffer != null) { buffer.delete(0, pos + 1); } return scheme.intern(); } - if ((ch >= 'a' && ch <= 'z') || (ch >= 'A' && ch <= 'Z')) - { + if ((ch >= 'a' && ch <= 'z') || (ch >= 'A' && ch <= 'Z')) { // A scheme character continue; } - if (pos > 0 - && ((ch >= '0' && ch <= '9') || ch == '+' || ch == '-' || ch == '.')) - { + if (pos > 0 && ((ch >= '0' && ch <= '9') || ch == '+' || ch == '-' || ch == '.')) { // A scheme character (these are not allowed as the first // character of the scheme, but can be used as subsequent // characters. @@ -284,19 +249,16 @@ public final class UriParser /** * Removes %nn encodings from a string. + * * @param encodedStr The encoded String. * @return The decoded String. * @throws FileSystemException if an error occurs. */ - public static String decode(final String encodedStr) - throws FileSystemException - { - if (encodedStr == null) - { + public static String decode(final String encodedStr) throws FileSystemException { + if (encodedStr == null) { return null; } - if (encodedStr.indexOf('%') < 0) - { + if (encodedStr.indexOf('%') < 0) { return encodedStr; } final StringBuilder buffer = new StringBuilder(encodedStr); @@ -306,38 +268,32 @@ public final class UriParser /** * Removes %nn encodings from a string. + * * @param buffer StringBuilder containing the string to decode. * @param offset The position in the string to start decoding. * @param length The number of characters to decode. * @throws FileSystemException if an error occurs. */ public static void decode(final StringBuilder buffer, final int offset, final int length) - throws FileSystemException - { + throws FileSystemException { int index = offset; int count = length; - for (; count > 0; count--, index++) - { + for (; count > 0; count--, index++) { final char ch = buffer.charAt(index); - if (ch != '%') - { + if (ch != '%') { continue; } - if (count < 3) - { - throw new FileSystemException( - "vfs.provider/invalid-escape-sequence.error", buffer - .substring(index, index + count)); + if (count < 3) { + throw new FileSystemException("vfs.provider/invalid-escape-sequence.error", + buffer.substring(index, index + count)); } // Decode final int dig1 = Character.digit(buffer.charAt(index + 1), HEX_BASE); final int dig2 = Character.digit(buffer.charAt(index + 2), HEX_BASE); - if (dig1 == -1 || dig2 == -1) - { - throw new FileSystemException( - "vfs.provider/invalid-escape-sequence.error", buffer - .substring(index, index + 3)); + if (dig1 == -1 || dig2 == -1) { + throw new FileSystemException("vfs.provider/invalid-escape-sequence.error", + buffer.substring(index, index + 3)); } final char value = (char) (dig1 << BITS_IN_HALF_BYTE | dig2); @@ -350,51 +306,42 @@ public final class UriParser /** * Encodes and appends a string to a StringBuilder. + * * @param buffer The StringBuilder to append to. * @param unencodedValue The String to encode and append. * @param reserved characters to encode. */ - public static void appendEncoded(final StringBuilder buffer, - final String unencodedValue, final char[] reserved) - { + public static void appendEncoded(final StringBuilder buffer, final String unencodedValue, final char[] reserved) { final int offset = buffer.length(); buffer.append(unencodedValue); encode(buffer, offset, unencodedValue.length(), reserved); } /** - * Encodes a set of reserved characters in a StringBuilder, using the URI %nn - * encoding. Always encodes % characters. + * Encodes a set of reserved characters in a StringBuilder, using the URI %nn encoding. Always encodes % characters. + * * @param buffer The StringBuilder to append to. * @param offset The position in the buffer to start encoding at. * @param length The number of characters to encode. * @param reserved characters to encode. */ - public static void encode(final StringBuilder buffer, final int offset, - final int length, final char[] reserved) - { + public static void encode(final StringBuilder buffer, final int offset, final int length, final char[] reserved) { int index = offset; int count = length; - for (; count > 0; index++, count--) - { + for (; count > 0; index++, count--) { final char ch = buffer.charAt(index); boolean match = ch == '%'; - if (reserved != null) - { - for (int i = 0; !match && i < reserved.length; i++) - { - if (ch == reserved[i]) - { + if (reserved != null) { + for (int i = 0; !match && i < reserved.length; i++) { + if (ch == reserved[i]) { match = true; } } } - if (match) - { + if (match) { // Encode - final char[] digits = - {Character.forDigit((ch >> BITS_IN_HALF_BYTE) & LOW_MASK, HEX_BASE), - Character.forDigit(ch & LOW_MASK, HEX_BASE)}; + final char[] digits = { Character.forDigit((ch >> BITS_IN_HALF_BYTE) & LOW_MASK, HEX_BASE), + Character.forDigit(ch & LOW_MASK, HEX_BASE) }; buffer.setCharAt(index, '%'); buffer.insert(index + 1, digits); index += 2; @@ -404,24 +351,23 @@ public final class UriParser /** * Removes %nn encodings from a string. + * * @param decodedStr The decoded String. * @return The encoded String. */ - public static String encode(final String decodedStr) - { + public static String encode(final String decodedStr) { return encode(decodedStr, null); } /** * Converts "special" characters to their %nn value. + * * @param decodedStr The decoded String. * @param reserved Characters to encode. * @return The encoded String */ - public static String encode(final String decodedStr, final char[] reserved) - { - if (decodedStr == null) - { + public static String encode(final String decodedStr, final char[] reserved) { + if (decodedStr == null) { return null; } final StringBuilder buffer = new StringBuilder(decodedStr); @@ -431,17 +377,15 @@ public final class UriParser /** * Encode an array of Strings. + * * @param strings The array of Strings to encode. * @return An array of encoded Strings. */ - public static String[] encode(final String[] strings) - { - if (strings == null) - { + public static String[] encode(final String[] strings) { + if (strings == null) { return null; } - for (int i = 0; i < strings.length; i++) - { + for (int i = 0; i < strings.length; i++) { strings[i] = encode(strings[i]); } return strings; @@ -449,47 +393,38 @@ public final class UriParser /** * Decodes the String. + * * @param uri The String to decode. * @throws FileSystemException if an error occurs. */ - public static void checkUriEncoding(final String uri) throws FileSystemException - { + public static void checkUriEncoding(final String uri) throws FileSystemException { decode(uri); } - public static void canonicalizePath(final StringBuilder buffer, final int offset, - final int length, final FileNameParser fileNameParser) - throws FileSystemException - { + public static void canonicalizePath(final StringBuilder buffer, final int offset, final int length, + final FileNameParser fileNameParser) throws FileSystemException { int index = offset; int count = length; - for (; count > 0; count--, index++) - { + for (; count > 0; count--, index++) { final char ch = buffer.charAt(index); - if (ch == '%') - { - if (count < 3) - { - throw new FileSystemException( - "vfs.provider/invalid-escape-sequence.error", + if (ch == '%') { + if (count < 3) { + throw new FileSystemException("vfs.provider/invalid-escape-sequence.error", buffer.substring(index, index + count)); } // Decode final int dig1 = Character.digit(buffer.charAt(index + 1), HEX_BASE); final int dig2 = Character.digit(buffer.charAt(index + 2), HEX_BASE); - if (dig1 == -1 || dig2 == -1) - { - throw new FileSystemException( - "vfs.provider/invalid-escape-sequence.error", + if (dig1 == -1 || dig2 == -1) { + throw new FileSystemException("vfs.provider/invalid-escape-sequence.error", buffer.substring(index, index + 3)); } final char value = (char) (dig1 << BITS_IN_HALF_BYTE | dig2); final boolean match = value == '%' || fileNameParser.encodeCharacter(value); - if (match) - { + if (match) { // this is a reserved character, not allowed to decode index += 2; count -= 2; @@ -500,13 +435,10 @@ public final class UriParser buffer.setCharAt(index, value); buffer.delete(index + 1, index + 3); count -= 2; - } - else if (fileNameParser.encodeCharacter(ch)) - { + } else if (fileNameParser.encodeCharacter(ch)) { // Encode - final char[] digits = - {Character.forDigit((ch >> BITS_IN_HALF_BYTE) & LOW_MASK, HEX_BASE), - Character.forDigit(ch & LOW_MASK, HEX_BASE)}; + final char[] digits = { Character.forDigit((ch >> BITS_IN_HALF_BYTE) & LOW_MASK, HEX_BASE), + Character.forDigit(ch & LOW_MASK, HEX_BASE) }; buffer.setCharAt(index, '%'); buffer.insert(index + 1, digits); index += 2; @@ -516,15 +448,13 @@ public final class UriParser /** * Extract the query String from the URI. + * * @param name StringBuilder containing the URI. * @return The query string, if any. null otherwise. */ - public static String extractQueryString(final StringBuilder name) - { - for (int pos = 0; pos < name.length(); pos++) - { - if (name.charAt(pos) == '?') - { + public static String extractQueryString(final StringBuilder name) { + for (int pos = 0; pos < name.length(); pos++) { + if (name.charAt(pos) == '?') { final String queryString = name.substring(pos + 1); name.delete(pos, name.length()); return queryString; Modified: commons/proper/vfs/trunk/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/VfsComponent.java URL: http://svn.apache.org/viewvc/commons/proper/vfs/trunk/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/VfsComponent.java?rev=1808381&r1=1808380&r2=1808381&view=diff ============================================================================== --- commons/proper/vfs/trunk/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/VfsComponent.java (original) +++ commons/proper/vfs/trunk/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/VfsComponent.java Thu Sep 14 19:26:39 2017 @@ -20,8 +20,8 @@ import org.apache.commons.logging.Log; import org.apache.commons.vfs2.FileSystemException; /** - * This interface is used to manage the lifecycle of all VFS components. - * This includes all implementations of the following interfaces: + * This interface is used to manage the lifecycle of all VFS components. This includes all implementations of the + * following interfaces: * <ul> * <li>{@link FileProvider} * <li>{@link org.apache.commons.vfs2.FileSystem} @@ -29,8 +29,7 @@ import org.apache.commons.vfs2.FileSyste * <li>{@link TemporaryFileStore} * </ul> */ -public interface VfsComponent -{ +public interface VfsComponent { /** * Sets the Logger to use for the component. * @@ -47,6 +46,7 @@ public interface VfsComponent /** * Initializes the component. + * * @throws FileSystemException if an error occurs. */ void init() throws FileSystemException; Modified: commons/proper/vfs/trunk/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/VfsComponentContext.java URL: http://svn.apache.org/viewvc/commons/proper/vfs/trunk/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/VfsComponentContext.java?rev=1808381&r1=1808380&r2=1808381&view=diff ============================================================================== --- commons/proper/vfs/trunk/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/VfsComponentContext.java (original) +++ commons/proper/vfs/trunk/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/VfsComponentContext.java Thu Sep 14 19:26:39 2017 @@ -25,18 +25,16 @@ import org.apache.commons.vfs2.FileSyste import org.apache.commons.vfs2.FileSystemOptions; /** - * Allows VFS components to access the services they need, such as the file - * replicator. A VFS component is supplied with a context as part of its - * initialisation. + * Allows VFS components to access the services they need, such as the file replicator. A VFS component is supplied with + * a context as part of its initialisation. * * @see VfsComponent#setContext */ -public interface VfsComponentContext -{ +public interface VfsComponentContext { /** - * Locate a file by name. See - * {@link FileSystemManager#resolveFile(FileObject, String)} for a - * description of how this works. + * Locate a file by name. See {@link FileSystemManager#resolveFile(FileObject, String)} for a description of how + * this works. + * * @param baseFile The base FileObject. * @param name The name of the file to locate. * @param fileSystemOptions The FileSystemOptions. @@ -44,22 +42,21 @@ public interface VfsComponentContext * @throws FileSystemException if an error occurs. */ FileObject resolveFile(FileObject baseFile, String name, FileSystemOptions fileSystemOptions) - throws FileSystemException; + throws FileSystemException; /** - * Locate a file by name. See - * {@link FileSystemManager#resolveFile( String)} for a - * description of how this works. + * Locate a file by name. See {@link FileSystemManager#resolveFile( String)} for a description of how this works. + * * @param name The name of the file to locate. * @param fileSystemOptions The FileSystemOptions. * @return The FileObject for the located file. * @throws FileSystemException if an error occurs. */ - FileObject resolveFile(String name, FileSystemOptions fileSystemOptions) - throws FileSystemException; + FileObject resolveFile(String name, FileSystemOptions fileSystemOptions) throws FileSystemException; /** * Parse a URI into a FileName. + * * @param uri The URI String. * @return The FileName. * @throws FileSystemException if an error occurs. @@ -68,6 +65,7 @@ public interface VfsComponentContext /** * Locates a file replicator for the provider to use. + * * @return The FileReplicator. * @throws FileSystemException if an error occurs. */ @@ -75,6 +73,7 @@ public interface VfsComponentContext /** * Locates a temporary file store for the provider to use. + * * @return The TemporaryFileStore. * @throws FileSystemException if an error occurs. */ @@ -82,6 +81,7 @@ public interface VfsComponentContext /** * Returns a {@link FileObject} for a local file. + * * @param file The File to convert to a FileObject. * @return the FileObject. * @throws FileSystemException if an error occurs. Modified: commons/proper/vfs/trunk/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/bzip2/Bzip2FileObject.java URL: http://svn.apache.org/viewvc/commons/proper/vfs/trunk/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/bzip2/Bzip2FileObject.java?rev=1808381&r1=1808380&r2=1808381&view=diff ============================================================================== --- commons/proper/vfs/trunk/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/bzip2/Bzip2FileObject.java (original) +++ commons/proper/vfs/trunk/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/bzip2/Bzip2FileObject.java Thu Sep 14 19:26:39 2017 @@ -30,40 +30,35 @@ import org.apache.commons.vfs2.provider. /** * the bzip2 file. */ -public class Bzip2FileObject extends CompressedFileFileObject<Bzip2FileSystem> -{ +public class Bzip2FileObject extends CompressedFileFileObject<Bzip2FileSystem> { /** - * Deprecated since 2.1. + * Deprecated since 2.1. * * @deprecated Use {@link #Bzip2FileObject(AbstractFileName, FileObject, Bzip2FileSystem)} instead. */ @Deprecated - protected Bzip2FileObject(final AbstractFileName name, final FileObject container, final CompressedFileFileSystem fs) - { + protected Bzip2FileObject(final AbstractFileName name, final FileObject container, + final CompressedFileFileSystem fs) { super(name, container, cast(fs)); } - protected Bzip2FileObject(final AbstractFileName name, final FileObject container, final Bzip2FileSystem fs) - { + protected Bzip2FileObject(final AbstractFileName name, final FileObject container, final Bzip2FileSystem fs) { super(name, container, fs); } @Override - protected InputStream doGetInputStream() throws Exception - { + protected InputStream doGetInputStream() throws Exception { // check file final InputStream is = getContainer().getContent().getInputStream(); return wrapInputStream(getName().getURI(), is); } - public static InputStream wrapInputStream(final String name, final InputStream is) throws IOException - { + public static InputStream wrapInputStream(final String name, final InputStream is) throws IOException { return new BZip2CompressorInputStream(is); } @Override - protected OutputStream doGetOutputStream(final boolean bAppend) throws Exception - { + protected OutputStream doGetOutputStream(final boolean bAppend) throws Exception { final OutputStream os = getContainer().getContent().getOutputStream(false); return new BZip2CompressorOutputStream(os); } Modified: commons/proper/vfs/trunk/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/bzip2/Bzip2FileProvider.java URL: http://svn.apache.org/viewvc/commons/proper/vfs/trunk/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/bzip2/Bzip2FileProvider.java?rev=1808381&r1=1808380&r2=1808381&view=diff ============================================================================== --- commons/proper/vfs/trunk/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/bzip2/Bzip2FileProvider.java (original) +++ commons/proper/vfs/trunk/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/bzip2/Bzip2FileProvider.java Thu Sep 14 19:26:39 2017 @@ -31,37 +31,24 @@ import org.apache.commons.vfs2.provider. /** * Provides access to the content of bzip2 compressed files. */ -public class Bzip2FileProvider extends CompressedFileFileProvider -{ +public class Bzip2FileProvider extends CompressedFileFileProvider { /** The provider's capabilities */ - protected static final Collection<Capability> capabilities = - Collections.unmodifiableCollection(Arrays.asList(new Capability[] - { - Capability.GET_LAST_MODIFIED, - Capability.GET_TYPE, - Capability.LIST_CHILDREN, - Capability.READ_CONTENT, - Capability.WRITE_CONTENT, - Capability.URI, - Capability.COMPRESS - })); + protected static final Collection<Capability> capabilities = Collections.unmodifiableCollection(Arrays + .asList(new Capability[] { Capability.GET_LAST_MODIFIED, Capability.GET_TYPE, Capability.LIST_CHILDREN, + Capability.READ_CONTENT, Capability.WRITE_CONTENT, Capability.URI, Capability.COMPRESS })); - public Bzip2FileProvider() - { + public Bzip2FileProvider() { super(); } @Override protected FileSystem createFileSystem(final FileName name, final FileObject file, - final FileSystemOptions fileSystemOptions) - throws FileSystemException - { + final FileSystemOptions fileSystemOptions) throws FileSystemException { return new Bzip2FileSystem(name, file, fileSystemOptions); } @Override - public Collection<Capability> getCapabilities() - { + public Collection<Capability> getCapabilities() { return capabilities; } } Modified: commons/proper/vfs/trunk/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/bzip2/Bzip2FileSystem.java URL: http://svn.apache.org/viewvc/commons/proper/vfs/trunk/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/bzip2/Bzip2FileSystem.java?rev=1808381&r1=1808380&r2=1808381&view=diff ============================================================================== --- commons/proper/vfs/trunk/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/bzip2/Bzip2FileSystem.java (original) +++ commons/proper/vfs/trunk/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/bzip2/Bzip2FileSystem.java Thu Sep 14 19:26:39 2017 @@ -29,23 +29,19 @@ import org.apache.commons.vfs2.provider. /** * Filesytem to handle compressed files using the bzip2 method. */ -public class Bzip2FileSystem extends CompressedFileFileSystem -{ +public class Bzip2FileSystem extends CompressedFileFileSystem { protected Bzip2FileSystem(final FileName rootName, final FileObject parentLayer, - final FileSystemOptions fileSystemOptions) - { + final FileSystemOptions fileSystemOptions) { super(rootName, parentLayer, fileSystemOptions); } @Override - protected FileObject createFile(final AbstractFileName name) throws FileSystemException - { + protected FileObject createFile(final AbstractFileName name) throws FileSystemException { return new Bzip2FileObject(name, getParentLayer(), this); } @Override - protected void addCapabilities(final Collection<Capability> caps) - { + protected void addCapabilities(final Collection<Capability> caps) { caps.addAll(Bzip2FileProvider.capabilities); } } Modified: commons/proper/vfs/trunk/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/compressed/CompressedFileFileObject.java URL: http://svn.apache.org/viewvc/commons/proper/vfs/trunk/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/compressed/CompressedFileFileObject.java?rev=1808381&r1=1808380&r2=1808381&view=diff ============================================================================== --- commons/proper/vfs/trunk/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/compressed/CompressedFileFileObject.java (original) +++ commons/proper/vfs/trunk/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/compressed/CompressedFileFileObject.java Thu Sep 14 19:26:39 2017 @@ -30,27 +30,23 @@ import org.apache.commons.vfs2.provider. * Such a file only has one child (the compressed filename with stripped last extension) * </p> * - * @param <FS> - * A CompressedFileFileSystem + * @param <FS> A CompressedFileFileSystem */ -public abstract class CompressedFileFileObject<FS extends CompressedFileFileSystem> extends AbstractFileObject<FS> -{ +public abstract class CompressedFileFileObject<FS extends CompressedFileFileSystem> extends AbstractFileObject<FS> { private final FileObject container; private final String[] children; - protected CompressedFileFileObject(final AbstractFileName name, final FileObject container, final FS fs) - { + protected CompressedFileFileObject(final AbstractFileName name, final FileObject container, final FS fs) { super(name, fs); this.container = container; // todo, add getBaseName(String) to FileName String basename = container.getName().getBaseName(); final int pos = basename.lastIndexOf('.'); - if (pos > 0) - { + if (pos > 0) { basename = basename.substring(0, pos); } - children = new String[]{basename}; + children = new String[] { basename }; } /** @@ -60,8 +56,7 @@ public abstract class CompressedFileFile * @throws FileSystemException if an error occurs. */ @Override - public boolean isWriteable() throws FileSystemException - { + public boolean isWriteable() throws FileSystemException { return getFileSystem().hasCapability(Capability.WRITE_CONTENT); } @@ -69,10 +64,8 @@ public abstract class CompressedFileFile * Returns the file's type. */ @Override - protected FileType doGetType() throws FileSystemException - { - if (getName().getPath().endsWith("/")) - { + protected FileType doGetType() throws FileSystemException { + if (getName().getPath().endsWith("/")) { return FileType.FOLDER; } return FileType.FILE; @@ -82,18 +75,16 @@ public abstract class CompressedFileFile * Lists the children of the file. */ @Override - protected String[] doListChildren() - { + protected String[] doListChildren() { return children; } /** - * Returns the size of the file content (in bytes). Is only called if - * {@link #doGetType} returns {@link FileType#FILE}. + * Returns the size of the file content (in bytes). Is only called if {@link #doGetType} returns + * {@link FileType#FILE}. */ @Override - protected long doGetContentSize() - { + protected long doGetContentSize() { return -1; } @@ -101,19 +92,16 @@ public abstract class CompressedFileFile * Returns the last modified time of this file. */ @Override - protected long doGetLastModifiedTime() throws Exception - { + protected long doGetLastModifiedTime() throws Exception { return container.getContent().getLastModifiedTime(); } - protected FileObject getContainer() - { + protected FileObject getContainer() { return container; } @Override - public void createFile() throws FileSystemException - { + public void createFile() throws FileSystemException { container.createFile(); injectType(FileType.FILE); } Modified: commons/proper/vfs/trunk/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/compressed/CompressedFileFileProvider.java URL: http://svn.apache.org/viewvc/commons/proper/vfs/trunk/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/compressed/CompressedFileFileProvider.java?rev=1808381&r1=1808380&r2=1808381&view=diff ============================================================================== --- commons/proper/vfs/trunk/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/compressed/CompressedFileFileProvider.java (original) +++ commons/proper/vfs/trunk/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/compressed/CompressedFileFileProvider.java Thu Sep 14 19:26:39 2017 @@ -29,14 +29,10 @@ import org.apache.commons.vfs2.provider. import org.apache.commons.vfs2.provider.LayeredFileName; /** - * A file system provider for compressed files. Provides read-only file - * systems. + * A file system provider for compressed files. Provides read-only file systems. */ -public abstract class CompressedFileFileProvider - extends AbstractLayeredFileProvider -{ - public CompressedFileFileProvider() - { +public abstract class CompressedFileFileProvider extends AbstractLayeredFileProvider { + public CompressedFileFileProvider() { super(); } @@ -46,35 +42,25 @@ public abstract class CompressedFileFile * @param uri The URI to parse. */ /* - public FileName parseUri(final String uri) - throws FileSystemException - { - return ZipFileName.parseUri(uri); - } - */ + * public FileName parseUri(final String uri) throws FileSystemException { return ZipFileName.parseUri(uri); } + */ /** - * Creates a layered file system. This method is called if the file system - * is not cached. + * Creates a layered file system. This method is called if the file system is not cached. * * @param scheme The URI scheme. - * @param file The file to create the file system on top of. + * @param file The file to create the file system on top of. * @return The file system. */ @Override - protected FileSystem doCreateFileSystem(final String scheme, - final FileObject file, - final FileSystemOptions fileSystemOptions) - throws FileSystemException - { - final FileName name = - new LayeredFileName(scheme, file.getName(), FileName.ROOT_PATH, FileType.FOLDER); + protected FileSystem doCreateFileSystem(final String scheme, final FileObject file, + final FileSystemOptions fileSystemOptions) throws FileSystemException { + final FileName name = new LayeredFileName(scheme, file.getName(), FileName.ROOT_PATH, FileType.FOLDER); return createFileSystem(name, file, fileSystemOptions); } protected abstract FileSystem createFileSystem(final FileName name, final FileObject file, - final FileSystemOptions fileSystemOptions) - throws FileSystemException; + final FileSystemOptions fileSystemOptions) throws FileSystemException; @Override public abstract Collection<Capability> getCapabilities(); Modified: commons/proper/vfs/trunk/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/compressed/CompressedFileFileSystem.java URL: http://svn.apache.org/viewvc/commons/proper/vfs/trunk/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/compressed/CompressedFileFileSystem.java?rev=1808381&r1=1808380&r2=1808381&view=diff ============================================================================== --- commons/proper/vfs/trunk/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/compressed/CompressedFileFileSystem.java (original) +++ commons/proper/vfs/trunk/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/compressed/CompressedFileFileSystem.java Thu Sep 14 19:26:39 2017 @@ -29,13 +29,9 @@ import org.apache.commons.vfs2.provider. /** * A read-only file system for compressed files. */ -public abstract class CompressedFileFileSystem - extends AbstractFileSystem -{ - protected CompressedFileFileSystem(final FileName rootName, - final FileObject parentLayer, - final FileSystemOptions fileSystemOptions) - { +public abstract class CompressedFileFileSystem extends AbstractFileSystem { + protected CompressedFileFileSystem(final FileName rootName, final FileObject parentLayer, + final FileSystemOptions fileSystemOptions) { super(rootName, parentLayer, fileSystemOptions); } Modified: commons/proper/vfs/trunk/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/ftp/FTPClientWrapper.java URL: http://svn.apache.org/viewvc/commons/proper/vfs/trunk/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/ftp/FTPClientWrapper.java?rev=1808381&r1=1808380&r2=1808381&view=diff ============================================================================== --- commons/proper/vfs/trunk/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/ftp/FTPClientWrapper.java (original) +++ commons/proper/vfs/trunk/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/ftp/FTPClientWrapper.java Thu Sep 14 19:26:39 2017 @@ -34,70 +34,56 @@ import org.apache.commons.vfs2.util.User /** * A wrapper to the FTPClient to allow automatic reconnect on connection loss. * <p> - * I decided to not to use eg. noop() to determine the state of the connection to avoid - * unnecessary server round-trips. + * I decided to not to use eg. noop() to determine the state of the connection to avoid unnecessary server round-trips. */ -public class FTPClientWrapper implements FtpClient -{ - +public class FTPClientWrapper implements FtpClient { + private static final Log LOG = LogFactory.getLog(FTPClientWrapper.class); - + protected final FileSystemOptions fileSystemOptions; private final GenericFileName root; private FTPClient ftpClient; protected FTPClientWrapper(final GenericFileName root, final FileSystemOptions fileSystemOptions) - throws FileSystemException - { + throws FileSystemException { this.root = root; this.fileSystemOptions = fileSystemOptions; getFtpClient(); // fail-fast } - public GenericFileName getRoot() - { + public GenericFileName getRoot() { return root; } - public FileSystemOptions getFileSystemOptions() - { + public FileSystemOptions getFileSystemOptions() { return fileSystemOptions; } - private FTPClient createClient() throws FileSystemException - { + private FTPClient createClient() throws FileSystemException { final GenericFileName rootName = getRoot(); UserAuthenticationData authData = null; - try - { + try { authData = UserAuthenticatorUtils.authenticate(fileSystemOptions, FtpFileProvider.AUTHENTICATOR_TYPES); return createClient(rootName, authData); - } - finally - { + } finally { UserAuthenticatorUtils.cleanup(authData); } } protected FTPClient createClient(final GenericFileName rootName, final UserAuthenticationData authData) - throws FileSystemException - { - return FtpClientFactory.createConnection( - rootName.getHostName(), - rootName.getPort(), - UserAuthenticatorUtils.getData( - authData, UserAuthenticationData.USERNAME, UserAuthenticatorUtils.toChar(rootName.getUserName())), - UserAuthenticatorUtils.getData( - authData, UserAuthenticationData.PASSWORD, UserAuthenticatorUtils.toChar(rootName.getPassword())), - rootName.getPath(), getFileSystemOptions()); - } - - private FTPClient getFtpClient() throws FileSystemException - { - if (ftpClient == null) - { + throws FileSystemException { + return FtpClientFactory.createConnection(rootName.getHostName(), rootName.getPort(), + UserAuthenticatorUtils.getData(authData, UserAuthenticationData.USERNAME, + UserAuthenticatorUtils.toChar(rootName.getUserName())), + UserAuthenticatorUtils.getData(authData, UserAuthenticationData.PASSWORD, + UserAuthenticatorUtils.toChar(rootName.getPassword())), + rootName.getPath(), getFileSystemOptions()); + } + + private FTPClient getFtpClient() throws FileSystemException { + if (ftpClient == null) { ftpClient = createClient(); } @@ -105,64 +91,46 @@ public class FTPClientWrapper implements } @Override - public boolean isConnected() throws FileSystemException - { + public boolean isConnected() throws FileSystemException { return ftpClient != null && ftpClient.isConnected(); } @Override - public void disconnect() throws IOException - { - try - { + public void disconnect() throws IOException { + try { getFtpClient().quit(); - } - catch (final IOException e) - { + } catch (final IOException e) { LOG.debug("I/O exception while trying to quit, probably it's a timed out connection, ignoring.", e); - } - finally - { - try - { + } finally { + try { getFtpClient().disconnect(); - } - catch (final IOException e) - { + } catch (final IOException e) { LOG.warn("I/O exception while trying to disconnect, probably it's a closed connection, ignoring.", e); - } - finally - { + } finally { ftpClient = null; } } } @Override - public FTPFile[] listFiles(final String relPath) throws IOException - { - try - { + public FTPFile[] listFiles(final String relPath) throws IOException { + try { // VFS-210: return getFtpClient().listFiles(relPath); final FTPFile[] files = listFilesInDirectory(relPath); return files; - } - catch (final IOException e) - { + } catch (final IOException e) { disconnect(); final FTPFile[] files = listFilesInDirectory(relPath); return files; } } - private FTPFile[] listFilesInDirectory(final String relPath) throws IOException - { + private FTPFile[] listFilesInDirectory(final String relPath) throws IOException { FTPFile[] files; // VFS-307: no check if we can simply list the files, this might fail if there are spaces in the path files = getFtpClient().listFiles(relPath); - if (FTPReply.isPositiveCompletion(getFtpClient().getReplyCode())) - { + if (FTPReply.isPositiveCompletion(getFtpClient().getReplyCode())) { return files; } @@ -170,19 +138,16 @@ public class FTPClientWrapper implements // if VFS is required to fallback here the user might experience a real bad FTP performance // as then every list requires 4 ftp commands. String workingDirectory = null; - if (relPath != null) - { + if (relPath != null) { workingDirectory = getFtpClient().printWorkingDirectory(); - if (!getFtpClient().changeWorkingDirectory(relPath)) - { + if (!getFtpClient().changeWorkingDirectory(relPath)) { return null; } } files = getFtpClient().listFiles(); - if (relPath != null && !getFtpClient().changeWorkingDirectory(workingDirectory)) - { + if (relPath != null && !getFtpClient().changeWorkingDirectory(workingDirectory)) { throw new FileSystemException("vfs.provider.ftp.wrapper/change-work-directory-back.error", workingDirectory); } @@ -190,66 +155,48 @@ public class FTPClientWrapper implements } @Override - public boolean removeDirectory(final String relPath) throws IOException - { - try - { + public boolean removeDirectory(final String relPath) throws IOException { + try { return getFtpClient().removeDirectory(relPath); - } - catch (final IOException e) - { + } catch (final IOException e) { disconnect(); return getFtpClient().removeDirectory(relPath); } } @Override - public boolean deleteFile(final String relPath) throws IOException - { - try - { + public boolean deleteFile(final String relPath) throws IOException { + try { return getFtpClient().deleteFile(relPath); - } - catch (final IOException e) - { + } catch (final IOException e) { disconnect(); return getFtpClient().deleteFile(relPath); } } @Override - public boolean rename(final String oldName, final String newName) throws IOException - { - try - { + public boolean rename(final String oldName, final String newName) throws IOException { + try { return getFtpClient().rename(oldName, newName); - } - catch (final IOException e) - { + } catch (final IOException e) { disconnect(); return getFtpClient().rename(oldName, newName); } } @Override - public boolean makeDirectory(final String relPath) throws IOException - { - try - { + public boolean makeDirectory(final String relPath) throws IOException { + try { return getFtpClient().makeDirectory(relPath); - } - catch (final IOException e) - { + } catch (final IOException e) { disconnect(); return getFtpClient().makeDirectory(relPath); } } @Override - public boolean completePendingCommand() throws IOException - { - if (ftpClient != null) - { + public boolean completePendingCommand() throws IOException { + if (ftpClient != null) { return getFtpClient().completePendingCommand(); } @@ -257,30 +204,22 @@ public class FTPClientWrapper implements } @Override - public InputStream retrieveFileStream(final String relPath) throws IOException - { - try - { + public InputStream retrieveFileStream(final String relPath) throws IOException { + try { return getFtpClient().retrieveFileStream(relPath); - } - catch (final IOException e) - { + } catch (final IOException e) { disconnect(); return getFtpClient().retrieveFileStream(relPath); } } @Override - public InputStream retrieveFileStream(final String relPath, final long restartOffset) throws IOException - { - try - { + public InputStream retrieveFileStream(final String relPath, final long restartOffset) throws IOException { + try { final FTPClient client = getFtpClient(); client.setRestartOffset(restartOffset); return client.retrieveFileStream(relPath); - } - catch (final IOException e) - { + } catch (final IOException e) { disconnect(); final FTPClient client = getFtpClient(); client.setRestartOffset(restartOffset); @@ -289,38 +228,28 @@ public class FTPClientWrapper implements } @Override - public OutputStream appendFileStream(final String relPath) throws IOException - { - try - { + public OutputStream appendFileStream(final String relPath) throws IOException { + try { return getFtpClient().appendFileStream(relPath); - } - catch (final IOException e) - { + } catch (final IOException e) { disconnect(); return getFtpClient().appendFileStream(relPath); } } @Override - public OutputStream storeFileStream(final String relPath) throws IOException - { - try - { + public OutputStream storeFileStream(final String relPath) throws IOException { + try { return getFtpClient().storeFileStream(relPath); - } - catch (final IOException e) - { + } catch (final IOException e) { disconnect(); return getFtpClient().storeFileStream(relPath); } } @Override - public boolean abort() throws IOException - { - try - { + public boolean abort() throws IOException { + try { // [email protected]: 2005-02-14 // it should be better to really "abort" the transfer, but // currently I didnt manage to make it work - so lets "abort" the hard way. @@ -328,17 +257,14 @@ public class FTPClientWrapper implements disconnect(); return true; - } - catch (final IOException e) - { + } catch (final IOException e) { disconnect(); } return true; } @Override - public String getReplyString() throws IOException - { + public String getReplyString() throws IOException { return getFtpClient().getReplyString(); } } Modified: commons/proper/vfs/trunk/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/ftp/FtpClient.java URL: http://svn.apache.org/viewvc/commons/proper/vfs/trunk/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/ftp/FtpClient.java?rev=1808381&r1=1808380&r2=1808381&view=diff ============================================================================== --- commons/proper/vfs/trunk/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/ftp/FtpClient.java (original) +++ commons/proper/vfs/trunk/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/ftp/FtpClient.java Thu Sep 14 19:26:39 2017 @@ -26,8 +26,7 @@ import org.apache.commons.vfs2.FileSyste /** * What VFS expects from an ftp client to provide. */ -public interface FtpClient -{ +public interface FtpClient { boolean isConnected() throws FileSystemException; void disconnect() throws IOException; Modified: commons/proper/vfs/trunk/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/ftp/FtpClientFactory.java URL: http://svn.apache.org/viewvc/commons/proper/vfs/trunk/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/ftp/FtpClientFactory.java?rev=1808381&r1=1808380&r2=1808381&view=diff ============================================================================== --- commons/proper/vfs/trunk/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/ftp/FtpClientFactory.java (original) +++ commons/proper/vfs/trunk/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/ftp/FtpClientFactory.java Thu Sep 14 19:26:39 2017 @@ -36,97 +36,79 @@ import org.apache.commons.vfs2.util.User /** * Create a FtpClient instance. */ -public final class FtpClientFactory -{ - private FtpClientFactory() - { +public final class FtpClientFactory { + private FtpClientFactory() { } /** * Creates a new connection to the server. * - * @param hostname The host name of the server. - * @param port The port to connect to. - * @param username The name of the user for authentication. - * @param password The user's password. - * @param workingDirectory The base directory. + * @param hostname The host name of the server. + * @param port The port to connect to. + * @param username The name of the user for authentication. + * @param password The user's password. + * @param workingDirectory The base directory. * @param fileSystemOptions The FileSystemOptions. * @return An FTPClient. * @throws FileSystemException if an error occurs while connecting. */ - public static FTPClient createConnection(final String hostname, final int port, - final char[] username, final char[] password, - final String workingDirectory, final FileSystemOptions fileSystemOptions) - throws FileSystemException - { + public static FTPClient createConnection(final String hostname, final int port, final char[] username, + final char[] password, final String workingDirectory, final FileSystemOptions fileSystemOptions) + throws FileSystemException { final FtpConnectionFactory factory = new FtpConnectionFactory(FtpFileSystemConfigBuilder.getInstance()); return factory.createConnection(hostname, port, username, password, workingDirectory, fileSystemOptions); } /** Connection Factory, used to configure the FTPClient. */ - public static final class FtpConnectionFactory extends ConnectionFactory<FTPClient, FtpFileSystemConfigBuilder> - { - private FtpConnectionFactory(final FtpFileSystemConfigBuilder builder) - { + public static final class FtpConnectionFactory extends ConnectionFactory<FTPClient, FtpFileSystemConfigBuilder> { + private FtpConnectionFactory(final FtpFileSystemConfigBuilder builder) { super(builder); } @Override - protected FTPClient createClient(final FileSystemOptions fileSystemOptions) - { + protected FTPClient createClient(final FileSystemOptions fileSystemOptions) { return new FTPClient(); } @Override - protected void setupOpenConnection(final FTPClient client, final FileSystemOptions fileSystemOptions) - { + protected void setupOpenConnection(final FTPClient client, final FileSystemOptions fileSystemOptions) { // nothing to do for FTP } } /** Abstract Factory, used to configure different FTPClients. */ - public abstract static class ConnectionFactory<C extends FTPClient, B extends FtpFileSystemConfigBuilder> - { + public abstract static class ConnectionFactory<C extends FTPClient, B extends FtpFileSystemConfigBuilder> { private static final char[] ANON_CHAR_ARRAY = "anonymous".toCharArray(); private static final int BUFSZ = 40; private final Log log = LogFactory.getLog(getClass()); protected B builder; - protected ConnectionFactory(final B builder) - { + protected ConnectionFactory(final B builder) { this.builder = builder; } public C createConnection(final String hostname, final int port, char[] username, char[] password, - final String workingDirectory, final FileSystemOptions fileSystemOptions) throws FileSystemException - { + final String workingDirectory, final FileSystemOptions fileSystemOptions) throws FileSystemException { // Determine the username and password to use - if (username == null) - { + if (username == null) { username = ANON_CHAR_ARRAY; } - if (password == null) - { + if (password == null) { password = ANON_CHAR_ARRAY; } - try - { + try { final C client = createClient(fileSystemOptions); - if (log.isDebugEnabled()) - { - final Writer writer = new StringWriter(1024) - { + if (log.isDebugEnabled()) { + final Writer writer = new StringWriter(1024) { @Override - public void flush() - { + public void flush() { final StringBuffer buffer = getBuffer(); String message = buffer.toString(); - if (message.toUpperCase().startsWith("PASS ") && message.length() > 5) - { + if (message.toUpperCase().startsWith("PASS ") && message.length() > 5) { message = "PASS ***"; } log.debug(message); @@ -138,159 +120,124 @@ public final class FtpClientFactory configureClient(fileSystemOptions, client); - final FTPFileEntryParserFactory myFactory = - builder.getEntryParserFactory(fileSystemOptions); - if (myFactory != null) - { + final FTPFileEntryParserFactory myFactory = builder.getEntryParserFactory(fileSystemOptions); + if (myFactory != null) { client.setParserFactory(myFactory); } final Boolean remoteVerification = builder.getRemoteVerification(fileSystemOptions); - if (remoteVerification != null) - { + if (remoteVerification != null) { client.setRemoteVerificationEnabled(remoteVerification.booleanValue()); } - try - { + try { // Set connect timeout final Integer connectTimeout = builder.getConnectTimeout(fileSystemOptions); - if (connectTimeout != null) - { + if (connectTimeout != null) { client.setDefaultTimeout(connectTimeout.intValue()); } final String controlEncoding = builder.getControlEncoding(fileSystemOptions); - if (controlEncoding != null) - { + if (controlEncoding != null) { client.setControlEncoding(controlEncoding); } final Proxy proxy = builder.getProxy(fileSystemOptions); - if (proxy != null) - { + if (proxy != null) { client.setProxy(proxy); } client.connect(hostname, port); final int reply = client.getReplyCode(); - if (!FTPReply.isPositiveCompletion(reply)) - { + if (!FTPReply.isPositiveCompletion(reply)) { throw new FileSystemException("vfs.provider.ftp/connect-rejected.error", hostname); } // Login - if (!client.login( - UserAuthenticatorUtils.toString(username), - UserAuthenticatorUtils.toString(password))) - { - throw new FileSystemException("vfs.provider.ftp/login.error", - hostname, UserAuthenticatorUtils.toString(username)); + if (!client.login(UserAuthenticatorUtils.toString(username), + UserAuthenticatorUtils.toString(password))) { + throw new FileSystemException("vfs.provider.ftp/login.error", hostname, + UserAuthenticatorUtils.toString(username)); } FtpFileType fileType = builder.getFileType(fileSystemOptions); - if (fileType == null) - { + if (fileType == null) { fileType = FtpFileType.BINARY; } // Set binary mode - if (!client.setFileType(fileType.getValue())) - { + if (!client.setFileType(fileType.getValue())) { throw new FileSystemException("vfs.provider.ftp/set-file-type.error", fileType); } // Set dataTimeout value final Integer dataTimeout = builder.getDataTimeout(fileSystemOptions); - if (dataTimeout != null) - { + if (dataTimeout != null) { client.setDataTimeout(dataTimeout.intValue()); } final Integer socketTimeout = builder.getSoTimeout(fileSystemOptions); - if (socketTimeout != null) - { + if (socketTimeout != null) { client.setSoTimeout(socketTimeout.intValue()); } final Boolean userDirIsRoot = builder.getUserDirIsRoot(fileSystemOptions); - if (workingDirectory != null && (userDirIsRoot == null || !userDirIsRoot.booleanValue())) - { - if (!client.changeWorkingDirectory(workingDirectory)) - { + if (workingDirectory != null && (userDirIsRoot == null || !userDirIsRoot.booleanValue())) { + if (!client.changeWorkingDirectory(workingDirectory)) { throw new FileSystemException("vfs.provider.ftp/change-work-directory.error", - workingDirectory); + workingDirectory); } } final Boolean passiveMode = builder.getPassiveMode(fileSystemOptions); - if (passiveMode != null && passiveMode.booleanValue()) - { + if (passiveMode != null && passiveMode.booleanValue()) { client.enterLocalPassiveMode(); } setupOpenConnection(client, fileSystemOptions); - } - catch (final IOException e) - { - if (client.isConnected()) - { + } catch (final IOException e) { + if (client.isConnected()) { client.disconnect(); } throw e; } return client; - } - catch (final Exception exc) - { + } catch (final Exception exc) { throw new FileSystemException("vfs.provider.ftp/connect.error", exc, hostname); } } protected abstract C createClient(FileSystemOptions fileSystemOptions) throws FileSystemException; + protected abstract void setupOpenConnection(C client, FileSystemOptions fileSystemOptions) throws IOException; - private void configureClient(final FileSystemOptions fileSystemOptions, final C client) - { + private void configureClient(final FileSystemOptions fileSystemOptions, final C client) { final String key = builder.getEntryParser(fileSystemOptions); - if (key != null) - { + if (key != null) { final FTPClientConfig config = new FTPClientConfig(key); - final String serverLanguageCode = - builder.getServerLanguageCode(fileSystemOptions); - if (serverLanguageCode != null) - { + final String serverLanguageCode = builder.getServerLanguageCode(fileSystemOptions); + if (serverLanguageCode != null) { config.setServerLanguageCode(serverLanguageCode); } - final String defaultDateFormat = - builder.getDefaultDateFormat(fileSystemOptions); - if (defaultDateFormat != null) - { + final String defaultDateFormat = builder.getDefaultDateFormat(fileSystemOptions); + if (defaultDateFormat != null) { config.setDefaultDateFormatStr(defaultDateFormat); } - final String recentDateFormat = - builder.getRecentDateFormat(fileSystemOptions); - if (recentDateFormat != null) - { + final String recentDateFormat = builder.getRecentDateFormat(fileSystemOptions); + if (recentDateFormat != null) { config.setRecentDateFormatStr(recentDateFormat); } - final String serverTimeZoneId = - builder.getServerTimeZoneId(fileSystemOptions); - if (serverTimeZoneId != null) - { + final String serverTimeZoneId = builder.getServerTimeZoneId(fileSystemOptions); + if (serverTimeZoneId != null) { config.setServerTimeZoneId(serverTimeZoneId); } - final String[] shortMonthNames = - builder.getShortMonthNames(fileSystemOptions); - if (shortMonthNames != null) - { + final String[] shortMonthNames = builder.getShortMonthNames(fileSystemOptions); + if (shortMonthNames != null) { final StringBuilder shortMonthNamesStr = new StringBuilder(BUFSZ); - for (final String shortMonthName : shortMonthNames) - { - if (shortMonthNamesStr.length() > 0) - { + for (final String shortMonthName : shortMonthNames) { + if (shortMonthNamesStr.length() > 0) { shortMonthNamesStr.append("|"); } shortMonthNamesStr.append(shortMonthName); Modified: commons/proper/vfs/trunk/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/ftp/FtpFileNameParser.java URL: http://svn.apache.org/viewvc/commons/proper/vfs/trunk/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/ftp/FtpFileNameParser.java?rev=1808381&r1=1808380&r2=1808381&view=diff ============================================================================== --- commons/proper/vfs/trunk/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/ftp/FtpFileNameParser.java (original) +++ commons/proper/vfs/trunk/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/ftp/FtpFileNameParser.java Thu Sep 14 19:26:39 2017 @@ -22,19 +22,16 @@ import org.apache.commons.vfs2.provider. /** * Implementation for ftp. set default port to 21 */ -public class FtpFileNameParser extends HostFileNameParser -{ +public class FtpFileNameParser extends HostFileNameParser { private static final FtpFileNameParser INSTANCE = new FtpFileNameParser(); private static final int PORT = 21; - public FtpFileNameParser() - { + public FtpFileNameParser() { super(PORT); } - public static FileNameParser getInstance() - { + public static FileNameParser getInstance() { return INSTANCE; } }
