Modified: commons/proper/vfs/trunk/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/gzip/GzipFileSystem.java URL: http://svn.apache.org/viewvc/commons/proper/vfs/trunk/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/gzip/GzipFileSystem.java?rev=1808381&r1=1808380&r2=1808381&view=diff ============================================================================== --- commons/proper/vfs/trunk/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/gzip/GzipFileSystem.java (original) +++ commons/proper/vfs/trunk/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/gzip/GzipFileSystem.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 gzip method. */ -public class GzipFileSystem extends CompressedFileFileSystem -{ +public class GzipFileSystem extends CompressedFileFileSystem { protected GzipFileSystem(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 GzipFileObject(name, getParentLayer(), this); } @Override - protected void addCapabilities(final Collection<Capability> caps) - { + protected void addCapabilities(final Collection<Capability> caps) { caps.addAll(GzipFileProvider.capabilities); } }
Modified: commons/proper/vfs/trunk/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/hdfs/HdfsFileAttributes.java URL: http://svn.apache.org/viewvc/commons/proper/vfs/trunk/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/hdfs/HdfsFileAttributes.java?rev=1808381&r1=1808380&r2=1808381&view=diff ============================================================================== --- commons/proper/vfs/trunk/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/hdfs/HdfsFileAttributes.java (original) +++ commons/proper/vfs/trunk/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/hdfs/HdfsFileAttributes.java Thu Sep 14 19:26:39 2017 @@ -21,8 +21,7 @@ package org.apache.commons.vfs2.provider * * @since 2.1 */ -public enum HdfsFileAttributes -{ +public enum HdfsFileAttributes { /** * Last access time. */ Modified: commons/proper/vfs/trunk/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/hdfs/HdfsFileContentInfoFactory.java URL: http://svn.apache.org/viewvc/commons/proper/vfs/trunk/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/hdfs/HdfsFileContentInfoFactory.java?rev=1808381&r1=1808380&r2=1808381&view=diff ============================================================================== --- commons/proper/vfs/trunk/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/hdfs/HdfsFileContentInfoFactory.java (original) +++ commons/proper/vfs/trunk/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/hdfs/HdfsFileContentInfoFactory.java Thu Sep 14 19:26:39 2017 @@ -27,23 +27,19 @@ import org.apache.commons.vfs2.impl.Defa * * @since 2.1 */ -public class HdfsFileContentInfoFactory implements FileContentInfoFactory -{ +public class HdfsFileContentInfoFactory implements FileContentInfoFactory { private static final String CONTENT = "text/plain"; private static final String ENCODING = "UTF-8"; /** * Creates a FileContentInfo for a the given FileContent. * - * @param fileContent - * Use this FileContent to create a matching FileContentInfo + * @param fileContent Use this FileContent to create a matching FileContentInfo * @return a FileContentInfo for the given FileContent with content set to "text/plain" and encoding set to "UTF-8" - * @throws FileSystemException - * when a problem occurs creating the FileContentInfo. + * @throws FileSystemException when a problem occurs creating the FileContentInfo. */ @Override - public FileContentInfo create(final FileContent fileContent) throws FileSystemException - { + public FileContentInfo create(final FileContent fileContent) throws FileSystemException { return new DefaultFileContentInfo(CONTENT, ENCODING); } Modified: commons/proper/vfs/trunk/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/hdfs/HdfsFileObject.java URL: http://svn.apache.org/viewvc/commons/proper/vfs/trunk/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/hdfs/HdfsFileObject.java?rev=1808381&r1=1808380&r2=1808381&view=diff ============================================================================== --- commons/proper/vfs/trunk/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/hdfs/HdfsFileObject.java (original) +++ commons/proper/vfs/trunk/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/hdfs/HdfsFileObject.java Thu Sep 14 19:26:39 2017 @@ -38,8 +38,7 @@ import org.apache.hadoop.fs.Path; * * @since 2.1 */ -public class HdfsFileObject extends AbstractFileObject<HdfsFileSystem> -{ +public class HdfsFileObject extends AbstractFileObject<HdfsFileSystem> { private final HdfsFileSystem fs; private final FileSystem hdfs; private final Path path; @@ -48,17 +47,13 @@ public class HdfsFileObject extends Abst /** * Constructs a new HDFS FileObject * - * @param name - * FileName - * @param fs - * HdfsFileSystem instance - * @param hdfs - * Hadoop FileSystem instance - * @param p - * Path to the file in HDFS + * @param name FileName + * @param fs HdfsFileSystem instance + * @param hdfs Hadoop FileSystem instance + * @param p Path to the file in HDFS */ - protected HdfsFileObject(final AbstractFileName name, final HdfsFileSystem fs, final FileSystem hdfs, final Path p) - { + protected HdfsFileObject(final AbstractFileName name, final HdfsFileSystem fs, final FileSystem hdfs, + final Path p) { super(name, fs); this.fs = fs; this.hdfs = hdfs; @@ -69,8 +64,7 @@ public class HdfsFileObject extends Abst * @see org.apache.commons.vfs2.provider.AbstractFileObject#canRenameTo(org.apache.commons.vfs2.FileObject) */ @Override - public boolean canRenameTo(final FileObject newfile) - { + public boolean canRenameTo(final FileObject newfile) { throw new UnsupportedOperationException(); } @@ -78,14 +72,10 @@ public class HdfsFileObject extends Abst * @see org.apache.commons.vfs2.provider.AbstractFileObject#doAttach() */ @Override - protected void doAttach() throws Exception - { - try - { + protected void doAttach() throws Exception { + try { this.stat = this.hdfs.getFileStatus(this.path); - } - catch (final FileNotFoundException e) - { + } catch (final FileNotFoundException e) { this.stat = null; return; } @@ -95,10 +85,8 @@ public class HdfsFileObject extends Abst * @see org.apache.commons.vfs2.provider.AbstractFileObject#doGetAttributes() */ @Override - protected Map<String, Object> doGetAttributes() throws Exception - { - if (null == this.stat) - { + protected Map<String, Object> doGetAttributes() throws Exception { + if (null == this.stat) { return super.doGetAttributes(); } final Map<String, Object> attrs = new HashMap<>(); @@ -116,8 +104,7 @@ public class HdfsFileObject extends Abst * @see org.apache.commons.vfs2.provider.AbstractFileObject#doGetContentSize() */ @Override - protected long doGetContentSize() throws Exception - { + protected long doGetContentSize() throws Exception { return stat.getLen(); } @@ -125,8 +112,7 @@ public class HdfsFileObject extends Abst * @see org.apache.commons.vfs2.provider.AbstractFileObject#doGetInputStream() */ @Override - protected InputStream doGetInputStream() throws Exception - { + protected InputStream doGetInputStream() throws Exception { return this.hdfs.open(this.path); } @@ -134,10 +120,8 @@ public class HdfsFileObject extends Abst * @see org.apache.commons.vfs2.provider.AbstractFileObject#doGetLastModifiedTime() */ @Override - protected long doGetLastModifiedTime() throws Exception - { - if (null != this.stat) - { + protected long doGetLastModifiedTime() throws Exception { + if (null != this.stat) { return this.stat.getModificationTime(); } return -1; @@ -148,10 +132,8 @@ public class HdfsFileObject extends Abst * (org.apache.commons.vfs2.util.RandomAccessMode) */ @Override - protected RandomAccessContent doGetRandomAccessContent(final RandomAccessMode mode) throws Exception - { - if (mode.equals(RandomAccessMode.READWRITE)) - { + protected RandomAccessContent doGetRandomAccessContent(final RandomAccessMode mode) throws Exception { + if (mode.equals(RandomAccessMode.READWRITE)) { throw new UnsupportedOperationException(); } return new HdfsRandomAccessContent(this.path, this.hdfs); @@ -161,23 +143,17 @@ public class HdfsFileObject extends Abst * @see org.apache.commons.vfs2.provider.AbstractFileObject#doGetType() */ @Override - protected FileType doGetType() throws Exception - { - try - { + protected FileType doGetType() throws Exception { + try { doAttach(); - if (null == stat) - { + if (null == stat) { return FileType.IMAGINARY; } - if (stat.isDir()) - { + if (stat.isDir()) { return FileType.FOLDER; } return FileType.FILE; - } - catch (final FileNotFoundException fnfe) - { + } catch (final FileNotFoundException fnfe) { return FileType.IMAGINARY; } } @@ -186,8 +162,7 @@ public class HdfsFileObject extends Abst * @see org.apache.commons.vfs2.provider.AbstractFileObject#doIsHidden() */ @Override - protected boolean doIsHidden() throws Exception - { + protected boolean doIsHidden() throws Exception { return false; } @@ -195,8 +170,7 @@ public class HdfsFileObject extends Abst * @see org.apache.commons.vfs2.provider.AbstractFileObject#doIsReadable() */ @Override - protected boolean doIsReadable() throws Exception - { + protected boolean doIsReadable() throws Exception { return true; } @@ -204,8 +178,7 @@ public class HdfsFileObject extends Abst * @see org.apache.commons.vfs2.provider.AbstractFileObject#doIsWriteable() */ @Override - protected boolean doIsWriteable() throws Exception - { + protected boolean doIsWriteable() throws Exception { return false; } @@ -213,18 +186,15 @@ public class HdfsFileObject extends Abst * @see org.apache.commons.vfs2.provider.AbstractFileObject#doListChildren() */ @Override - protected String[] doListChildren() throws Exception - { - if (this.doGetType() != FileType.FOLDER) - { + protected String[] doListChildren() throws Exception { + if (this.doGetType() != FileType.FOLDER) { throw new FileNotFolderException(this); } final FileStatus[] files = this.hdfs.listStatus(this.path); final String[] children = new String[files.length]; int i = 0; - for (final FileStatus status : files) - { + for (final FileStatus status : files) { children[i++] = status.getPath().getName(); } return children; @@ -234,16 +204,13 @@ public class HdfsFileObject extends Abst * @see org.apache.commons.vfs2.provider.AbstractFileObject#doListChildrenResolved() */ @Override - protected FileObject[] doListChildrenResolved() throws Exception - { - if (this.doGetType() != FileType.FOLDER) - { + protected FileObject[] doListChildrenResolved() throws Exception { + if (this.doGetType() != FileType.FOLDER) { return null; } final String[] children = doListChildren(); final FileObject[] fo = new FileObject[children.length]; - for (int i = 0; i < children.length; i++) - { + for (int i = 0; i < children.length; i++) { final Path p = new Path(this.path, children[i]); fo[i] = this.fs.resolveFile(p.toUri().toString()); } @@ -254,8 +221,7 @@ public class HdfsFileObject extends Abst * @see org.apache.commons.vfs2.provider.AbstractFileObject#doRemoveAttribute(java.lang.String) */ @Override - protected void doRemoveAttribute(final String attrName) throws Exception - { + protected void doRemoveAttribute(final String attrName) throws Exception { throw new UnsupportedOperationException(); } @@ -263,8 +229,7 @@ public class HdfsFileObject extends Abst * @see org.apache.commons.vfs2.provider.AbstractFileObject#doSetAttribute(java.lang.String, java.lang.Object) */ @Override - protected void doSetAttribute(final String attrName, final Object value) throws Exception - { + protected void doSetAttribute(final String attrName, final Object value) throws Exception { throw new UnsupportedOperationException(); } @@ -272,8 +237,7 @@ public class HdfsFileObject extends Abst * @see org.apache.commons.vfs2.provider.AbstractFileObject#doSetLastModifiedTime(long) */ @Override - protected boolean doSetLastModifiedTime(final long modtime) throws Exception - { + protected boolean doSetLastModifiedTime(final long modtime) throws Exception { throw new UnsupportedOperationException(); } @@ -282,19 +246,13 @@ public class HdfsFileObject extends Abst * @return boolean true if file exists, false if not */ @Override - public boolean exists() throws FileSystemException - { - try - { + public boolean exists() throws FileSystemException { + try { doAttach(); return this.stat != null; - } - catch (final FileNotFoundException fne) - { + } catch (final FileNotFoundException fne) { return false; - } - catch (final Exception e) - { + } catch (final Exception e) { throw new FileSystemException("Unable to check existance ", e); } } Modified: commons/proper/vfs/trunk/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/hdfs/HdfsFileProvider.java URL: http://svn.apache.org/viewvc/commons/proper/vfs/trunk/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/hdfs/HdfsFileProvider.java?rev=1808381&r1=1808380&r2=1808381&view=diff ============================================================================== --- commons/proper/vfs/trunk/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/hdfs/HdfsFileProvider.java (original) +++ commons/proper/vfs/trunk/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/hdfs/HdfsFileProvider.java Thu Sep 14 19:26:39 2017 @@ -34,60 +34,51 @@ import org.apache.commons.vfs2.provider. * * @since 2.1 */ -public class HdfsFileProvider extends AbstractOriginatingFileProvider -{ - static final Collection<Capability> CAPABILITIES = Collections.unmodifiableCollection(Arrays - .asList(new Capability[] - { - Capability.GET_TYPE, - Capability.READ_CONTENT, - Capability.URI, - Capability.GET_LAST_MODIFIED, - Capability.ATTRIBUTES, - Capability.RANDOM_ACCESS_READ, - Capability.DIRECTORY_READ_CONTENT, - Capability.LIST_CHILDREN })); +public class HdfsFileProvider extends AbstractOriginatingFileProvider { + static final Collection<Capability> CAPABILITIES = Collections + .unmodifiableCollection(Arrays.asList(new Capability[] { Capability.GET_TYPE, Capability.READ_CONTENT, + Capability.URI, Capability.GET_LAST_MODIFIED, Capability.ATTRIBUTES, Capability.RANDOM_ACCESS_READ, + Capability.DIRECTORY_READ_CONTENT, Capability.LIST_CHILDREN })); /** * Constructs a new HdfsFileProvider. */ - public HdfsFileProvider() - { + public HdfsFileProvider() { super(); this.setFileNameParser(HttpFileNameParser.getInstance()); } /** * Create a new HdfsFileSystem instance. + * * @param rootName Name of the root file. * @param fileSystemOptions Configuration options for this instance. * @throws FileSystemException if error occurred. */ @Override protected FileSystem doCreateFileSystem(final FileName rootName, final FileSystemOptions fileSystemOptions) - throws FileSystemException - { + throws FileSystemException { return new HdfsFileSystem(rootName, fileSystemOptions); } /** * Get Capabilities of HdfsFileSystem. + * * @return The capabilities (unmodifiable). */ @Override - public Collection<Capability> getCapabilities() - { + public Collection<Capability> getCapabilities() { return CAPABILITIES; } /** * Return config builder. + * * @return A config builder for HdfsFileSystems. * @see org.apache.commons.vfs2.provider.AbstractFileProvider#getConfigBuilder() */ @Override - public FileSystemConfigBuilder getConfigBuilder() - { + public FileSystemConfigBuilder getConfigBuilder() { return HdfsFileSystemConfigBuilder.getInstance(); } Modified: commons/proper/vfs/trunk/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/hdfs/HdfsFileSystem.java URL: http://svn.apache.org/viewvc/commons/proper/vfs/trunk/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/hdfs/HdfsFileSystem.java?rev=1808381&r1=1808380&r2=1808381&view=diff ============================================================================== --- commons/proper/vfs/trunk/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/hdfs/HdfsFileSystem.java (original) +++ commons/proper/vfs/trunk/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/hdfs/HdfsFileSystem.java Thu Sep 14 19:26:39 2017 @@ -42,8 +42,7 @@ import org.apache.hadoop.fs.Path; * * @since 2.1 */ -public class HdfsFileSystem extends AbstractFileSystem -{ +public class HdfsFileSystem extends AbstractFileSystem { private static final Log log = LogFactory.getLog(HdfsFileSystem.class); private FileSystem fs; @@ -54,8 +53,7 @@ public class HdfsFileSystem extends Abst * @param rootName Name of the root directory of this file system. * @param fileSystemOptions options for this file system instance. */ - protected HdfsFileSystem(final FileName rootName, final FileSystemOptions fileSystemOptions) - { + protected HdfsFileSystem(final FileName rootName, final FileSystemOptions fileSystemOptions) { super(rootName, null, fileSystemOptions); } @@ -63,8 +61,7 @@ public class HdfsFileSystem extends Abst * @see org.apache.commons.vfs2.provider.AbstractFileSystem#addCapabilities(Collection) */ @Override - protected void addCapabilities(final Collection<Capability> capabilities) - { + protected void addCapabilities(final Collection<Capability> capabilities) { capabilities.addAll(HdfsFileProvider.CAPABILITIES); } @@ -72,17 +69,12 @@ public class HdfsFileSystem extends Abst * @see org.apache.commons.vfs2.provider.AbstractFileSystem#close() */ @Override - public void close() - { - try - { - if (null != fs) - { + public void close() { + try { + if (null != fs) { fs.close(); } - } - catch (final IOException e) - { + } catch (final IOException e) { throw new RuntimeException("Error closing HDFS client", e); } super.close(); @@ -92,24 +84,21 @@ public class HdfsFileSystem extends Abst * @see org.apache.commons.vfs2.provider.AbstractFileSystem#createFile(AbstractFileName) */ @Override - protected FileObject createFile(final AbstractFileName name) throws Exception - { + protected FileObject createFile(final AbstractFileName name) throws Exception { throw new FileSystemException("Operation not supported"); } /** * Resolve FileName into FileObject. + * * @param name The name of a file on the HdfsFileSystem. * @return resolved FileObject. * @throws FileSystemException if an error occurred. */ @Override - public FileObject resolveFile(final FileName name) throws FileSystemException - { - synchronized (this) - { - if (this.fs == null) - { + public FileObject resolveFile(final FileName name) throws FileSystemException { + synchronized (this) { + if (this.fs == null) { final String hdfsUri = name.getRootURI(); final HdfsFileSystemConfigBuilder builder = HdfsFileSystemConfigBuilder.getInstance(); final FileSystemOptions options = getFileSystemOptions(); @@ -124,47 +113,36 @@ public class HdfsFileSystem extends Abst // Load any alternate configuration parameters that may have been specified // no matter where they might come from - if (configNames != null) - { - for (final String configName : configNames) - { + if (configNames != null) { + for (final String configName : configNames) { log.debug("Adding HDFS configuration resource: " + configName); conf.addResource(configName); } } - if (configPaths != null) - { - for (final Path path : configPaths) - { + if (configPaths != null) { + for (final Path path : configPaths) { log.debug("Adding HDFS configuration path: " + path); conf.addResource(path); } } - if (configURLs != null) - { - for (final URL url : configURLs) - { + if (configURLs != null) { + for (final URL url : configURLs) { log.debug("Adding HDFS configuration URL: " + url); conf.addResource(url); } } - if (configStream != null) - { + if (configStream != null) { log.debug("Adding HDFS configuration stream"); conf.addResource(configStream); } - if (configConfiguration != null) - { + if (configConfiguration != null) { log.debug("Adding HDFS configuration object"); conf.addResource(configConfiguration); } - try - { + try { fs = FileSystem.get(conf); - } - catch (final IOException e) - { + } catch (final IOException e) { log.error("Error connecting to filesystem " + hdfsUri, e); throw new FileSystemException("Error connecting to filesystem " + hdfsUri, e); } @@ -173,37 +151,28 @@ public class HdfsFileSystem extends Abst final boolean useCache = null != getContext().getFileSystemManager().getFilesCache(); FileObject file; - if (useCache) - { + if (useCache) { file = this.getFileFromCache(name); - } - else - { + } else { file = null; } - if (null == file) - { + if (null == file) { String path = null; - try - { + try { path = URLDecoder.decode(name.getPath(), "UTF-8"); - } - catch (final UnsupportedEncodingException e) - { + } catch (final UnsupportedEncodingException e) { path = name.getPath(); } final Path filePath = new Path(path); file = new HdfsFileObject((AbstractFileName) name, this, fs, filePath); - if (useCache) - { + if (useCache) { this.putFileToCache(file); } } /** * resync the file information if requested */ - if (getFileSystemManager().getCacheStrategy().equals(CacheStrategy.ON_RESOLVE)) - { + if (getFileSystemManager().getCacheStrategy().equals(CacheStrategy.ON_RESOLVE)) { file.refresh(); } return file; Modified: commons/proper/vfs/trunk/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/hdfs/HdfsFileSystemConfigBuilder.java URL: http://svn.apache.org/viewvc/commons/proper/vfs/trunk/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/hdfs/HdfsFileSystemConfigBuilder.java?rev=1808381&r1=1808380&r2=1808381&view=diff ============================================================================== --- commons/proper/vfs/trunk/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/hdfs/HdfsFileSystemConfigBuilder.java (original) +++ commons/proper/vfs/trunk/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/hdfs/HdfsFileSystemConfigBuilder.java Thu Sep 14 19:26:39 2017 @@ -30,25 +30,22 @@ import org.apache.hadoop.fs.Path; * * @since 2.1 */ -public final class HdfsFileSystemConfigBuilder extends FileSystemConfigBuilder -{ +public final class HdfsFileSystemConfigBuilder extends FileSystemConfigBuilder { private static final HdfsFileSystemConfigBuilder BUILDER = new HdfsFileSystemConfigBuilder(); - private static final String KEY_CONFIG_NAMES = "configNames"; - private static final String KEY_CONFIG_PATHS = "configPaths"; - private static final String KEY_CONFIG_URLS = "configURLs"; + private static final String KEY_CONFIG_NAMES = "configNames"; + private static final String KEY_CONFIG_PATHS = "configPaths"; + private static final String KEY_CONFIG_URLS = "configURLs"; private static final String KEY_CONFIG_STREAM = "configStream"; - private static final String KEY_CONFIG_CONF = "configConf"; + private static final String KEY_CONFIG_CONF = "configConf"; - private HdfsFileSystemConfigBuilder() - { + private HdfsFileSystemConfigBuilder() { super("hdfs."); } /** * @return HdfsFileSystemConfigBuilder instance */ - public static HdfsFileSystemConfigBuilder getInstance() - { + public static HdfsFileSystemConfigBuilder getInstance() { return BUILDER; } @@ -56,8 +53,7 @@ public final class HdfsFileSystemConfigB * @return HDFSFileSystem */ @Override - protected Class<? extends FileSystem> getConfigClass() - { + protected Class<? extends FileSystem> getConfigClass() { return HdfsFileSystem.class; } @@ -68,8 +64,7 @@ public final class HdfsFileSystemConfigB * @param opts The FileSystemOptions. * @see #setConfigName(FileSystemOptions, String) */ - public String[] getConfigNames(final FileSystemOptions opts) - { + public String[] getConfigNames(final FileSystemOptions opts) { final String names = this.getString(opts, KEY_CONFIG_NAMES); return names == null || names.isEmpty() ? null : names.split(","); } @@ -77,40 +72,32 @@ public final class HdfsFileSystemConfigB /** * Sets the name of configuration resource to be loaded after the defaults. * <p> - * Specifies the name of a config resource to override any specific HDFS settings. - * The property will be passed on to {@code org.apache.hadoop.conf.Configuration#addResource(String)} - * after the URL was set as the default name with: {@code Configuration#set(FileSystem.FS_DEFAULT_NAME_KEY, url)}. - * <p> - * One use for this is to set a different value for the {@code dfs.client.use.datanode.hostname} - * property in order to access HDFS files stored in an AWS installation (from outside their - * firewall). There are other possible uses too. + * Specifies the name of a config resource to override any specific HDFS settings. The property will be passed on to + * {@code org.apache.hadoop.conf.Configuration#addResource(String)} after the URL was set as the default name with: + * {@code Configuration#set(FileSystem.FS_DEFAULT_NAME_KEY, url)}. + * <p> + * One use for this is to set a different value for the {@code dfs.client.use.datanode.hostname} property in order + * to access HDFS files stored in an AWS installation (from outside their firewall). There are other possible uses + * too. * <p> - * This method may be called multiple times and all the specified resources will be loaded - * in the order they were specified. + * This method may be called multiple times and all the specified resources will be loaded in the order they were + * specified. * <p> - * Note also, that if a list of names is provided, separated by commas ({@code ","}), that - * this will work the same as calling this method a number of times with just one name each. + * Note also, that if a list of names is provided, separated by commas ({@code ","}), that this will work the same + * as calling this method a number of times with just one name each. * * @param opts The FileSystemOptions to modify. - * @param name resource name of additional configuration or {@code null} to unset all the - * values set so far. + * @param name resource name of additional configuration or {@code null} to unset all the values set so far. * @see #getConfigNames */ - public void setConfigName(final FileSystemOptions opts, final String name) - { - if (name == null || name.isEmpty()) - { + public void setConfigName(final FileSystemOptions opts, final String name) { + if (name == null || name.isEmpty()) { this.setParam(opts, KEY_CONFIG_NAMES, null); - } - else - { + } else { final String previousNames = this.getString(opts, KEY_CONFIG_NAMES); - if (previousNames == null || previousNames.isEmpty()) - { + if (previousNames == null || previousNames.isEmpty()) { this.setParam(opts, KEY_CONFIG_NAMES, name); - } - else - { + } else { this.setParam(opts, KEY_CONFIG_NAMES, previousNames + "," + name); } } @@ -123,17 +110,14 @@ public final class HdfsFileSystemConfigB * @param opts The FileSystemOptions. * @see #setConfigPath(FileSystemOptions, Path) */ - public Path[] getConfigPaths(final FileSystemOptions opts) - { + public Path[] getConfigPaths(final FileSystemOptions opts) { final String pathNames = this.getString(opts, KEY_CONFIG_PATHS); - if (pathNames == null || pathNames.isEmpty()) - { + if (pathNames == null || pathNames.isEmpty()) { return null; } final String[] paths = pathNames.split(","); final Path[] realPaths = new Path[paths.length]; - for (int i = 0; i < paths.length; i++) - { + for (int i = 0; i < paths.length; i++) { realPaths[i] = new Path(paths[i]); } return realPaths; @@ -142,36 +126,29 @@ public final class HdfsFileSystemConfigB /** * Sets the full path of configuration file to be loaded after the defaults. * <p> - * Specifies the path of a local file system config file to override any specific HDFS settings. - * The property will be passed on to {@code org.apache.hadoop.conf.Configuration#addResource(Path)} - * after the URL was set as the default name with: {@code Configuration#set(FileSystem.FS_DEFAULT_NAME_KEY, url)}. - * <p> - * One use for this is to set a different value for the {@code dfs.client.use.datanode.hostname} - * property in order to access HDFS files stored in an AWS installation (from outside their - * firewall). There are other possible uses too. + * Specifies the path of a local file system config file to override any specific HDFS settings. The property will + * be passed on to {@code org.apache.hadoop.conf.Configuration#addResource(Path)} after the URL was set as the + * default name with: {@code Configuration#set(FileSystem.FS_DEFAULT_NAME_KEY, url)}. + * <p> + * One use for this is to set a different value for the {@code dfs.client.use.datanode.hostname} property in order + * to access HDFS files stored in an AWS installation (from outside their firewall). There are other possible uses + * too. * <p> - * This method may be called multiple times and all the specified resources will be loaded - * in the order they were specified. + * This method may be called multiple times and all the specified resources will be loaded in the order they were + * specified. * * @param opts The FileSystemOptions to modify. - * @param path full path of additional configuration file (local file system) or {@code null} - * to unset all the path values set so far. + * @param path full path of additional configuration file (local file system) or {@code null} to unset all the path + * values set so far. */ - public void setConfigPath(final FileSystemOptions opts, final Path path) - { - if (path == null) - { + public void setConfigPath(final FileSystemOptions opts, final Path path) { + if (path == null) { this.setParam(opts, KEY_CONFIG_PATHS, null); - } - else - { + } else { final String previousPathNames = this.getString(opts, KEY_CONFIG_PATHS); - if (previousPathNames == null || previousPathNames.isEmpty()) - { + if (previousPathNames == null || previousPathNames.isEmpty()) { this.setParam(opts, KEY_CONFIG_PATHS, path.toString()); - } - else - { + } else { this.setParam(opts, KEY_CONFIG_PATHS, previousPathNames + "," + path.toString()); } } @@ -184,25 +161,19 @@ public final class HdfsFileSystemConfigB * @param opts The FileSystemOptions. * @see #setConfigURL(FileSystemOptions, URL) */ - public URL[] getConfigURLs(final FileSystemOptions opts) - { - try - { + public URL[] getConfigURLs(final FileSystemOptions opts) { + try { final String urlNames = this.getString(opts, KEY_CONFIG_URLS); - if (urlNames == null || urlNames.isEmpty()) - { + if (urlNames == null || urlNames.isEmpty()) { return null; } final String[] urls = urlNames.split(","); final URL[] realURLs = new URL[urls.length]; - for (int i = 0; i < urls.length; i++) - { + for (int i = 0; i < urls.length; i++) { realURLs[i] = new URL(urls[i]); } return realURLs; - } - catch (final MalformedURLException mue) - { + } catch (final MalformedURLException mue) { // This should never happen because we save it in the proper form } return null; @@ -211,36 +182,28 @@ public final class HdfsFileSystemConfigB /** * Sets the URL of configuration file to be loaded after the defaults. * <p> - * Specifies the URL of a config file to override any specific HDFS settings. - * The property will be passed on to {@code org.apache.hadoop.conf.Configuration#addResource(URL)} - * after the URL was set as the default name with: {@code Configuration#set(FileSystem.FS_DEFAULT_NAME_KEY, url)}. - * <p> - * One use for this is to set a different value for the {@code dfs.client.use.datanode.hostname} - * property in order to access HDFS files stored in an AWS installation (from outside their - * firewall). There are other possible uses too. + * Specifies the URL of a config file to override any specific HDFS settings. The property will be passed on to + * {@code org.apache.hadoop.conf.Configuration#addResource(URL)} after the URL was set as the default name with: + * {@code Configuration#set(FileSystem.FS_DEFAULT_NAME_KEY, url)}. + * <p> + * One use for this is to set a different value for the {@code dfs.client.use.datanode.hostname} property in order + * to access HDFS files stored in an AWS installation (from outside their firewall). There are other possible uses + * too. * <p> - * This method may be called multiple times and all the specified resources will be loaded - * in the order they were specified. + * This method may be called multiple times and all the specified resources will be loaded in the order they were + * specified. * * @param opts The FileSystemOptions to modify. - * @param url URL of additional configuration file or {@code null} to unset all the URL - * values set so far. + * @param url URL of additional configuration file or {@code null} to unset all the URL values set so far. */ - public void setConfigURL(final FileSystemOptions opts, final URL url) - { - if (url == null) - { + public void setConfigURL(final FileSystemOptions opts, final URL url) { + if (url == null) { this.setParam(opts, KEY_CONFIG_URLS, null); - } - else - { + } else { final String previousURLNames = this.getString(opts, KEY_CONFIG_URLS); - if (previousURLNames == null || previousURLNames.isEmpty()) - { + if (previousURLNames == null || previousURLNames.isEmpty()) { this.setParam(opts, KEY_CONFIG_URLS, url.toString()); - } - else - { + } else { this.setParam(opts, KEY_CONFIG_URLS, previousURLNames + "," + url.toString()); } } @@ -253,28 +216,26 @@ public final class HdfsFileSystemConfigB * @param opts The FileSystemOptions. * @see #setConfigInputStream(FileSystemOptions, InputStream) */ - public InputStream getConfigInputStream(final FileSystemOptions opts) - { - return (InputStream)this.getParam(opts, KEY_CONFIG_STREAM); + public InputStream getConfigInputStream(final FileSystemOptions opts) { + return (InputStream) this.getParam(opts, KEY_CONFIG_STREAM); } /** * Sets the input stream of configuration file to be loaded after the defaults. * <p> - * Specifies an input stream connected to a config file to override any specific HDFS settings. - * The property will be passed on to {@code org.apache.hadoop.conf.Configuration#addResource(InputStream)} - * after the URL was set as the default name with: {@code Configuration#set(FileSystem.FS_DEFAULT_NAME_KEY, url)}. - * <p> - * One use for this is to set a different value for the {@code dfs.client.use.datanode.hostname} - * property in order to access HDFS files stored in an AWS installation (from outside their - * firewall). There are other possible uses too. + * Specifies an input stream connected to a config file to override any specific HDFS settings. The property will be + * passed on to {@code org.apache.hadoop.conf.Configuration#addResource(InputStream)} after the URL was set as the + * default name with: {@code Configuration#set(FileSystem.FS_DEFAULT_NAME_KEY, url)}. + * <p> + * One use for this is to set a different value for the {@code dfs.client.use.datanode.hostname} property in order + * to access HDFS files stored in an AWS installation (from outside their firewall). There are other possible uses + * too. * * @param opts The FileSystemOptions to modify. - * @param inputStream input stream of additional configuration file or {@code null} to unset - * the configuration input stream previously set up. + * @param inputStream input stream of additional configuration file or {@code null} to unset the configuration input + * stream previously set up. */ - public void setConfigInputStream(final FileSystemOptions opts, final InputStream inputStream) - { + public void setConfigInputStream(final FileSystemOptions opts, final InputStream inputStream) { this.setParam(opts, KEY_CONFIG_STREAM, inputStream); } @@ -285,28 +246,26 @@ public final class HdfsFileSystemConfigB * @param opts The FileSystemOptions. * @see #setConfigConfiguration(FileSystemOptions, Configuration) */ - public Configuration getConfigConfiguration(final FileSystemOptions opts) - { - return (Configuration)this.getParam(opts, KEY_CONFIG_CONF); + public Configuration getConfigConfiguration(final FileSystemOptions opts) { + return (Configuration) this.getParam(opts, KEY_CONFIG_CONF); } /** * Sets the configuration object to be loaded after the defaults. * <p> - * Specifies an already initialized configuration object to override any specific HDFS settings. - * The property will be passed on to {@code org.apache.hadoop.conf.Configuration#addResource(Configuration)} - * after the URL was set as the default name with: {@code Configuration#set(FileSystem.FS_DEFAULT_NAME_KEY, url)}. - * <p> - * One use for this is to set a different value for the {@code dfs.client.use.datanode.hostname} - * property in order to access HDFS files stored in an AWS installation (from outside their - * firewall). There are other possible uses too. + * Specifies an already initialized configuration object to override any specific HDFS settings. The property will + * be passed on to {@code org.apache.hadoop.conf.Configuration#addResource(Configuration)} after the URL was set as + * the default name with: {@code Configuration#set(FileSystem.FS_DEFAULT_NAME_KEY, url)}. + * <p> + * One use for this is to set a different value for the {@code dfs.client.use.datanode.hostname} property in order + * to access HDFS files stored in an AWS installation (from outside their firewall). There are other possible uses + * too. * * @param opts The FileSystemOptions to modify. - * @param configuration additional configuration object or {@code null} to unset any configuration - * object previously set. + * @param configuration additional configuration object or {@code null} to unset any configuration object previously + * set. */ - public void setConfigConfiguration(final FileSystemOptions opts, final Configuration configuration) - { + public void setConfigConfiguration(final FileSystemOptions opts, final Configuration configuration) { this.setParam(opts, KEY_CONFIG_CONF, configuration); } Modified: commons/proper/vfs/trunk/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/hdfs/HdfsRandomAccessContent.java URL: http://svn.apache.org/viewvc/commons/proper/vfs/trunk/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/hdfs/HdfsRandomAccessContent.java?rev=1808381&r1=1808380&r2=1808381&view=diff ============================================================================== --- commons/proper/vfs/trunk/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/hdfs/HdfsRandomAccessContent.java (original) +++ commons/proper/vfs/trunk/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/hdfs/HdfsRandomAccessContent.java Thu Sep 14 19:26:39 2017 @@ -31,8 +31,7 @@ import org.apache.hadoop.fs.Path; * * @since 2.1 */ -public class HdfsRandomAccessContent extends AbstractRandomAccessContent -{ +public class HdfsRandomAccessContent extends AbstractRandomAccessContent { private final FSDataInputStream fis; private final FileSystem fs; private final Path path; @@ -44,8 +43,7 @@ public class HdfsRandomAccessContent ext * @param fs A Hadoop FileSystem * @throws IOException when the path cannot be processed. */ - public HdfsRandomAccessContent(final Path path, final FileSystem fs) throws IOException - { + public HdfsRandomAccessContent(final Path path, final FileSystem fs) throws IOException { super(RandomAccessMode.READ); this.fs = fs; this.path = path; @@ -56,8 +54,7 @@ public class HdfsRandomAccessContent ext * @see org.apache.commons.vfs2.RandomAccessContent#close() */ @Override - public void close() throws IOException - { + public void close() throws IOException { this.fis.close(); } @@ -65,8 +62,7 @@ public class HdfsRandomAccessContent ext * @see org.apache.commons.vfs2.RandomAccessContent#getFilePointer() */ @Override - public long getFilePointer() throws IOException - { + public long getFilePointer() throws IOException { return this.fis.getPos(); } @@ -74,8 +70,7 @@ public class HdfsRandomAccessContent ext * @see org.apache.commons.vfs2.RandomAccessContent#getInputStream() */ @Override - public InputStream getInputStream() throws IOException - { + public InputStream getInputStream() throws IOException { return this.fis; } @@ -83,8 +78,7 @@ public class HdfsRandomAccessContent ext * @see org.apache.commons.vfs2.RandomAccessContent#length() */ @Override - public long length() throws IOException - { + public long length() throws IOException { return this.fs.getFileStatus(this.path).getLen(); } @@ -92,8 +86,7 @@ public class HdfsRandomAccessContent ext * @see java.io.DataInput#readBoolean() */ @Override - public boolean readBoolean() throws IOException - { + public boolean readBoolean() throws IOException { return this.fis.readBoolean(); } @@ -101,8 +94,7 @@ public class HdfsRandomAccessContent ext * @see java.io.DataInput#readByte() */ @Override - public byte readByte() throws IOException - { + public byte readByte() throws IOException { return this.fis.readByte(); } @@ -110,8 +102,7 @@ public class HdfsRandomAccessContent ext * @see java.io.DataInput#readChar() */ @Override - public char readChar() throws IOException - { + public char readChar() throws IOException { return this.fis.readChar(); } @@ -119,8 +110,7 @@ public class HdfsRandomAccessContent ext * @see java.io.DataInput#readDouble() */ @Override - public double readDouble() throws IOException - { + public double readDouble() throws IOException { return this.fis.readDouble(); } @@ -128,8 +118,7 @@ public class HdfsRandomAccessContent ext * @see java.io.DataInput#readFloat() */ @Override - public float readFloat() throws IOException - { + public float readFloat() throws IOException { return this.fis.readFloat(); } @@ -137,8 +126,7 @@ public class HdfsRandomAccessContent ext * @see java.io.DataInput#readFully(byte[]) */ @Override - public void readFully(final byte[] b) throws IOException - { + public void readFully(final byte[] b) throws IOException { throw new UnsupportedOperationException(); } @@ -146,8 +134,7 @@ public class HdfsRandomAccessContent ext * @see java.io.DataInput#readFully(byte[], int, int) */ @Override - public void readFully(final byte[] b, final int off, final int len) throws IOException - { + public void readFully(final byte[] b, final int off, final int len) throws IOException { throw new UnsupportedOperationException(); } @@ -155,8 +142,7 @@ public class HdfsRandomAccessContent ext * @see java.io.DataInput#readInt() */ @Override - public int readInt() throws IOException - { + public int readInt() throws IOException { return this.fis.readInt(); } @@ -165,8 +151,7 @@ public class HdfsRandomAccessContent ext */ @Override @SuppressWarnings("deprecation") - public String readLine() throws IOException - { + public String readLine() throws IOException { return this.fis.readLine(); } @@ -174,8 +159,7 @@ public class HdfsRandomAccessContent ext * @see java.io.DataInput#readLong() */ @Override - public long readLong() throws IOException - { + public long readLong() throws IOException { return this.fis.readLong(); } @@ -183,8 +167,7 @@ public class HdfsRandomAccessContent ext * @see java.io.DataInput#readShort() */ @Override - public short readShort() throws IOException - { + public short readShort() throws IOException { return this.fis.readShort(); } @@ -192,8 +175,7 @@ public class HdfsRandomAccessContent ext * @see java.io.DataInput#readUnsignedByte() */ @Override - public int readUnsignedByte() throws IOException - { + public int readUnsignedByte() throws IOException { return this.fis.readUnsignedByte(); } @@ -201,8 +183,7 @@ public class HdfsRandomAccessContent ext * @see java.io.DataInput#readUnsignedShort() */ @Override - public int readUnsignedShort() throws IOException - { + public int readUnsignedShort() throws IOException { return this.fis.readUnsignedShort(); } @@ -210,8 +191,7 @@ public class HdfsRandomAccessContent ext * @see java.io.DataInput#readUTF() */ @Override - public String readUTF() throws IOException - { + public String readUTF() throws IOException { return this.fis.readUTF(); } @@ -219,8 +199,7 @@ public class HdfsRandomAccessContent ext * @see org.apache.commons.vfs2.RandomAccessContent#seek(long) */ @Override - public void seek(final long pos) throws IOException - { + public void seek(final long pos) throws IOException { this.fis.seek(pos); } @@ -228,8 +207,7 @@ public class HdfsRandomAccessContent ext * @see org.apache.commons.vfs2.RandomAccessContent#setLength(long) */ @Override - public void setLength(final long newLength) throws IOException - { + public void setLength(final long newLength) throws IOException { throw new UnsupportedOperationException(); } @@ -237,8 +215,7 @@ public class HdfsRandomAccessContent ext * @see java.io.DataInput#skipBytes(int) */ @Override - public int skipBytes(final int n) throws IOException - { + public int skipBytes(final int n) throws IOException { throw new UnsupportedOperationException(); } Modified: commons/proper/vfs/trunk/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/http/HttpClientFactory.java URL: http://svn.apache.org/viewvc/commons/proper/vfs/trunk/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/http/HttpClientFactory.java?rev=1808381&r1=1808380&r2=1808381&view=diff ============================================================================== --- commons/proper/vfs/trunk/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/http/HttpClientFactory.java (original) +++ commons/proper/vfs/trunk/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/http/HttpClientFactory.java Thu Sep 14 19:26:39 2017 @@ -34,23 +34,20 @@ import org.apache.commons.vfs2.util.User /** * Create a HttpClient instance. */ -public final class HttpClientFactory -{ - private HttpClientFactory() - { +public final class HttpClientFactory { + private HttpClientFactory() { } public static HttpClient createConnection(final String scheme, final String hostname, final int port, - final String username, final String password, - final FileSystemOptions fileSystemOptions) - throws FileSystemException - { - return createConnection(HttpFileSystemConfigBuilder.getInstance(), scheme, hostname, port, - username, password, fileSystemOptions); + final String username, final String password, final FileSystemOptions fileSystemOptions) + throws FileSystemException { + return createConnection(HttpFileSystemConfigBuilder.getInstance(), scheme, hostname, port, username, password, + fileSystemOptions); } /** * Creates a new connection to the server. + * * @param builder The HttpFileSystemConfigBuilder. * @param scheme The protocol. * @param hostname The hostname. @@ -63,13 +60,10 @@ public final class HttpClientFactory * @since 2.0 */ public static HttpClient createConnection(final HttpFileSystemConfigBuilder builder, final String scheme, - final String hostname, final int port, final String username, - final String password, final FileSystemOptions fileSystemOptions) - throws FileSystemException - { + final String hostname, final int port, final String username, final String password, + final FileSystemOptions fileSystemOptions) throws FileSystemException { HttpClient client; - try - { + try { final HttpConnectionManager mgr = new MultiThreadedHttpConnectionManager(); final HttpConnectionManagerParams connectionMgrParams = mgr.getParams(); @@ -78,41 +72,32 @@ public final class HttpClientFactory final HostConfiguration config = new HostConfiguration(); config.setHost(hostname, port, scheme); - if (fileSystemOptions != null) - { + if (fileSystemOptions != null) { final String proxyHost = builder.getProxyHost(fileSystemOptions); final int proxyPort = builder.getProxyPort(fileSystemOptions); - if (proxyHost != null && proxyHost.length() > 0 && proxyPort > 0) - { + if (proxyHost != null && proxyHost.length() > 0 && proxyPort > 0) { config.setProxy(proxyHost, proxyPort); } final UserAuthenticator proxyAuth = builder.getProxyAuthenticator(fileSystemOptions); - if (proxyAuth != null) - { + if (proxyAuth != null) { final UserAuthenticationData authData = UserAuthenticatorUtils.authenticate(proxyAuth, - new UserAuthenticationData.Type[] - { - UserAuthenticationData.USERNAME, - UserAuthenticationData.PASSWORD - }); - - if (authData != null) - { - final UsernamePasswordCredentials proxyCreds = - new UsernamePasswordCredentials( + new UserAuthenticationData.Type[] { UserAuthenticationData.USERNAME, + UserAuthenticationData.PASSWORD }); + + if (authData != null) { + final UsernamePasswordCredentials proxyCreds = new UsernamePasswordCredentials( UserAuthenticatorUtils.toString(UserAuthenticatorUtils.getData(authData, - UserAuthenticationData.USERNAME, null)), + UserAuthenticationData.USERNAME, null)), UserAuthenticatorUtils.toString(UserAuthenticatorUtils.getData(authData, - UserAuthenticationData.PASSWORD, null))); + UserAuthenticationData.PASSWORD, null))); final AuthScope scope = new AuthScope(proxyHost, AuthScope.ANY_PORT); client.getState().setProxyCredentials(scope, proxyCreds); } - if (builder.isPreemptiveAuth(fileSystemOptions)) - { + if (builder.isPreemptiveAuth(fileSystemOptions)) { final HttpClientParams httpClientParams = new HttpClientParams(); httpClientParams.setAuthenticationPreemptive(true); client.setParams(httpClientParams); @@ -120,15 +105,14 @@ public final class HttpClientFactory } final Cookie[] cookies = builder.getCookies(fileSystemOptions); - if (cookies != null) - { + if (cookies != null) { client.getState().addCookies(cookies); } } /** - * ConnectionManager set methods must be called after the host & port and proxy host & port - * are set in the HostConfiguration. They are all used as part of the key when HttpConnectionManagerParams - * tries to locate the host configuration. + * ConnectionManager set methods must be called after the host & port and proxy host & port are set in the + * HostConfiguration. They are all used as part of the key when HttpConnectionManagerParams tries to locate + * the host configuration. */ connectionMgrParams.setMaxConnectionsPerHost(config, builder.getMaxConnectionsPerHost(fileSystemOptions)); connectionMgrParams.setMaxTotalConnections(builder.getMaxTotalConnections(fileSystemOptions)); @@ -138,16 +122,12 @@ public final class HttpClientFactory client.setHostConfiguration(config); - if (username != null) - { - final UsernamePasswordCredentials creds = - new UsernamePasswordCredentials(username, password); + if (username != null) { + final UsernamePasswordCredentials creds = new UsernamePasswordCredentials(username, password); final AuthScope scope = new AuthScope(hostname, AuthScope.ANY_PORT); client.getState().setCredentials(scope, creds); } - } - catch (final Exception exc) - { + } catch (final Exception exc) { throw new FileSystemException("vfs.provider.http/connect.error", exc, hostname); } Modified: commons/proper/vfs/trunk/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/http/HttpFileContentInfoFactory.java URL: http://svn.apache.org/viewvc/commons/proper/vfs/trunk/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/http/HttpFileContentInfoFactory.java?rev=1808381&r1=1808380&r2=1808381&view=diff ============================================================================== --- commons/proper/vfs/trunk/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/http/HttpFileContentInfoFactory.java (original) +++ commons/proper/vfs/trunk/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/http/HttpFileContentInfoFactory.java Thu Sep 14 19:26:39 2017 @@ -31,31 +31,24 @@ import org.apache.commons.vfs2.util.File /** * Creates FileContentInfo instances for HTTP. */ -public class HttpFileContentInfoFactory implements FileContentInfoFactory -{ +public class HttpFileContentInfoFactory implements FileContentInfoFactory { @Override - public FileContentInfo create(final FileContent fileContent) throws FileSystemException - { + public FileContentInfo create(final FileContent fileContent) throws FileSystemException { final HttpFileObject httpFile = (HttpFileObject) FileObjectUtils.getAbstractFileObject(fileContent.getFile()); String contentType = null; String contentEncoding = null; HeadMethod headMethod; - try - { + try { headMethod = httpFile.getHeadMethod(); - } - catch (final IOException e) - { + } catch (final IOException e) { throw new FileSystemException(e); } final Header header = headMethod.getResponseHeader("content-type"); - if (header != null) - { + if (header != null) { final HeaderElement[] element = header.getElements(); - if (element != null && element.length > 0) - { + if (element != null && element.length > 0) { contentType = element[0].getName(); } } Modified: commons/proper/vfs/trunk/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/http/HttpFileNameParser.java URL: http://svn.apache.org/viewvc/commons/proper/vfs/trunk/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/http/HttpFileNameParser.java?rev=1808381&r1=1808380&r2=1808381&view=diff ============================================================================== --- commons/proper/vfs/trunk/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/http/HttpFileNameParser.java (original) +++ commons/proper/vfs/trunk/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/http/HttpFileNameParser.java Thu Sep 14 19:26:39 2017 @@ -22,19 +22,16 @@ import org.apache.commons.vfs2.provider. /** * Implementation for http. set default port to 80 */ -public class HttpFileNameParser extends URLFileNameParser -{ +public class HttpFileNameParser extends URLFileNameParser { private static final int DEFAULT_PORT = 80; private static final HttpFileNameParser INSTANCE = new HttpFileNameParser(); - public HttpFileNameParser() - { + public HttpFileNameParser() { super(DEFAULT_PORT); } - 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/http/HttpFileObject.java URL: http://svn.apache.org/viewvc/commons/proper/vfs/trunk/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/http/HttpFileObject.java?rev=1808381&r1=1808380&r2=1808381&view=diff ============================================================================== --- commons/proper/vfs/trunk/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/http/HttpFileObject.java (original) +++ commons/proper/vfs/trunk/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/http/HttpFileObject.java Thu Sep 14 19:26:39 2017 @@ -47,18 +47,14 @@ import org.apache.commons.vfs2.util.Rand * * @param <FS> An {@link HttpFileSystem} subclass */ -public class HttpFileObject<FS extends HttpFileSystem> extends AbstractFileObject<FS> -{ +public class HttpFileObject<FS extends HttpFileSystem> extends AbstractFileObject<FS> { /** * An InputStream that cleans up the HTTP connection on close. */ - static class HttpInputStream extends MonitorInputStream - { + static class HttpInputStream extends MonitorInputStream { private final GetMethod method; - public HttpInputStream(final GetMethod method) - throws IOException - { + public HttpInputStream(final GetMethod method) throws IOException { super(method.getResponseBodyAsStream()); this.method = method; } @@ -67,25 +63,23 @@ public class HttpFileObject<FS extends H * Called after the stream has been closed. */ @Override - protected void onClose() throws IOException - { + protected void onClose() throws IOException { method.releaseConnection(); } } + private final String urlCharset; private final String userAgent; private final boolean followRedirect; private HeadMethod method; - protected HttpFileObject(final AbstractFileName name, final FS fileSystem) - { + protected HttpFileObject(final AbstractFileName name, final FS fileSystem) { this(name, fileSystem, HttpFileSystemConfigBuilder.getInstance()); } protected HttpFileObject(final AbstractFileName name, final FS fileSystem, - final HttpFileSystemConfigBuilder builder) - { + final HttpFileSystemConfigBuilder builder) { super(name, fileSystem); final FileSystemOptions fileSystemOptions = fileSystem.getFileSystemOptions(); urlCharset = builder.getUrlCharset(fileSystemOptions); @@ -97,8 +91,7 @@ public class HttpFileObject<FS extends H * Detaches this file object from its file resource. */ @Override - protected void doDetach() throws Exception - { + protected void doDetach() throws Exception { method = null; } @@ -106,11 +99,9 @@ public class HttpFileObject<FS extends H * Returns the size of the file content (in bytes). */ @Override - protected long doGetContentSize() throws Exception - { + protected long doGetContentSize() throws Exception { final Header header = method.getResponseHeader("content-length"); - if (header == null) - { + if (header == null) { // Assume 0 content-length return 0; } @@ -118,26 +109,22 @@ public class HttpFileObject<FS extends H } /** - * Creates an input stream to read the file content from. Is only called - * if {@link #doGetType} returns {@link FileType#FILE}. + * Creates an input stream to read the file content from. Is only called if {@link #doGetType} returns + * {@link FileType#FILE}. * <p> - * It is guaranteed that there are no open output streams for this file - * when this method is called. + * It is guaranteed that there are no open output streams for this file when this method is called. * <p> * The returned stream does not have to be buffered. */ @Override - protected InputStream doGetInputStream() throws Exception - { + protected InputStream doGetInputStream() throws Exception { final GetMethod getMethod = new GetMethod(); setupMethod(getMethod); final int status = getAbstractFileSystem().getClient().executeMethod(getMethod); - if (status == HttpURLConnection.HTTP_NOT_FOUND) - { + if (status == HttpURLConnection.HTTP_NOT_FOUND) { throw new FileNotFoundException(getName()); } - if (status != HttpURLConnection.HTTP_OK) - { + if (status != HttpURLConnection.HTTP_OK) { throw new FileSystemException("vfs.provider.http/get.error", getName(), Integer.valueOf(status)); } @@ -150,50 +137,39 @@ public class HttpFileObject<FS extends H * This implementation throws an exception. */ @Override - protected long doGetLastModifiedTime() throws Exception - { + protected long doGetLastModifiedTime() throws Exception { final Header header = method.getResponseHeader("last-modified"); - if (header == null) - { + if (header == null) { throw new FileSystemException("vfs.provider.http/last-modified.error", getName()); } return DateUtil.parseDate(header.getValue()).getTime(); } @Override - protected RandomAccessContent doGetRandomAccessContent(final RandomAccessMode mode) throws Exception - { + protected RandomAccessContent doGetRandomAccessContent(final RandomAccessMode mode) throws Exception { return new HttpRandomAccessContent(this, mode); } /** - * 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 - { + protected FileType doGetType() throws Exception { // Use the HEAD method to probe the file. final int status = this.getHeadMethod().getStatusCode(); if (status == HttpURLConnection.HTTP_OK - || status == HttpURLConnection.HTTP_BAD_METHOD /* method is bad, but resource exist */) - { + || status == HttpURLConnection.HTTP_BAD_METHOD /* method is bad, but resource exist */) { return FileType.FILE; - } - else if (status == HttpURLConnection.HTTP_NOT_FOUND - || status == HttpURLConnection.HTTP_GONE) - { + } else if (status == HttpURLConnection.HTTP_NOT_FOUND || status == HttpURLConnection.HTTP_GONE) { return FileType.IMAGINARY; - } - else - { + } else { throw new FileSystemException("vfs.provider.http/head.error", getName(), Integer.valueOf(status)); } } @Override - protected boolean doIsWriteable() throws Exception - { + protected boolean doIsWriteable() throws Exception { return false; } @@ -201,37 +177,29 @@ public class HttpFileObject<FS extends H * Lists the children of this file. */ @Override - protected String[] doListChildren() throws Exception - { + protected String[] doListChildren() throws Exception { throw new Exception("Not implemented."); } - protected String encodePath(final String decodedPath) throws URIException - { + protected String encodePath(final String decodedPath) throws URIException { return URIUtil.encodePath(decodedPath); } - @Override - protected FileContentInfoFactory getFileContentInfoFactory() - { + protected FileContentInfoFactory getFileContentInfoFactory() { return new HttpFileContentInfoFactory(); } - protected boolean getFollowRedirect() - { + protected boolean getFollowRedirect() { return followRedirect; } - protected String getUserAgent() - { + protected String getUserAgent() { return userAgent; } - HeadMethod getHeadMethod() throws IOException - { - if (method != null) - { + HeadMethod getHeadMethod() throws IOException { + if (method != null) { return method; } method = new HeadMethod(); @@ -242,8 +210,7 @@ public class HttpFileObject<FS extends H return method; } - protected String getUrlCharset() - { + protected String getUrlCharset() { return urlCharset; } @@ -255,8 +222,7 @@ public class HttpFileObject<FS extends H * @throws URIException if path cannot be represented. * @since 2.0 (was package) */ - 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()); @@ -264,22 +230,12 @@ public class HttpFileObject<FS extends H } /* - protected Map doGetAttributes() throws Exception - { - TreeMap map = new TreeMap(); - - Header contentType = method.getResponseHeader("content-type"); - if (contentType != null) - { - HeaderElement[] element = contentType.getValues(); - if (element != null && element.length > 0) - { - map.put("content-type", element[0].getName()); - } - } - - map.put("content-encoding", method.getResponseCharSet()); - return map; - } - */ + * protected Map doGetAttributes() throws Exception { TreeMap map = new TreeMap(); + * + * Header contentType = method.getResponseHeader("content-type"); if (contentType != null) { HeaderElement[] element + * = contentType.getValues(); if (element != null && element.length > 0) { map.put("content-type", + * element[0].getName()); } } + * + * map.put("content-encoding", method.getResponseCharSet()); return map; } + */ } Modified: commons/proper/vfs/trunk/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/http/HttpFileProvider.java URL: http://svn.apache.org/viewvc/commons/proper/vfs/trunk/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/http/HttpFileProvider.java?rev=1808381&r1=1808380&r2=1808381&view=diff ============================================================================== --- commons/proper/vfs/trunk/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/http/HttpFileProvider.java (original) +++ commons/proper/vfs/trunk/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/http/HttpFileProvider.java Thu Sep 14 19:26:39 2017 @@ -35,31 +35,20 @@ import org.apache.commons.vfs2.util.User /** * An HTTP provider that uses commons-httpclient. */ -public class HttpFileProvider - extends AbstractOriginatingFileProvider -{ +public class HttpFileProvider extends AbstractOriginatingFileProvider { /** Authenticator information. */ - public static final UserAuthenticationData.Type[] AUTHENTICATOR_TYPES = new UserAuthenticationData.Type[] - { - UserAuthenticationData.USERNAME, UserAuthenticationData.PASSWORD - }; - - static final Collection<Capability> capabilities = Collections.unmodifiableCollection(Arrays.asList(new Capability[] - { - Capability.GET_TYPE, - Capability.READ_CONTENT, - Capability.URI, - Capability.GET_LAST_MODIFIED, - Capability.ATTRIBUTES, - Capability.RANDOM_ACCESS_READ, - Capability.DIRECTORY_READ_CONTENT, - })); + public static final UserAuthenticationData.Type[] AUTHENTICATOR_TYPES = new UserAuthenticationData.Type[] { + UserAuthenticationData.USERNAME, UserAuthenticationData.PASSWORD }; + + static final Collection<Capability> capabilities = Collections + .unmodifiableCollection(Arrays.asList(new Capability[] { Capability.GET_TYPE, Capability.READ_CONTENT, + Capability.URI, Capability.GET_LAST_MODIFIED, Capability.ATTRIBUTES, Capability.RANDOM_ACCESS_READ, + Capability.DIRECTORY_READ_CONTENT, })); /** * Constructs a new provider. */ - public HttpFileProvider() - { + public HttpFileProvider() { super(); setFileNameParser(HttpFileNameParser.getInstance()); } @@ -69,29 +58,23 @@ public class HttpFileProvider */ @Override protected FileSystem doCreateFileSystem(final FileName name, final FileSystemOptions fileSystemOptions) - throws FileSystemException - { + throws FileSystemException { // Create the file system final GenericFileName rootName = (GenericFileName) name; UserAuthenticationData authData = null; HttpClient httpClient; - try - { + try { authData = UserAuthenticatorUtils.authenticate(fileSystemOptions, AUTHENTICATOR_TYPES); - httpClient = HttpClientFactory.createConnection( - rootName.getScheme(), - 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()))), - fileSystemOptions); - } - finally - { + httpClient = HttpClientFactory.createConnection(rootName.getScheme(), 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()))), + fileSystemOptions); + } finally { UserAuthenticatorUtils.cleanup(authData); } @@ -99,14 +82,12 @@ public class HttpFileProvider } @Override - public FileSystemConfigBuilder getConfigBuilder() - { + public FileSystemConfigBuilder getConfigBuilder() { return HttpFileSystemConfigBuilder.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/http/HttpFileSystem.java URL: http://svn.apache.org/viewvc/commons/proper/vfs/trunk/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/http/HttpFileSystem.java?rev=1808381&r1=1808380&r2=1808381&view=diff ============================================================================== --- commons/proper/vfs/trunk/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/http/HttpFileSystem.java (original) +++ commons/proper/vfs/trunk/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/http/HttpFileSystem.java Thu Sep 14 19:26:39 2017 @@ -31,14 +31,11 @@ import org.apache.commons.vfs2.provider. /** * An HTTP file system. */ -public class HttpFileSystem - extends AbstractFileSystem -{ +public class HttpFileSystem extends AbstractFileSystem { private final HttpClient client; protected HttpFileSystem(final GenericFileName rootName, final HttpClient client, - final FileSystemOptions fileSystemOptions) - { + final FileSystemOptions fileSystemOptions) { super(rootName, null, fileSystemOptions); this.client = client; } @@ -47,38 +44,30 @@ public class HttpFileSystem * Adds the capabilities of this file system. */ @Override - protected void addCapabilities(final Collection<Capability> caps) - { + protected void addCapabilities(final Collection<Capability> caps) { caps.addAll(HttpFileProvider.capabilities); } - protected HttpClient getClient() - { + protected HttpClient getClient() { return client; } /** @since 2.0 */ @Override - public void closeCommunicationLink() - { - if (getClient() != null) - { + public void closeCommunicationLink() { + if (getClient() != null) { final HttpConnectionManager mgr = getClient().getHttpConnectionManager(); - if (mgr instanceof MultiThreadedHttpConnectionManager) - { + if (mgr instanceof MultiThreadedHttpConnectionManager) { ((MultiThreadedHttpConnectionManager) mgr).shutdown(); } } } /** - * Creates a file object. This method is called only if the requested - * file is not cached. + * Creates a file object. This method is called only if the requested file is not cached. */ @Override - protected FileObject createFile(final AbstractFileName name) - throws Exception - { + protected FileObject createFile(final AbstractFileName name) throws Exception { return new HttpFileObject(name, this); } }
