Modified: commons/proper/vfs/trunk/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/tar/TarFileProvider.java URL: http://svn.apache.org/viewvc/commons/proper/vfs/trunk/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/tar/TarFileProvider.java?rev=1808381&r1=1808380&r2=1808381&view=diff ============================================================================== --- commons/proper/vfs/trunk/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/tar/TarFileProvider.java (original) +++ commons/proper/vfs/trunk/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/tar/TarFileProvider.java Thu Sep 14 19:26:39 2017 @@ -32,49 +32,35 @@ import org.apache.commons.vfs2.provider. import org.apache.commons.vfs2.provider.LayeredFileName; /** - * A file system provider for Tar files. Provides read-only file systems. + * A file system provider for Tar files. Provides read-only file systems. */ -public class TarFileProvider extends AbstractLayeredFileProvider -{ +public class TarFileProvider extends AbstractLayeredFileProvider { /** 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.URI, - Capability.VIRTUAL - })); + 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.URI, Capability.VIRTUAL })); - public TarFileProvider() - { + public TarFileProvider() { super(); } /** - * 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 AbstractFileName rootName = - 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 AbstractFileName rootName = new LayeredFileName(scheme, file.getName(), FileName.ROOT_PATH, + FileType.FOLDER); return new TarFileSystem(rootName, 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/tar/TarFileSystem.java URL: http://svn.apache.org/viewvc/commons/proper/vfs/trunk/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/tar/TarFileSystem.java?rev=1808381&r1=1808380&r2=1808381&view=diff ============================================================================== --- commons/proper/vfs/trunk/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/tar/TarFileSystem.java (original) +++ commons/proper/vfs/trunk/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/tar/TarFileSystem.java Thu Sep 14 19:26:39 2017 @@ -43,8 +43,7 @@ import org.apache.commons.vfs2.provider. /** * A read-only file system for Tar files. */ -public class TarFileSystem extends AbstractFileSystem -{ +public class TarFileSystem extends AbstractFileSystem { private static final int DEFAULT_INDEX_SIZE = 100; private static final Log LOG = LogFactory.getLog(TarFileSystem.class); @@ -52,19 +51,15 @@ public class TarFileSystem extends Abstr private final File file; private TarArchiveInputStream tarFile; - protected TarFileSystem(final AbstractFileName rootName, - final FileObject parentLayer, - final FileSystemOptions fileSystemOptions) - throws FileSystemException - { + protected TarFileSystem(final AbstractFileName rootName, final FileObject parentLayer, + final FileSystemOptions fileSystemOptions) throws FileSystemException { super(rootName, parentLayer, fileSystemOptions); // Make a local copy of the file file = parentLayer.getFileSystem().replicateFile(parentLayer, Selectors.SELECT_SELF); // Open the Tar file - if (!file.exists()) - { + if (!file.exists()) { // Don't need to do anything tarFile = null; return; @@ -74,24 +69,20 @@ public class TarFileSystem extends Abstr } @Override - public void init() throws FileSystemException - { + public void init() throws FileSystemException { super.init(); // Build the index - try - { + try { final List<TarFileObject> strongRef = new ArrayList<>(DEFAULT_INDEX_SIZE); TarArchiveEntry entry; - while ((entry = getTarFile().getNextTarEntry()) != null) - { + while ((entry = getTarFile().getNextTarEntry()) != null) { final AbstractFileName name = (AbstractFileName) getFileSystemManager().resolveName(getRootName(), - UriParser.encode(entry.getName())); + UriParser.encode(entry.getName())); // Create the file TarFileObject fileObj; - if (entry.isDirectory() && getFileFromCache(name) != null) - { + if (entry.isDirectory() && getFileFromCache(name) != null) { fileObj = (TarFileObject) getFileFromCache(name); fileObj.setTarEntry(entry); continue; @@ -105,14 +96,12 @@ public class TarFileSystem extends Abstr // Make sure all ancestors exist // TODO - create these on demand TarFileObject parent = null; - for (AbstractFileName parentName = (AbstractFileName) name.getParent(); - parentName != null; - fileObj = parent, parentName = (AbstractFileName) parentName.getParent()) - { + for (AbstractFileName parentName = (AbstractFileName) name + .getParent(); parentName != null; fileObj = parent, parentName = (AbstractFileName) parentName + .getParent()) { // Locate the parent parent = (TarFileObject) getFileFromCache(parentName); - if (parent == null) - { + if (parent == null) { parent = createTarFileObject(parentName, null); putFileToCache(parent); strongRef.add(parent); @@ -123,54 +112,38 @@ public class TarFileSystem extends Abstr parent.attachChild(fileObj.getName()); } } - } - catch (final IOException e) - { + } catch (final IOException e) { throw new FileSystemException(e); - } - finally - { + } finally { closeCommunicationLink(); } } - public InputStream getInputStream(final TarArchiveEntry entry) throws FileSystemException - { + public InputStream getInputStream(final TarArchiveEntry entry) throws FileSystemException { resetTarFile(); - try - { - while (!tarFile.getNextEntry().equals(entry)) - { + try { + while (!tarFile.getNextEntry().equals(entry)) { } return tarFile; - } - catch (final IOException e) - { + } catch (final IOException e) { throw new FileSystemException(e); } } - protected void resetTarFile() throws FileSystemException - { + protected void resetTarFile() throws FileSystemException { // Reading specific entries requires skipping through the tar file from the beginning // Not especially elegant, but we don't have the ability to seek to specific positions // with an input stream. - if (this.file.exists()) - { + if (this.file.exists()) { recreateTarFile(); } } - private void recreateTarFile() throws FileSystemException - { - if (this.tarFile != null) - { - try - { + private void recreateTarFile() throws FileSystemException { + if (this.tarFile != null) { + try { this.tarFile.close(); - } - catch (final IOException e) - { + } catch (final IOException e) { throw new FileSystemException("vfs.provider.tar/close-tar-file.error", file, e); } tarFile = null; @@ -179,57 +152,42 @@ public class TarFileSystem extends Abstr this.tarFile = tarFile; } - protected TarArchiveInputStream getTarFile() throws FileSystemException - { - if (tarFile == null && this.file.exists()) - { + protected TarArchiveInputStream getTarFile() throws FileSystemException { + if (tarFile == null && this.file.exists()) { recreateTarFile(); } return tarFile; } - protected TarFileObject createTarFileObject(final AbstractFileName name, - final TarArchiveEntry entry) throws FileSystemException - { + protected TarFileObject createTarFileObject(final AbstractFileName name, final TarArchiveEntry entry) + throws FileSystemException { return new TarFileObject(name, entry, this, true); } - protected TarArchiveInputStream createTarFile(final File file) throws FileSystemException - { - try - { - if ("tgz".equalsIgnoreCase(getRootName().getScheme())) - { + protected TarArchiveInputStream createTarFile(final File file) throws FileSystemException { + try { + if ("tgz".equalsIgnoreCase(getRootName().getScheme())) { return new TarArchiveInputStream(new GZIPInputStream(new FileInputStream(file))); - } - else if ("tbz2".equalsIgnoreCase(getRootName().getScheme())) - { - return new TarArchiveInputStream(Bzip2FileObject.wrapInputStream(file.getAbsolutePath(), - new FileInputStream(file))); + } else if ("tbz2".equalsIgnoreCase(getRootName().getScheme())) { + return new TarArchiveInputStream( + Bzip2FileObject.wrapInputStream(file.getAbsolutePath(), new FileInputStream(file))); } return new TarArchiveInputStream(new FileInputStream(file)); - } - catch (final IOException ioe) - { + } catch (final IOException ioe) { throw new FileSystemException("vfs.provider.tar/open-tar-file.error", file, ioe); } } @Override - protected void doCloseCommunicationLink() - { + protected void doCloseCommunicationLink() { // Release the tar file - try - { - if (tarFile != null) - { + try { + if (tarFile != null) { tarFile.close(); tarFile = null; } - } - catch (final IOException e) - { + } catch (final IOException e) { // getLogger().warn("vfs.provider.tar/close-tar-file.error :" + file, e); VfsLog.warn(getLogger(), LOG, "vfs.provider.tar/close-tar-file.error :" + file, e); } @@ -239,8 +197,7 @@ public class TarFileSystem extends Abstr * Returns the capabilities of this file system. */ @Override - protected void addCapabilities(final Collection<Capability> caps) - { + protected void addCapabilities(final Collection<Capability> caps) { caps.addAll(TarFileProvider.capabilities); } @@ -248,17 +205,13 @@ public class TarFileSystem extends Abstr * Creates a file object. */ @Override - protected FileObject createFile(final AbstractFileName name) throws FileSystemException - { + protected FileObject createFile(final AbstractFileName name) throws FileSystemException { // This is only called for files which do not exist in the Tar file return new TarFileObject(name, null, this, false); } /** - * will be called after all file-objects closed their streams. - protected void notifyAllStreamsClosed() - { - closeCommunicationLink(); - } + * will be called after all file-objects closed their streams. protected void notifyAllStreamsClosed() { + * closeCommunicationLink(); } */ } Modified: commons/proper/vfs/trunk/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/tar/Tbz2FileProvider.java URL: http://svn.apache.org/viewvc/commons/proper/vfs/trunk/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/tar/Tbz2FileProvider.java?rev=1808381&r1=1808380&r2=1808381&view=diff ============================================================================== --- commons/proper/vfs/trunk/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/tar/Tbz2FileProvider.java (original) +++ commons/proper/vfs/trunk/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/tar/Tbz2FileProvider.java Thu Sep 14 19:26:39 2017 @@ -22,33 +22,25 @@ import org.apache.commons.vfs2.Capabilit import org.apache.commons.vfs2.provider.CompositeFileProvider; /** - * A file system provider for Tar files. Provides read-only file systems. + * A file system provider for Tar files. Provides read-only file systems. */ -public class Tbz2FileProvider extends CompositeFileProvider -{ +public class Tbz2FileProvider extends CompositeFileProvider { /** The provider's capabilities */ protected static final Collection<Capability> capabilities = TarFileProvider.capabilities; - private static final String[] SCHEMES = new String[] - { - "bz2", - "tar" - }; + private static final String[] SCHEMES = new String[] { "bz2", "tar" }; - public Tbz2FileProvider() - { + public Tbz2FileProvider() { super(); } @Override - protected String[] getSchemes() - { + protected String[] getSchemes() { return SCHEMES; } @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/tar/TgzFileProvider.java URL: http://svn.apache.org/viewvc/commons/proper/vfs/trunk/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/tar/TgzFileProvider.java?rev=1808381&r1=1808380&r2=1808381&view=diff ============================================================================== --- commons/proper/vfs/trunk/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/tar/TgzFileProvider.java (original) +++ commons/proper/vfs/trunk/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/tar/TgzFileProvider.java Thu Sep 14 19:26:39 2017 @@ -22,33 +22,25 @@ import org.apache.commons.vfs2.Capabilit import org.apache.commons.vfs2.provider.CompositeFileProvider; /** - * A file system provider for Tar files. Provides read-only file systems. + * A file system provider for Tar files. Provides read-only file systems. */ -public class TgzFileProvider extends CompositeFileProvider -{ +public class TgzFileProvider extends CompositeFileProvider { /** The provider's capabilities */ protected static final Collection<Capability> capabilities = TarFileProvider.capabilities; - private static final String[] SCHEMES = new String[] - { - "gz", - "tar" - }; + private static final String[] SCHEMES = new String[] { "gz", "tar" }; - public TgzFileProvider() - { + public TgzFileProvider() { super(); } @Override - protected String[] getSchemes() - { + protected String[] getSchemes() { return SCHEMES; } @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/temp/TemporaryFileProvider.java URL: http://svn.apache.org/viewvc/commons/proper/vfs/trunk/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/temp/TemporaryFileProvider.java?rev=1808381&r1=1808380&r2=1808381&view=diff ============================================================================== --- commons/proper/vfs/trunk/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/temp/TemporaryFileProvider.java (original) +++ commons/proper/vfs/trunk/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/temp/TemporaryFileProvider.java Thu Sep 14 19:26:39 2017 @@ -33,49 +33,34 @@ import org.apache.commons.vfs2.provider. /** * A provider for temporary files. */ -public class TemporaryFileProvider - extends AbstractFileProvider - implements Comparable<Object> -{ +public class TemporaryFileProvider extends AbstractFileProvider implements Comparable<Object> { private File rootFile; /* - private final static FileName tmpFileName = new AbstractFileName("tmp", "/") - { - protected FileName createName(String absPath) - { - return null; - } - - protected void appendRootUri(StringBuffer buffer) - { - } - }; -*/ + * private final static FileName tmpFileName = new AbstractFileName("tmp", "/") { protected FileName + * createName(String absPath) { return null; } + * + * protected void appendRootUri(StringBuffer buffer) { } }; + */ - public TemporaryFileProvider(final File rootFile) - { + public TemporaryFileProvider(final File rootFile) { this(); this.rootFile = rootFile; } - public TemporaryFileProvider() - { + public TemporaryFileProvider() { super(); } @Override - public int compareTo(final Object o) - { + public int compareTo(final Object o) { final int h1 = hashCode(); final int h2 = o.hashCode(); - if (h1 < h2) - { + if (h1 < h2) { return -1; } - if (h1 > h2) - { + if (h1 > h2) { return 1; } @@ -84,6 +69,7 @@ public class TemporaryFileProvider /** * Locates a file object, by absolute URI. + * * @param baseFile The base FileObject. * @param uri The URI of the file to be located. * @param properties FileSystemOptions to use to locate or create the file. @@ -92,9 +78,7 @@ public class TemporaryFileProvider */ @Override public synchronized FileObject findFile(final FileObject baseFile, final String uri, - final FileSystemOptions properties) - throws FileSystemException - { + final FileSystemOptions properties) throws FileSystemException { // Parse the name final StringBuilder buffer = new StringBuilder(uri); final String scheme = UriParser.extractScheme(uri, buffer); @@ -105,16 +89,13 @@ public class TemporaryFileProvider // Create the temp file system if it does not exist // FileSystem filesystem = findFileSystem( this, (Properties) null); FileSystem filesystem = findFileSystem(this, properties); - if (filesystem == null) - { - if (rootFile == null) - { + if (filesystem == null) { + if (rootFile == null) { rootFile = getContext().getTemporaryFileStore().allocateFile("tempfs"); } - final FileName rootName = - getContext().parseURI(scheme + ":" + FileName.ROOT_PATH); + final FileName rootName = getContext().parseURI(scheme + ":" + FileName.ROOT_PATH); // final FileName rootName = - // new LocalFileName(scheme, scheme + ":", FileName.ROOT_PATH); + // new LocalFileName(scheme, scheme + ":", FileName.ROOT_PATH); filesystem = new LocalFileSystem(rootName, rootFile.getAbsolutePath(), properties); addFileSystem(this, filesystem); } @@ -124,8 +105,7 @@ public class TemporaryFileProvider } @Override - public Collection<Capability> getCapabilities() - { + public Collection<Capability> getCapabilities() { return DefaultLocalFileProvider.capabilities; } } Modified: commons/proper/vfs/trunk/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/url/UrlFileName.java URL: http://svn.apache.org/viewvc/commons/proper/vfs/trunk/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/url/UrlFileName.java?rev=1808381&r1=1808380&r2=1808381&view=diff ============================================================================== --- commons/proper/vfs/trunk/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/url/UrlFileName.java (original) +++ commons/proper/vfs/trunk/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/url/UrlFileName.java Thu Sep 14 19:26:39 2017 @@ -22,10 +22,10 @@ import org.apache.commons.vfs2.provider. /** * A URL FileName. */ -public class UrlFileName extends URLFileName -{ +public class UrlFileName extends URLFileName { /** * The constructor. + * * @param scheme The scheme to use. * @param hostName The host name. * @param port The port. @@ -37,17 +37,14 @@ public class UrlFileName extends URLFile * @param queryString Parameters to use when locating or creating the file name. */ 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) - { + final String userName, final String password, final String path, final FileType type, + final String queryString) { super(scheme, hostName, port, defaultPort, userName, password, path, type, queryString); } @Override - protected void appendRootUri(final StringBuilder buffer, final boolean addPassword) - { - if (getHostName() != null && !"".equals(getHostName())) - { + protected void appendRootUri(final StringBuilder buffer, final boolean addPassword) { + if (getHostName() != null && !"".equals(getHostName())) { super.appendRootUri(buffer, addPassword); return; } Modified: commons/proper/vfs/trunk/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/url/UrlFileNameParser.java URL: http://svn.apache.org/viewvc/commons/proper/vfs/trunk/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/url/UrlFileNameParser.java?rev=1808381&r1=1808380&r2=1808381&view=diff ============================================================================== --- commons/proper/vfs/trunk/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/url/UrlFileNameParser.java (original) +++ commons/proper/vfs/trunk/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/url/UrlFileNameParser.java Thu Sep 14 19:26:39 2017 @@ -29,36 +29,32 @@ import org.apache.commons.vfs2.provider. * <p> * Composite of URLFilenameParser and GenericFilenameParser */ -public class UrlFileNameParser extends AbstractFileNameParser -{ +public class UrlFileNameParser extends AbstractFileNameParser { private final URLFileNameParser url = new URLFileNameParser(80); private final GenericFileNameParser generic = new GenericFileNameParser(); - public UrlFileNameParser() - { + public UrlFileNameParser() { super(); } @Override - public boolean encodeCharacter(final char ch) - { + public boolean encodeCharacter(final char ch) { return super.encodeCharacter(ch) || ch == '?'; } - /** - * Parse a URI. - * @param context The component context. - * @param base The base FileName. - * @param uri The target file name. - * @return The FileName. - * @throws FileSystemException if an error occurs - */ + /** + * Parse a URI. + * + * @param context The component context. + * @param base The base FileName. + * @param uri The target file name. + * @return The FileName. + * @throws FileSystemException if an error occurs + */ @Override public FileName parseUri(final VfsComponentContext context, final FileName base, final String uri) - throws FileSystemException - { - if (isUrlBased(base, uri)) - { + throws FileSystemException { + if (isUrlBased(base, uri)) { return url.parseUri(context, base, uri); } @@ -70,17 +66,15 @@ public class UrlFileNameParser extends A * <p> * VFS treats such URLs differently. * <p> - * A file name is URL-based if the base is a {@code URLFileName} or there are only 2 slashes - * after the scheme. - * e.g: {@code http://host/path}, {@code file:/path/to/file}, {@code file:///path/to/file}. + * A file name is URL-based if the base is a {@code URLFileName} or there are only 2 slashes after the scheme. e.g: + * {@code http://host/path}, {@code file:/path/to/file}, {@code file:///path/to/file}. + * * @param base The filename is relative to this base. * @param filename The filename. * @return true if filename contains two slashes or base was URLFileName. */ - protected boolean isUrlBased(final FileName base, final String filename) - { - if (base instanceof URLFileName) - { + protected boolean isUrlBased(final FileName base, final String filename) { + if (base instanceof URLFileName) { return true; } @@ -93,33 +87,23 @@ public class UrlFileNameParser extends A * @param filename The file name. * @return number of slashes */ - protected int countSlashes(final String filename) - { + protected int countSlashes(final String filename) { int state = 0; int nuofSlash = 0; - for (int pos = 0; pos < filename.length(); pos++) - { + for (int pos = 0; pos < filename.length(); pos++) { final char c = filename.charAt(pos); - if (state == 0) - { - if (c >= 'a' && c <= 'z') - { + if (state == 0) { + if (c >= 'a' && c <= 'z') { continue; } - if (c == ':') - { + if (c == ':') { state++; continue; } - } - else if (state == 1) - { - if (c == '/') - { + } else if (state == 1) { + if (c == '/') { nuofSlash++; - } - else - { + } else { return nuofSlash; } } Modified: commons/proper/vfs/trunk/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/url/UrlFileObject.java URL: http://svn.apache.org/viewvc/commons/proper/vfs/trunk/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/url/UrlFileObject.java?rev=1808381&r1=1808380&r2=1808381&view=diff ============================================================================== --- commons/proper/vfs/trunk/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/url/UrlFileObject.java (original) +++ commons/proper/vfs/trunk/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/url/UrlFileObject.java Thu Sep 14 19:26:39 2017 @@ -32,42 +32,33 @@ import org.apache.commons.vfs2.provider. import org.apache.commons.vfs2.provider.URLFileName; /** - * A {@link org.apache.commons.vfs2.FileObject FileObject} - * implementation backed by a {@link URL}. + * A {@link org.apache.commons.vfs2.FileObject FileObject} implementation backed by a {@link URL}. * <p> * TODO - Implement set lastModified and get/set attribute * <p> * TODO - Implement getOutputStream(). */ -public class UrlFileObject extends AbstractFileObject<UrlFileSystem> -{ +public class UrlFileObject extends AbstractFileObject<UrlFileSystem> { private URL url; - protected UrlFileObject(final UrlFileSystem fs, - final AbstractFileName fileName) - { + protected UrlFileObject(final UrlFileSystem fs, final AbstractFileName fileName) { super(fileName, fs); } /** - * Attaches this file object to its file resource. This method is called - * before any of the doBlah() or onBlah() methods. Sub-classes can use - * this method to perform lazy initialisation. + * Attaches this file object to its file resource. This method is called before any of the doBlah() or onBlah() + * methods. Sub-classes can use this method to perform lazy initialisation. */ @Override - protected void doAttach() throws Exception - { - if (url == null) - { + protected void doAttach() throws Exception { + if (url == null) { // url = new URL(getName().getURI()); url = createURL(getName()); } } - protected URL createURL(final FileName name) throws MalformedURLException, FileSystemException, URIException - { - if (name instanceof URLFileName) - { + protected URL createURL(final FileName name) throws MalformedURLException, FileSystemException, URIException { + if (name instanceof URLFileName) { final URLFileName urlName = (URLFileName) getName(); // TODO: charset @@ -80,34 +71,25 @@ public class UrlFileObject extends Abstr * Determines the type of the file. */ @Override - protected FileType doGetType() throws Exception - { - try - { + protected FileType doGetType() throws Exception { + try { // Attempt to connect & check status final URLConnection conn = url.openConnection(); final InputStream in = conn.getInputStream(); - try - { - if (conn instanceof HttpURLConnection) - { + try { + if (conn instanceof HttpURLConnection) { final int status = ((HttpURLConnection) conn).getResponseCode(); // 200 is good, maybe add more later... - if (HttpURLConnection.HTTP_OK != status) - { + if (HttpURLConnection.HTTP_OK != status) { return FileType.IMAGINARY; } } return FileType.FILE; - } - finally - { + } finally { in.close(); } - } - catch (final FileNotFoundException e) - { + } catch (final FileNotFoundException e) { return FileType.IMAGINARY; } } @@ -116,16 +98,12 @@ public class UrlFileObject extends Abstr * Returns the size of the file content (in bytes). */ @Override - protected long doGetContentSize() throws Exception - { + protected long doGetContentSize() throws Exception { final URLConnection conn = url.openConnection(); final InputStream in = conn.getInputStream(); - try - { + try { return conn.getContentLength(); - } - finally - { + } finally { in.close(); } } @@ -134,17 +112,12 @@ public class UrlFileObject extends Abstr * Returns the last modified time of this file. */ @Override - protected long doGetLastModifiedTime() - throws Exception - { + protected long doGetLastModifiedTime() throws Exception { final URLConnection conn = url.openConnection(); final InputStream in = conn.getInputStream(); - try - { + try { return conn.getLastModified(); - } - finally - { + } finally { in.close(); } } @@ -153,8 +126,7 @@ public class UrlFileObject extends Abstr * Lists the children of the file. */ @Override - protected String[] doListChildren() throws Exception - { + protected String[] doListChildren() throws Exception { throw new FileSystemException("Not implemented."); } @@ -162,8 +134,7 @@ public class UrlFileObject extends Abstr * Creates an input stream to read the file content from. */ @Override - protected InputStream doGetInputStream() throws Exception - { + protected InputStream doGetInputStream() throws Exception { return url.openStream(); } } Modified: commons/proper/vfs/trunk/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/url/UrlFileProvider.java URL: http://svn.apache.org/viewvc/commons/proper/vfs/trunk/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/url/UrlFileProvider.java?rev=1808381&r1=1808380&r2=1808381&view=diff ============================================================================== --- commons/proper/vfs/trunk/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/url/UrlFileProvider.java (original) +++ commons/proper/vfs/trunk/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/url/UrlFileProvider.java Thu Sep 14 19:26:39 2017 @@ -34,26 +34,19 @@ import org.apache.commons.vfs2.provider. /** * A file provider backed by Java's URL API. */ -public class UrlFileProvider - extends AbstractFileProvider -{ +public class UrlFileProvider extends AbstractFileProvider { /** The provider's capabilities */ - protected static final Collection<Capability> capabilities = - Collections.unmodifiableCollection(Arrays.asList(new Capability[] - { - Capability.READ_CONTENT, - Capability.URI, - Capability.GET_LAST_MODIFIED - })); + protected static final Collection<Capability> capabilities = Collections.unmodifiableCollection( + Arrays.asList(new Capability[] { Capability.READ_CONTENT, Capability.URI, Capability.GET_LAST_MODIFIED })); - public UrlFileProvider() - { + public UrlFileProvider() { super(); setFileNameParser(new UrlFileNameParser()); } /** * Locates a file object, by absolute URI. + * * @param baseFile The base FileObject. * @param uri The uri of the file to locate. * @param fileSystemOptions The FileSystemOptions @@ -61,45 +54,35 @@ public class UrlFileProvider * @throws FileSystemException if an error occurs. */ @Override - public synchronized FileObject findFile(final FileObject baseFile, - final String uri, - final FileSystemOptions fileSystemOptions) - throws FileSystemException - { - try - { + public synchronized FileObject findFile(final FileObject baseFile, final String uri, + final FileSystemOptions fileSystemOptions) throws FileSystemException { + try { final URL url = new URL(uri); final URL rootUrl = new URL(url, "/"); final String key = this.getClass().getName() + rootUrl.toString(); FileSystem fs = findFileSystem(key, fileSystemOptions); - if (fs == null) - { + if (fs == null) { final String extForm = rootUrl.toExternalForm(); - final FileName rootName = - getContext().parseURI(extForm); + final FileName rootName = getContext().parseURI(extForm); // final FileName rootName = - // new BasicFileName(rootUrl, FileName.ROOT_PATH); + // new BasicFileName(rootUrl, FileName.ROOT_PATH); fs = new UrlFileSystem(rootName, fileSystemOptions); addFileSystem(key, fs); } return fs.resolveFile(url.getPath()); - } - catch (final MalformedURLException e) - { + } catch (final MalformedURLException e) { throw new FileSystemException("vfs.provider.url/badly-formed-uri.error", uri, e); } } @Override - public FileSystemConfigBuilder getConfigBuilder() - { + public FileSystemConfigBuilder getConfigBuilder() { return org.apache.commons.vfs2.provider.res.ResourceFileSystemConfigBuilder.getInstance(); } @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/url/UrlFileSystem.java URL: http://svn.apache.org/viewvc/commons/proper/vfs/trunk/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/url/UrlFileSystem.java?rev=1808381&r1=1808380&r2=1808381&view=diff ============================================================================== --- commons/proper/vfs/trunk/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/url/UrlFileSystem.java (original) +++ commons/proper/vfs/trunk/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/url/UrlFileSystem.java Thu Sep 14 19:26:39 2017 @@ -28,11 +28,8 @@ import org.apache.commons.vfs2.provider. /** * A File system backed by Java's URL API. */ -public class UrlFileSystem - extends AbstractFileSystem -{ - protected UrlFileSystem(final FileName rootName, final FileSystemOptions fileSystemOptions) - { +public class UrlFileSystem extends AbstractFileSystem { + protected UrlFileSystem(final FileName rootName, final FileSystemOptions fileSystemOptions) { super(rootName, null, fileSystemOptions); } @@ -40,8 +37,7 @@ public class UrlFileSystem * Creates a file object. */ @Override - protected FileObject createFile(final AbstractFileName name) - { + protected FileObject createFile(final AbstractFileName name) { return new UrlFileObject(this, name); } @@ -49,8 +45,7 @@ public class UrlFileSystem * Returns the capabilities of this file system. */ @Override - protected void addCapabilities(final Collection<Capability> caps) - { + protected void addCapabilities(final Collection<Capability> caps) { caps.addAll(UrlFileProvider.capabilities); } } Modified: commons/proper/vfs/trunk/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/webdav/ExceptionConverter.java URL: http://svn.apache.org/viewvc/commons/proper/vfs/trunk/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/webdav/ExceptionConverter.java?rev=1808381&r1=1808380&r2=1808381&view=diff ============================================================================== --- commons/proper/vfs/trunk/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/webdav/ExceptionConverter.java (original) +++ commons/proper/vfs/trunk/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/webdav/ExceptionConverter.java Thu Sep 14 19:26:39 2017 @@ -27,60 +27,45 @@ import org.w3c.dom.Element; /** * {@code ExceptionConverter} converts WebDAV exceptions into FileSystemExceptions. + * * @since 2.0 */ -public final class ExceptionConverter -{ +public final class ExceptionConverter { // avoid instanciation - private ExceptionConverter() - { + private ExceptionConverter() { } - public static FileSystemException generate(final DavException davExc) throws FileSystemException - { + public static FileSystemException generate(final DavException davExc) throws FileSystemException { return generate(davExc, null); } public static FileSystemException generate(final DavException davExc, final DavMethod method) - throws FileSystemException - { + throws FileSystemException { String msg = davExc.getMessage(); - if (davExc.hasErrorCondition()) - { - try - { + if (davExc.hasErrorCondition()) { + try { final Element error = davExc.toXml(DomUtil.BUILDER_FACTORY.newDocumentBuilder().newDocument()); - if (DomUtil.matches(error, DavException.XML_ERROR, DavConstants.NAMESPACE)) - { - if (DomUtil.hasChildElement(error, "exception", null)) - { + if (DomUtil.matches(error, DavException.XML_ERROR, DavConstants.NAMESPACE)) { + if (DomUtil.hasChildElement(error, "exception", null)) { final Element exc = DomUtil.getChildElement(error, "exception", null); - if (DomUtil.hasChildElement(exc, "message", null)) - { + if (DomUtil.hasChildElement(exc, "message", null)) { msg = DomUtil.getChildText(exc, "message", null); } - if (DomUtil.hasChildElement(exc, "class", null)) - { + if (DomUtil.hasChildElement(exc, "class", null)) { final Class<?> cl = Class.forName(DomUtil.getChildText(exc, "class", null)); - final Constructor<?> excConstr = cl.getConstructor(new Class[]{String.class}); - if (excConstr != null) - { - final Object o = excConstr.newInstance(new Object[]{msg}); - if (o instanceof FileSystemException) - { + final Constructor<?> excConstr = cl.getConstructor(new Class[] { String.class }); + if (excConstr != null) { + final Object o = excConstr.newInstance(new Object[] { msg }); + if (o instanceof FileSystemException) { return (FileSystemException) o; - } - else if (o instanceof Exception) - { + } else if (o instanceof Exception) { return new FileSystemException(msg, (Exception) o); } } } } } - } - catch (final Exception e) - { + } catch (final Exception e) { throw new FileSystemException(e); } } Modified: commons/proper/vfs/trunk/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/webdav/WebdavFileContentInfoFactory.java URL: http://svn.apache.org/viewvc/commons/proper/vfs/trunk/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/webdav/WebdavFileContentInfoFactory.java?rev=1808381&r1=1808380&r2=1808381&view=diff ============================================================================== --- commons/proper/vfs/trunk/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/webdav/WebdavFileContentInfoFactory.java (original) +++ commons/proper/vfs/trunk/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/webdav/WebdavFileContentInfoFactory.java Thu Sep 14 19:26:39 2017 @@ -33,13 +33,10 @@ import org.apache.jackrabbit.webdav.prop * * @since 2.0 */ -public class WebdavFileContentInfoFactory implements FileContentInfoFactory -{ +public class WebdavFileContentInfoFactory implements FileContentInfoFactory { @Override - public FileContentInfo create(final FileContent fileContent) throws FileSystemException - { - final WebdavFileObject file = (WebdavFileObject) FileObjectUtils - .getAbstractFileObject(fileContent.getFile()); + public FileContentInfo create(final FileContent fileContent) throws FileSystemException { + final WebdavFileObject file = (WebdavFileObject) FileObjectUtils.getAbstractFileObject(fileContent.getFile()); String contentType = null; String contentEncoding = null; @@ -49,13 +46,11 @@ public class WebdavFileContentInfoFactor final DavPropertySet propertySet = file.getProperties((URLFileName) file.getName(), nameSet, true); DavProperty property = propertySet.get(DavPropertyName.GETCONTENTTYPE); - if (property != null) - { + if (property != null) { contentType = (String) property.getValue(); } property = propertySet.get(WebdavFileObject.RESPONSE_CHARSET); - if (property != null) - { + if (property != null) { contentEncoding = (String) property.getValue(); } Modified: commons/proper/vfs/trunk/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/webdav/WebdavFileNameParser.java URL: http://svn.apache.org/viewvc/commons/proper/vfs/trunk/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/webdav/WebdavFileNameParser.java?rev=1808381&r1=1808380&r2=1808381&view=diff ============================================================================== --- commons/proper/vfs/trunk/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/webdav/WebdavFileNameParser.java (original) +++ commons/proper/vfs/trunk/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/webdav/WebdavFileNameParser.java Thu Sep 14 19:26:39 2017 @@ -21,19 +21,17 @@ import org.apache.commons.vfs2.provider. /** * Implementation for http. set default port to 80 + * * @since 2.0 */ -public class WebdavFileNameParser extends HttpFileNameParser -{ +public class WebdavFileNameParser extends HttpFileNameParser { private static final WebdavFileNameParser INSTANCE = new WebdavFileNameParser(); - public WebdavFileNameParser() - { + public WebdavFileNameParser() { super(); } - public static FileNameParser getInstance() - { + public static FileNameParser getInstance() { return INSTANCE; } } Modified: commons/proper/vfs/trunk/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/webdav/WebdavFileObject.java URL: http://svn.apache.org/viewvc/commons/proper/vfs/trunk/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/webdav/WebdavFileObject.java?rev=1808381&r1=1808380&r2=1808381&view=diff ============================================================================== --- commons/proper/vfs/trunk/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/webdav/WebdavFileObject.java (original) +++ commons/proper/vfs/trunk/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/webdav/WebdavFileObject.java Thu Sep 14 19:26:39 2017 @@ -77,34 +77,27 @@ import org.w3c.dom.Node; * * @since 2.0 */ -public class WebdavFileObject extends HttpFileObject<WebdavFileSystem> -{ +public class WebdavFileObject extends HttpFileObject<WebdavFileSystem> { /** * An OutputStream that writes to a Webdav resource. * <p> * TODO - Use piped stream to avoid temporary file. */ - private class WebdavOutputStream extends MonitorOutputStream - { + private class WebdavOutputStream extends MonitorOutputStream { private final WebdavFileObject file; - public WebdavOutputStream(final WebdavFileObject file) - { + public WebdavOutputStream(final WebdavFileObject file) { super(new ByteArrayOutputStream()); this.file = file; } - private boolean createVersion(final String urlStr) - { - try - { + private boolean createVersion(final String urlStr) { + try { final VersionControlMethod method = new VersionControlMethod(urlStr); setupMethod(method); execute(method); return true; - } - catch (final Exception ex) - { + } catch (final Exception ex) { return false; } } @@ -113,136 +106,98 @@ public class WebdavFileObject extends Ht * Called after this stream is closed. */ @Override - protected void onClose() throws IOException - { + protected void onClose() throws IOException { final RequestEntity entity = new ByteArrayRequestEntity(((ByteArrayOutputStream) out).toByteArray()); final URLFileName fileName = (URLFileName) getName(); final String urlStr = toUrlString(fileName); - if (builder.isVersioning(getFileSystem().getFileSystemOptions())) - { + if (builder.isVersioning(getFileSystem().getFileSystemOptions())) { DavPropertySet set = null; boolean fileExists = true; boolean isCheckedIn = true; - try - { + try { set = getPropertyNames(fileName); - } - catch (final FileNotFoundException fnfe) - { + } catch (final FileNotFoundException fnfe) { fileExists = false; } - if (fileExists && set != null) - { - if (set.contains(VersionControlledResource.CHECKED_OUT)) - { + if (fileExists && set != null) { + if (set.contains(VersionControlledResource.CHECKED_OUT)) { isCheckedIn = false; - } - else if (!set.contains(VersionControlledResource.CHECKED_IN)) - { + } else if (!set.contains(VersionControlledResource.CHECKED_IN)) { DavProperty prop = set.get(VersionControlledResource.AUTO_VERSION); - if (prop != null) - { + if (prop != null) { prop = getProperty(fileName, VersionControlledResource.AUTO_VERSION); - if (DeltaVConstants.XML_CHECKOUT_CHECKIN.equals(prop.getValue())) - { + if (DeltaVConstants.XML_CHECKOUT_CHECKIN.equals(prop.getValue())) { createVersion(urlStr); } } } } - if (fileExists && isCheckedIn) - { - try - { + if (fileExists && isCheckedIn) { + try { final CheckoutMethod checkout = new CheckoutMethod(urlStr); setupMethod(checkout); execute(checkout); isCheckedIn = false; - } - catch (final FileSystemException ex) - { + } catch (final FileSystemException ex) { // Ignore the exception checking out. } } - try - { + try { final PutMethod method = new PutMethod(urlStr); method.setRequestEntity(entity); setupMethod(method); execute(method); setUserName(fileName, urlStr); - } - catch (final FileSystemException ex) - { - if (!isCheckedIn) - { - try - { + } catch (final FileSystemException ex) { + if (!isCheckedIn) { + try { final UncheckoutMethod method = new UncheckoutMethod(urlStr); setupMethod(method); execute(method); isCheckedIn = true; - } - catch (final Exception e) - { + } catch (final Exception e) { // Ignore the exception. Going to throw original. } throw ex; } } - if (!fileExists) - { + if (!fileExists) { createVersion(urlStr); - try - { + try { final DavPropertySet props = getPropertyNames(fileName); isCheckedIn = !props.contains(VersionControlledResource.CHECKED_OUT); - } - catch (final FileNotFoundException fnfe) - { + } catch (final FileNotFoundException fnfe) { // Ignore the error } } - if (!isCheckedIn) - { - final CheckinMethod checkin = new CheckinMethod(urlStr); - setupMethod(checkin); - execute(checkin); + if (!isCheckedIn) { + final CheckinMethod checkin = new CheckinMethod(urlStr); + setupMethod(checkin); + execute(checkin); } - } - else - { + } else { final PutMethod method = new PutMethod(urlStr); method.setRequestEntity(entity); setupMethod(method); execute(method); - try - { + try { setUserName(fileName, urlStr); - } - catch (final IOException e) - { + } catch (final IOException e) { // Ignore the exception if unable to set the user name. } } ((DefaultFileContent) this.file.getContent()).resetAttributes(); } - private void setUserName(final URLFileName fileName, final String urlStr) - throws IOException - { + private void setUserName(final URLFileName fileName, final String urlStr) throws IOException { final List<DefaultDavProperty> list = new ArrayList<>(); String name = builder.getCreatorName(getFileSystem().getFileSystemOptions()); final String userName = fileName.getUserName(); - if (name == null) - { + if (name == null) { name = userName; - } - else - { - if (userName != null) - { + } else { + if (userName != null) { final String comment = "Modified by user " + userName; list.add(new DefaultDavProperty(DeltaVConstants.COMMENT, comment)); } @@ -255,23 +210,20 @@ public class WebdavFileObject extends Ht } /** The character set property name. */ - public static final DavPropertyName RESPONSE_CHARSET = DavPropertyName.create( - "response-charset"); + public static final DavPropertyName RESPONSE_CHARSET = DavPropertyName.create("response-charset"); /** The FileSystemConfigBuilder */ private final WebdavFileSystemConfigBuilder builder; private final WebdavFileSystem fileSystem; - protected WebdavFileObject(final AbstractFileName name, final WebdavFileSystem fileSystem) - { + protected WebdavFileObject(final AbstractFileName name, final WebdavFileSystem fileSystem) { super(name, fileSystem, WebdavFileSystemConfigBuilder.getInstance()); this.fileSystem = fileSystem; builder = (WebdavFileSystemConfigBuilder) WebdavFileSystemConfigBuilder.getInstance(); } - protected void configureMethod(final HttpMethodBase httpMethod) - { + protected void configureMethod(final HttpMethodBase httpMethod) { httpMethod.getParams().setParameter(HttpMethodParams.RETRY_HANDLER, WebdavMethodRetryHandler.getInstance()); } @@ -279,18 +231,13 @@ public class WebdavFileObject extends Ht * Creates this file as a folder. */ @Override - protected void doCreateFolder() throws Exception - { + protected void doCreateFolder() throws Exception { final DavMethod method = new MkColMethod(toUrlString((URLFileName) getName())); setupMethod(method); - try - { + try { execute(method); - } - catch (final FileSystemException fse) - { - throw new FileSystemException("vfs.provider.webdav/create-collection.error", getName(), - fse); + } catch (final FileSystemException fse) { + throw new FileSystemException("vfs.provider.webdav/create-collection.error", getName(), fse); } } @@ -298,8 +245,7 @@ public class WebdavFileObject extends Ht * Deletes the file. */ @Override - protected void doDelete() throws Exception - { + protected void doDelete() throws Exception { final DavMethod method = new DeleteMethod(toUrlString((URLFileName) getName())); setupMethod(method); execute(method); @@ -309,47 +255,36 @@ public class WebdavFileObject extends Ht * Returns the properties of the Webdav resource. */ @Override - protected Map<String, Object> doGetAttributes() throws Exception - { + protected Map<String, Object> doGetAttributes() throws Exception { final Map<String, Object> attributes = new HashMap<>(); - try - { + try { final URLFileName fileName = (URLFileName) getName(); DavPropertySet properties = getProperties(fileName, DavConstants.PROPFIND_ALL_PROP, new DavPropertyNameSet(), false); @SuppressWarnings("unchecked") // iterator() is documented to return DavProperty instances - final - Iterator<DavProperty> iter = properties.iterator(); - while (iter.hasNext()) - { + final Iterator<DavProperty> iter = properties.iterator(); + while (iter.hasNext()) { final DavProperty property = iter.next(); attributes.put(property.getName().toString(), property.getValue()); } properties = getPropertyNames(fileName); @SuppressWarnings("unchecked") // iterator() is documented to return DavProperty instances - final - Iterator<DavProperty> iter2 = properties.iterator(); - while (iter2.hasNext()) - { + final Iterator<DavProperty> iter2 = properties.iterator(); + while (iter2.hasNext()) { DavProperty property = iter2.next(); - if (!attributes.containsKey(property.getName().getName())) - { + if (!attributes.containsKey(property.getName().getName())) { property = getProperty(fileName, property.getName()); - if (property != null) - { + if (property != null) { final Object name = property.getName(); final Object value = property.getValue(); - if (name != null && value != null) - { + if (name != null && value != null) { attributes.put(name.toString(), value); } } } } return attributes; - } - catch (final Exception e) - { + } catch (final Exception e) { throw new FileSystemException("vfs.provider.webdav/get-attributes.error", getName(), e); } } @@ -358,12 +293,9 @@ public class WebdavFileObject extends Ht * Returns the size of the file content (in bytes). */ @Override - protected long doGetContentSize() throws Exception - { - final DavProperty property = getProperty((URLFileName) getName(), - DavConstants.PROPERTY_GETCONTENTLENGTH); - if (property != null) - { + protected long doGetContentSize() throws Exception { + final DavProperty property = getProperty((URLFileName) getName(), DavConstants.PROPERTY_GETCONTENTLENGTH); + if (property != null) { final String value = (String) property.getValue(); return Long.parseLong(value); } @@ -371,16 +303,13 @@ public class WebdavFileObject extends Ht } /** - * Returns the last modified time of this file. Is only called if - * {@link #doGetType} does not return {@link FileType#IMAGINARY}. + * Returns the last modified time of this file. Is only called if {@link #doGetType} does not return + * {@link FileType#IMAGINARY}. */ @Override - protected long doGetLastModifiedTime() throws Exception - { - final DavProperty property = getProperty((URLFileName) getName(), - DavConstants.PROPERTY_GETLASTMODIFIED); - if (property != null) - { + protected long doGetLastModifiedTime() throws Exception { + final DavProperty property = getProperty((URLFileName) getName(), DavConstants.PROPERTY_GETLASTMODIFIED); + if (property != null) { final String value = (String) property.getValue(); return DateUtil.parseDate(value).getTime(); } @@ -388,36 +317,29 @@ public class WebdavFileObject extends Ht } @Override - protected OutputStream doGetOutputStream(final boolean bAppend) throws Exception - { + protected OutputStream doGetOutputStream(final boolean bAppend) throws Exception { return new WebdavOutputStream(this); } /** - * Determines the type of this file. Must not return null. The return - * value of this method is cached, so the implementation can be expensive. + * Determines the type of this file. Must not return null. The return value of this method is cached, so the + * implementation can be expensive. */ @Override - protected FileType doGetType() throws Exception - { - try - { + protected FileType doGetType() throws Exception { + try { return isDirectory((URLFileName) getName()) ? FileType.FOLDER : FileType.FILE; - } - catch (final FileNotFolderException fnfe) - { + } catch (final FileNotFolderException fnfe) { return FileType.IMAGINARY; - } - catch (final FileNotFoundException fnfe) - { + } catch (final FileNotFoundException fnfe) { return FileType.IMAGINARY; } } /** - * Determines if this file can be written to. Is only called if - * {@link #doGetType} does not return {@link FileType#IMAGINARY}. + * Determines if this file can be written to. Is only called if {@link #doGetType} does not return + * {@link FileType#IMAGINARY}. * <p> * This implementation always returns true. * @@ -425,8 +347,7 @@ public class WebdavFileObject extends Ht * @throws Exception if an error occurs. */ @Override - protected boolean doIsWriteable() throws Exception - { + protected boolean doIsWriteable() throws Exception { return true; } @@ -434,8 +355,7 @@ public class WebdavFileObject extends Ht * Lists the children of the file. */ @Override - protected String[] doListChildren() throws Exception - { + protected String[] doListChildren() throws Exception { // use doListChildrenResolved for performance return null; } @@ -444,41 +364,30 @@ public class WebdavFileObject extends Ht * Lists the children of the file. */ @Override - protected FileObject[] doListChildrenResolved() throws Exception - { + protected FileObject[] doListChildrenResolved() throws Exception { PropFindMethod method = null; - try - { + try { final URLFileName name = (URLFileName) getName(); - if (isDirectory(name)) - { + if (isDirectory(name)) { final DavPropertyNameSet nameSet = new DavPropertyNameSet(); nameSet.add(DavPropertyName.create(DavConstants.PROPERTY_DISPLAYNAME)); - method = new PropFindMethod(toUrlString(name), nameSet, - DavConstants.DEPTH_1); + method = new PropFindMethod(toUrlString(name), nameSet, DavConstants.DEPTH_1); execute(method); final List<WebdavFileObject> vfs = new ArrayList<>(); - if (method.succeeded()) - { - final MultiStatusResponse[] responses = - method.getResponseBodyAsMultiStatus().getResponses(); - - for (final MultiStatusResponse response : responses) - { - if (isCurrentFile(response.getHref(), name)) - { + if (method.succeeded()) { + final MultiStatusResponse[] responses = method.getResponseBodyAsMultiStatus().getResponses(); + + for (final MultiStatusResponse response : responses) { + if (isCurrentFile(response.getHref(), name)) { continue; } final String resourceName = resourceName(response.getHref()); - if (resourceName != null && resourceName.length() > 0) - { - final WebdavFileObject fo = (WebdavFileObject) FileObjectUtils. - getAbstractFileObject(getFileSystem().resolveFile( - getFileSystem().getFileSystemManager(). - resolveName(getName(), resourceName, - NameScope.CHILD))); + if (resourceName != null && resourceName.length() > 0) { + final WebdavFileObject fo = (WebdavFileObject) FileObjectUtils.getAbstractFileObject( + getFileSystem().resolveFile(getFileSystem().getFileSystemManager() + .resolveName(getName(), resourceName, NameScope.CHILD))); vfs.add(fo); } } @@ -486,23 +395,14 @@ public class WebdavFileObject extends Ht return vfs.toArray(new WebdavFileObject[vfs.size()]); } throw new FileNotFolderException(getName()); - } - catch (final FileNotFolderException fnfe) - { + } catch (final FileNotFolderException fnfe) { throw fnfe; - } - catch (final DavException e) - { + } catch (final DavException e) { throw new FileSystemException(e.getMessage(), e); - } - catch (final IOException e) - { + } catch (final IOException e) { throw new FileSystemException(e.getMessage(), e); - } - finally - { - if (method != null) - { + } finally { + if (method != null) { method.releaseConnection(); } } @@ -512,8 +412,7 @@ public class WebdavFileObject extends Ht * Rename the file. */ @Override - protected void doRename(final FileObject newFile) throws Exception - { + protected void doRename(final FileObject newFile) throws Exception { final String url = encodePath(toUrlString((URLFileName) getName())); final String dest = toUrlString((URLFileName) newFile.getName(), false); final DavMethod method = new MoveMethod(url, dest, false); @@ -522,43 +421,31 @@ public class WebdavFileObject extends Ht } /** - * Sets an attribute of this file. Is only called if {@link #doGetType} - * does not return {@link FileType#IMAGINARY}. + * Sets an attribute of this file. Is only called if {@link #doGetType} does not return {@link FileType#IMAGINARY}. */ @Override - protected void doSetAttribute(final String attrName, final Object value) - throws Exception - { - try - { + protected void doSetAttribute(final String attrName, final Object value) throws Exception { + try { final URLFileName fileName = (URLFileName) getName(); final String urlStr = toUrlString(fileName); final DavPropertySet properties = new DavPropertySet(); final DavPropertyNameSet propertyNameSet = new DavPropertyNameSet(); final DavProperty property = new DefaultDavProperty(attrName, value, Namespace.EMPTY_NAMESPACE); - if (value != null) - { + if (value != null) { properties.add(property); - } - else - { + } else { propertyNameSet.add(property.getName()); // remove property } final PropPatchMethod method = new PropPatchMethod(urlStr, properties, propertyNameSet); setupMethod(method); execute(method); - if (!method.succeeded()) - { + if (!method.succeeded()) { throw new FileSystemException("Property '" + attrName + "' could not be set."); } - } - catch (final FileSystemException fse) - { + } catch (final FileSystemException fse) { throw fse; - } - catch (final Exception e) - { + } catch (final Exception e) { throw new FileSystemException("vfs.provider.webdav/set-attributes", e, getName(), attrName); } } @@ -569,113 +456,79 @@ public class WebdavFileObject extends Ht * @param method The DavMethod to invoke. * @throws FileSystemException If an error occurs. */ - private void execute(final DavMethod method) throws FileSystemException - { - try - { + private void execute(final DavMethod method) throws FileSystemException { + try { final int status = fileSystem.getClient().executeMethod(method); - if (status == HttpURLConnection.HTTP_NOT_FOUND - || status == HttpURLConnection.HTTP_GONE) - { + if (status == HttpURLConnection.HTTP_NOT_FOUND || status == HttpURLConnection.HTTP_GONE) { throw new FileNotFoundException(method.getURI()); } method.checkSuccess(); - } - catch (final FileSystemException fse) - { + } catch (final FileSystemException fse) { throw fse; - } - catch (final IOException e) - { + } catch (final IOException e) { throw new FileSystemException(e); - } - catch (final DavException e) - { + } catch (final DavException e) { throw ExceptionConverter.generate(e); - } - finally - { - if (method != null) - { + } finally { + if (method != null) { method.releaseConnection(); } } } @Override - protected FileContentInfoFactory getFileContentInfoFactory() - { + protected FileContentInfoFactory getFileContentInfoFactory() { return new WebdavFileContentInfoFactory(); } - DavPropertySet getProperties(final URLFileName name) throws FileSystemException - { - return getProperties(name, DavConstants.PROPFIND_ALL_PROP, new DavPropertyNameSet(), - false); + DavPropertySet getProperties(final URLFileName name) throws FileSystemException { + return getProperties(name, DavConstants.PROPFIND_ALL_PROP, new DavPropertyNameSet(), false); } DavPropertySet getProperties(final URLFileName name, final DavPropertyNameSet nameSet, final boolean addEncoding) - throws FileSystemException - { + throws FileSystemException { return getProperties(name, DavConstants.PROPFIND_BY_PROPERTY, nameSet, addEncoding); } DavPropertySet getProperties(final URLFileName name, final int type, final DavPropertyNameSet nameSet, - final boolean addEncoding) - throws FileSystemException - { - try - { + final boolean addEncoding) throws FileSystemException { + try { final String urlStr = toUrlString(name); final PropFindMethod method = new PropFindMethod(urlStr, type, nameSet, DavConstants.DEPTH_0); setupMethod(method); execute(method); - if (method.succeeded()) - { + if (method.succeeded()) { final MultiStatus multiStatus = method.getResponseBodyAsMultiStatus(); final MultiStatusResponse response = multiStatus.getResponses()[0]; final DavPropertySet props = response.getProperties(HttpStatus.SC_OK); - if (addEncoding) - { - final DavProperty prop = new DefaultDavProperty(RESPONSE_CHARSET, - method.getResponseCharSet()); + if (addEncoding) { + final DavProperty prop = new DefaultDavProperty(RESPONSE_CHARSET, method.getResponseCharSet()); props.add(prop); } return props; } return new DavPropertySet(); - } - catch (final FileSystemException fse) - { + } catch (final FileSystemException fse) { throw fse; - } - catch (final Exception e) - { + } catch (final Exception e) { throw new FileSystemException("vfs.provider.webdav/get-property.error", e, getName(), name, type, nameSet.getContent(), addEncoding); } } - DavProperty getProperty(final URLFileName fileName, final DavPropertyName name) - throws FileSystemException - { + DavProperty getProperty(final URLFileName fileName, final DavPropertyName name) throws FileSystemException { final DavPropertyNameSet nameSet = new DavPropertyNameSet(); nameSet.add(name); final DavPropertySet propertySet = getProperties(fileName, nameSet, false); return propertySet.get(name); } - DavProperty getProperty(final URLFileName fileName, final String property) - throws FileSystemException - { + DavProperty getProperty(final URLFileName fileName, final String property) throws FileSystemException { return getProperty(fileName, DavPropertyName.create(property)); } - - DavPropertySet getPropertyNames(final URLFileName name) throws FileSystemException - { - return getProperties(name, DavConstants.PROPFIND_PROPERTY_NAMES, - new DavPropertyNameSet(), false); + DavPropertySet getPropertyNames(final URLFileName name) throws FileSystemException { + return getProperties(name, DavConstants.PROPFIND_PROPERTY_NAMES, new DavPropertyNameSet(), false); } /** @@ -684,45 +537,33 @@ public class WebdavFileObject extends Ht * @param name The FileName. * @return The encoded URL String. */ - private String hrefString(final URLFileName name) - { - final URLFileName newFile = new URLFileName("http", name.getHostName(), name.getPort(), - name.getDefaultPort(), null, null, - name.getPath(), name.getType(), name.getQueryString()); - try - { + private String hrefString(final URLFileName name) { + final URLFileName newFile = new URLFileName("http", name.getHostName(), name.getPort(), name.getDefaultPort(), + null, null, name.getPath(), name.getType(), name.getQueryString()); + try { return newFile.getURIEncoded(this.getUrlCharset()); - } - catch (final Exception e) - { + } catch (final Exception e) { return name.getURI(); } } - private boolean isCurrentFile(final String href, final URLFileName fileName) - { + private boolean isCurrentFile(final String href, final URLFileName fileName) { String name = hrefString(fileName); - if (href.endsWith("/") && !name.endsWith("/")) - { + if (href.endsWith("/") && !name.endsWith("/")) { name += "/"; } return href.equals(name) || href.equals(fileName.getPath()); } - private boolean isDirectory(final URLFileName name) throws IOException - { - try - { + private boolean isDirectory(final URLFileName name) throws IOException { + try { final DavProperty property = getProperty(name, DavConstants.PROPERTY_RESOURCETYPE); Node node; - if (property != null && (node = (Node) property.getValue()) != null) - { + if (property != null && (node = (Node) property.getValue()) != null) { return node.getLocalName().equals(DavConstants.XML_COLLECTION); } return false; - } - catch (final FileNotFoundException fse) - { + } catch (final FileNotFoundException fse) { throw new FileNotFolderException(name); } } @@ -733,10 +574,8 @@ public class WebdavFileObject extends Ht * @param path the path to the file. * @return The resource name */ - private String resourceName(String path) - { - if (path.endsWith("/")) - { + private String resourceName(String path) { + if (path.endsWith("/")) { path = path.substring(0, path.length() - 1); } final int i = path.lastIndexOf("/"); @@ -748,11 +587,10 @@ public class WebdavFileObject extends Ht * * @param method the HttpMethod. * @throws FileSystemException if an error occurs encoding the uri. - * @throws URIException if the URI is in error. + * @throws URIException if the URI is in error. */ @Override - protected void setupMethod(final HttpMethod method) throws FileSystemException, URIException - { + protected void setupMethod(final HttpMethod method) throws FileSystemException, URIException { final String pathEncoded = ((URLFileName) getName()).getPathQueryEncoded(this.getUrlCharset()); method.setPath(pathEncoded); method.setFollowRedirects(this.getFollowRedirect()); @@ -763,8 +601,7 @@ public class WebdavFileObject extends Ht method.addRequestHeader("Expires", "0"); } - private String toUrlString(final URLFileName name) - { + private String toUrlString(final URLFileName name) { return toUrlString(name, true); } @@ -775,24 +612,18 @@ public class WebdavFileObject extends Ht * @param includeUserInfo true if user information should be included. * @return The encoded URL String. */ - private String toUrlString(final URLFileName name, final boolean includeUserInfo) - { + private String toUrlString(final URLFileName name, final boolean includeUserInfo) { String user = null; String password = null; - if (includeUserInfo) - { + if (includeUserInfo) { user = name.getUserName(); password = name.getPassword(); } - final URLFileName newFile = new URLFileName("http", name.getHostName(), name.getPort(), - name.getDefaultPort(), user, password, - name.getPath(), name.getType(), name.getQueryString()); - try - { + final URLFileName newFile = new URLFileName("http", name.getHostName(), name.getPort(), name.getDefaultPort(), + user, password, name.getPath(), name.getType(), name.getQueryString()); + try { return newFile.getURIEncoded(this.getUrlCharset()); - } - catch (final Exception e) - { + } catch (final Exception e) { return name.getURI(); } } Modified: commons/proper/vfs/trunk/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/webdav/WebdavFileProvider.java URL: http://svn.apache.org/viewvc/commons/proper/vfs/trunk/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/webdav/WebdavFileProvider.java?rev=1808381&r1=1808380&r2=1808381&view=diff ============================================================================== --- commons/proper/vfs/trunk/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/webdav/WebdavFileProvider.java (original) +++ commons/proper/vfs/trunk/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/webdav/WebdavFileProvider.java Thu Sep 14 19:26:39 2017 @@ -38,83 +38,60 @@ import org.apache.commons.vfs2.util.User * * @since 2.0 */ -public class WebdavFileProvider - extends HttpFileProvider -{ - +public class WebdavFileProvider extends HttpFileProvider { + /** * The authenticator types used by the WebDAV provider. * * @deprecated Might be removed in the next major version. */ @Deprecated - public static final UserAuthenticationData.Type[] AUTHENTICATOR_TYPES = new UserAuthenticationData.Type[] - { - UserAuthenticationData.USERNAME, UserAuthenticationData.PASSWORD - }; - + public static final UserAuthenticationData.Type[] AUTHENTICATOR_TYPES = new UserAuthenticationData.Type[] { + UserAuthenticationData.USERNAME, UserAuthenticationData.PASSWORD }; + /** The capabilities of the WebDAV provider */ - protected static final Collection<Capability> capabilities = - Collections.unmodifiableCollection(Arrays.asList(new Capability[] - { - Capability.CREATE, - Capability.DELETE, - Capability.RENAME, - Capability.GET_TYPE, - Capability.LIST_CHILDREN, - Capability.READ_CONTENT, - Capability.URI, - Capability.WRITE_CONTENT, - Capability.GET_LAST_MODIFIED, - Capability.ATTRIBUTES, - Capability.RANDOM_ACCESS_READ, - Capability.DIRECTORY_READ_CONTENT, - })); + protected static final Collection<Capability> capabilities = Collections + .unmodifiableCollection(Arrays.asList(new Capability[] { Capability.CREATE, Capability.DELETE, + Capability.RENAME, Capability.GET_TYPE, Capability.LIST_CHILDREN, Capability.READ_CONTENT, + Capability.URI, Capability.WRITE_CONTENT, Capability.GET_LAST_MODIFIED, Capability.ATTRIBUTES, + Capability.RANDOM_ACCESS_READ, Capability.DIRECTORY_READ_CONTENT, })); - public WebdavFileProvider() - { + public WebdavFileProvider() { super(); setFileNameParser(WebdavFileNameParser.getInstance()); } + /** * Creates a {@link FileSystem}. * <p> - * If you're looking at this method and wondering how to get a FileSystemOptions - * object bearing the proxy host and credentials configuration through - * to this method so it's used for resolving a - * {@link org.apache.commons.vfs2.FileObject FileObject} in the FileSystem, then be sure - * to use correct signature of the {@link org.apache.commons.vfs2.FileSystemManager FileSystemManager} - * resolveFile method. + * If you're looking at this method and wondering how to get a FileSystemOptions object bearing the proxy host and + * credentials configuration through to this method so it's used for resolving a + * {@link org.apache.commons.vfs2.FileObject FileObject} in the FileSystem, then be sure to use correct signature of + * the {@link org.apache.commons.vfs2.FileSystemManager FileSystemManager} resolveFile method. + * * @see org.apache.commons.vfs2.impl.DefaultFileSystemManager#resolveFile(FileObject, String, FileSystemOptions) */ @Override protected FileSystem doCreateFileSystem(final FileName name, final FileSystemOptions fileSystemOptions) - throws FileSystemException - { + throws FileSystemException { // Create the file system final GenericFileName rootName = (GenericFileName) name; final FileSystemOptions fsOpts = fileSystemOptions == null ? new FileSystemOptions() : fileSystemOptions; UserAuthenticationData authData = null; HttpClient httpClient; - try - { + try { authData = UserAuthenticatorUtils.authenticate(fsOpts, AUTHENTICATOR_TYPES); - httpClient = HttpClientFactory.createConnection( - WebdavFileSystemConfigBuilder.getInstance(), - "http", - rootName.getHostName(), - rootName.getPort(), - UserAuthenticatorUtils.toString(UserAuthenticatorUtils.getData(authData, - UserAuthenticationData.USERNAME, UserAuthenticatorUtils.toChar(rootName.getUserName()))), - UserAuthenticatorUtils.toString(UserAuthenticatorUtils.getData(authData, - UserAuthenticationData.PASSWORD, UserAuthenticatorUtils.toChar(rootName.getPassword()))), - fsOpts); - } - finally - { + httpClient = HttpClientFactory.createConnection(WebdavFileSystemConfigBuilder.getInstance(), "http", + rootName.getHostName(), rootName.getPort(), + UserAuthenticatorUtils.toString(UserAuthenticatorUtils.getData(authData, + UserAuthenticationData.USERNAME, UserAuthenticatorUtils.toChar(rootName.getUserName()))), + UserAuthenticatorUtils.toString(UserAuthenticatorUtils.getData(authData, + UserAuthenticationData.PASSWORD, UserAuthenticatorUtils.toChar(rootName.getPassword()))), + fsOpts); + } finally { UserAuthenticatorUtils.cleanup(authData); } @@ -122,15 +99,12 @@ public class WebdavFileProvider } @Override - public FileSystemConfigBuilder getConfigBuilder() - { + public FileSystemConfigBuilder getConfigBuilder() { return WebdavFileSystemConfigBuilder.getInstance(); } - @Override - public Collection<Capability> getCapabilities() - { + public Collection<Capability> getCapabilities() { return capabilities; } }
