commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ggreg...@apache.org
Subject svn commit: r1363962 - in /commons/proper/vfs/trunk: core/src/main/java/org/apache/commons/vfs2/provider/ core/src/main/java/org/apache/commons/vfs2/provider/bzip2/ core/src/main/java/org/apache/commons/vfs2/provider/compressed/ core/src/main/java/org/...
Date Fri, 20 Jul 2012 21:59:49 GMT
Author: ggregory
Date: Fri Jul 20 21:59:48 2012
New Revision: 1363962

URL: http://svn.apache.org/viewvc?rev=1363962&view=rev
Log:
[VFS-429] Remove extra FileSystem ivar in AbstractFileObject subclasses with generics.

Modified:
    commons/proper/vfs/trunk/core/src/main/java/org/apache/commons/vfs2/provider/AbstractFileObject.java
    commons/proper/vfs/trunk/core/src/main/java/org/apache/commons/vfs2/provider/DelegateFileObject.java
    commons/proper/vfs/trunk/core/src/main/java/org/apache/commons/vfs2/provider/bzip2/Bzip2FileObject.java
    commons/proper/vfs/trunk/core/src/main/java/org/apache/commons/vfs2/provider/compressed/CompressedFileFileObject.java
    commons/proper/vfs/trunk/core/src/main/java/org/apache/commons/vfs2/provider/ftp/FtpFileObject.java
    commons/proper/vfs/trunk/core/src/main/java/org/apache/commons/vfs2/provider/gzip/GzipFileObject.java
    commons/proper/vfs/trunk/core/src/main/java/org/apache/commons/vfs2/provider/http/HttpFileObject.java
    commons/proper/vfs/trunk/core/src/main/java/org/apache/commons/vfs2/provider/local/LocalFile.java
    commons/proper/vfs/trunk/core/src/main/java/org/apache/commons/vfs2/provider/ram/RamFileObject.java
    commons/proper/vfs/trunk/core/src/main/java/org/apache/commons/vfs2/provider/sftp/SftpFileObject.java
    commons/proper/vfs/trunk/core/src/main/java/org/apache/commons/vfs2/provider/tar/TarFileObject.java
    commons/proper/vfs/trunk/core/src/main/java/org/apache/commons/vfs2/provider/url/UrlFileObject.java
    commons/proper/vfs/trunk/core/src/main/java/org/apache/commons/vfs2/provider/zip/ZipFileObject.java
    commons/proper/vfs/trunk/src/changes/changes.xml

Modified: commons/proper/vfs/trunk/core/src/main/java/org/apache/commons/vfs2/provider/AbstractFileObject.java
URL: http://svn.apache.org/viewvc/commons/proper/vfs/trunk/core/src/main/java/org/apache/commons/vfs2/provider/AbstractFileObject.java?rev=1363962&r1=1363961&r2=1363962&view=diff
==============================================================================
--- commons/proper/vfs/trunk/core/src/main/java/org/apache/commons/vfs2/provider/AbstractFileObject.java
(original)
+++ commons/proper/vfs/trunk/core/src/main/java/org/apache/commons/vfs2/provider/AbstractFileObject.java
Fri Jul 20 21:59:48 2012
@@ -55,13 +55,14 @@ import org.apache.commons.vfs2.util.Rand
 
 /**
  * A partial file object implementation.
+ * @param <AFS> An AbstractFileSystem subclass
  *
  * @todo Chop this class up - move all the protected methods to several
  * interfaces, so that structure and content can be separately overridden.
  * @todo Check caps in methods like getChildren(), etc, and give better error messages
  * (eg 'this file type does not support listing children', vs 'this is not a folder')
  */
-public abstract class AbstractFileObject implements FileObject
+public abstract class AbstractFileObject<AFS extends AbstractFileSystem> implements
FileObject
 {
     // private static final FileObject[] EMPTY_FILE_ARRAY = {};
     private static final FileName[] EMPTY_FILE_ARRAY = {};
@@ -69,7 +70,7 @@ public abstract class AbstractFileObject
     private static final int INITIAL_LIST_SIZE = 5;
 
     private final AbstractFileName name;
-    private final AbstractFileSystem fs;
+    private final AFS fs;
 
     private FileContent content;
 
@@ -96,7 +97,7 @@ public abstract class AbstractFileObject
      * @throws ClassCastException if {@code name} is not an instance of {@link AbstractFileName}
      */
     protected AbstractFileObject(final AbstractFileName name,
-                                 final AbstractFileSystem fs)
+                                 final AFS fs)
     {
         this.name = name;
         this.fs = fs;
@@ -505,6 +506,15 @@ public abstract class AbstractFileObject
     }
 
     /**
+     * Returns the file system this file belongs to.
+     * @return The FileSystem this file is associated with.
+     */
+    protected AFS getAbstractFileSystem()
+    {
+        return fs;
+    }
+
+    /**
      * Returns a URL representation of the file.
      * @return The URL representation of the file.
      * @throws FileSystemException if an error occurs.

Modified: commons/proper/vfs/trunk/core/src/main/java/org/apache/commons/vfs2/provider/DelegateFileObject.java
URL: http://svn.apache.org/viewvc/commons/proper/vfs/trunk/core/src/main/java/org/apache/commons/vfs2/provider/DelegateFileObject.java?rev=1363962&r1=1363961&r2=1363962&view=diff
==============================================================================
--- commons/proper/vfs/trunk/core/src/main/java/org/apache/commons/vfs2/provider/DelegateFileObject.java
(original)
+++ commons/proper/vfs/trunk/core/src/main/java/org/apache/commons/vfs2/provider/DelegateFileObject.java
Fri Jul 20 21:59:48 2012
@@ -37,17 +37,19 @@ import org.apache.commons.vfs2.util.Weak
 
 /**
  * A file backed by another file.
+ * 
+ * @param <AFS>  A subclass of AbstractFileSystem.
  *
  * @todo Extract subclass that overlays the children
  */
-public class DelegateFileObject extends AbstractFileObject implements FileListener
+public class DelegateFileObject<AFS extends AbstractFileSystem> extends AbstractFileObject<AFS>
implements FileListener
 {
     private FileObject file;
     private final Set<String> children = new HashSet<String>();
     private boolean ignoreEvent;
 
     public DelegateFileObject(final AbstractFileName name,
-                              final AbstractFileSystem fileSystem,
+                              final AFS fileSystem,
                               final FileObject file) throws FileSystemException
     {
         super(name, fileSystem);

Modified: commons/proper/vfs/trunk/core/src/main/java/org/apache/commons/vfs2/provider/bzip2/Bzip2FileObject.java
URL: http://svn.apache.org/viewvc/commons/proper/vfs/trunk/core/src/main/java/org/apache/commons/vfs2/provider/bzip2/Bzip2FileObject.java?rev=1363962&r1=1363961&r2=1363962&view=diff
==============================================================================
--- commons/proper/vfs/trunk/core/src/main/java/org/apache/commons/vfs2/provider/bzip2/Bzip2FileObject.java
(original)
+++ commons/proper/vfs/trunk/core/src/main/java/org/apache/commons/vfs2/provider/bzip2/Bzip2FileObject.java
Fri Jul 20 21:59:48 2012
@@ -25,14 +25,13 @@ import org.apache.commons.compress.compr
 import org.apache.commons.vfs2.FileObject;
 import org.apache.commons.vfs2.provider.AbstractFileName;
 import org.apache.commons.vfs2.provider.compressed.CompressedFileFileObject;
-import org.apache.commons.vfs2.provider.compressed.CompressedFileFileSystem;
 
 /**
  * the bzip2 file.
  */
-public class Bzip2FileObject extends CompressedFileFileObject
+public class Bzip2FileObject extends CompressedFileFileObject<Bzip2FileSystem>
 {
-    protected Bzip2FileObject(AbstractFileName name, FileObject container, CompressedFileFileSystem
fs)
+    protected Bzip2FileObject(AbstractFileName name, FileObject container, Bzip2FileSystem
fs)
     {
         super(name, container, fs);
     }

Modified: commons/proper/vfs/trunk/core/src/main/java/org/apache/commons/vfs2/provider/compressed/CompressedFileFileObject.java
URL: http://svn.apache.org/viewvc/commons/proper/vfs/trunk/core/src/main/java/org/apache/commons/vfs2/provider/compressed/CompressedFileFileObject.java?rev=1363962&r1=1363961&r2=1363962&view=diff
==============================================================================
--- commons/proper/vfs/trunk/core/src/main/java/org/apache/commons/vfs2/provider/compressed/CompressedFileFileObject.java
(original)
+++ commons/proper/vfs/trunk/core/src/main/java/org/apache/commons/vfs2/provider/compressed/CompressedFileFileObject.java
Fri Jul 20 21:59:48 2012
@@ -24,15 +24,21 @@ import org.apache.commons.vfs2.provider.
 import org.apache.commons.vfs2.provider.AbstractFileObject;
 
 /**
- * A compressed file.<br>
- * Such a file do only have one child (the compressed filename with stripped last extension)
+ * A compressed file.
+ * 
+ * <p>
+ * Such a file only has one child (the compressed filename with stripped last extension)
+ * </p>
+ * 
+ * @param <FS>
+ *            A CompressedFileFileSystem
  */
-public abstract class CompressedFileFileObject extends AbstractFileObject
+public abstract class CompressedFileFileObject<FS extends CompressedFileFileSystem>
extends AbstractFileObject<FS>
 {
     private final FileObject container;
     private final String[] children;
 
-    protected CompressedFileFileObject(AbstractFileName name, FileObject container, CompressedFileFileSystem
fs)
+    protected CompressedFileFileObject(AbstractFileName name, FileObject container, FS fs)
     {
         super(name, fs);
         this.container = container;

Modified: commons/proper/vfs/trunk/core/src/main/java/org/apache/commons/vfs2/provider/ftp/FtpFileObject.java
URL: http://svn.apache.org/viewvc/commons/proper/vfs/trunk/core/src/main/java/org/apache/commons/vfs2/provider/ftp/FtpFileObject.java?rev=1363962&r1=1363961&r2=1363962&view=diff
==============================================================================
--- commons/proper/vfs/trunk/core/src/main/java/org/apache/commons/vfs2/provider/ftp/FtpFileObject.java
(original)
+++ commons/proper/vfs/trunk/core/src/main/java/org/apache/commons/vfs2/provider/ftp/FtpFileObject.java
Fri Jul 20 21:59:48 2012
@@ -47,14 +47,13 @@ import org.apache.commons.vfs2.util.Rand
 /**
  * An FTP file.
  */
-public class FtpFileObject extends AbstractFileObject
+public class FtpFileObject extends AbstractFileObject<FtpFileSystem>
 {
     private static final Map<String, FTPFile> EMPTY_FTP_FILE_MAP =
         Collections.unmodifiableMap(new TreeMap<String, FTPFile>());
     private static final FTPFile UNKNOWN = new FTPFile();
 
     private final Log log = LogFactory.getLog(FtpFileObject.class);
-    private final FtpFileSystem ftpFs;
     private final String relPath;
 
     // Cached info
@@ -70,7 +69,6 @@ public class FtpFileObject extends Abstr
         throws FileSystemException
     {
         super(name, fileSystem);
-        ftpFs = fileSystem;
         String relPath = UriParser.decode(rootName.getRelativeName(name));
         if (".".equals(relPath))
         {
@@ -128,7 +126,7 @@ public class FtpFileObject extends Abstr
             return;
         }
 
-        final FtpClient client = ftpFs.getClient();
+        final FtpClient client = getAbstractFileSystem().getClient();
         try
         {
             final String path = fileInfo != null && fileInfo.isSymbolicLink()
@@ -167,7 +165,7 @@ public class FtpFileObject extends Abstr
         }
         finally
         {
-            ftpFs.putClient(client);
+            getAbstractFileSystem().putClient(client);
         }
     }
 
@@ -459,7 +457,7 @@ public class FtpFileObject extends Abstr
         synchronized (getFileSystem())
         {
             final boolean ok;
-            final FtpClient ftpClient = ftpFs.getClient();
+            final FtpClient ftpClient = getAbstractFileSystem().getClient();
             try
             {
                 if (this.fileInfo.isDirectory())
@@ -473,7 +471,7 @@ public class FtpFileObject extends Abstr
             }
             finally
             {
-                ftpFs.putClient(ftpClient);
+                getAbstractFileSystem().putClient(ftpClient);
             }
 
             if (!ok)
@@ -494,7 +492,7 @@ public class FtpFileObject extends Abstr
         synchronized (getFileSystem())
         {
             final boolean ok;
-            final FtpClient ftpClient = ftpFs.getClient();
+            final FtpClient ftpClient = getAbstractFileSystem().getClient();
             try
             {
                 String oldName = getName().getPath();
@@ -503,7 +501,7 @@ public class FtpFileObject extends Abstr
             }
             finally
             {
-                ftpFs.putClient(ftpClient);
+                getAbstractFileSystem().putClient(ftpClient);
             }
 
             if (!ok)
@@ -524,14 +522,14 @@ public class FtpFileObject extends Abstr
         throws Exception
     {
         final boolean ok;
-        final FtpClient client = ftpFs.getClient();
+        final FtpClient client = getAbstractFileSystem().getClient();
         try
         {
             ok = client.makeDirectory(relPath);
         }
         finally
         {
-            ftpFs.putClient(client);
+            getAbstractFileSystem().putClient(client);
         }
 
         if (!ok)
@@ -594,7 +592,7 @@ public class FtpFileObject extends Abstr
     @Override
     protected InputStream doGetInputStream() throws Exception
     {
-        final FtpClient client = ftpFs.getClient();
+        final FtpClient client = getAbstractFileSystem().getClient();
         try
         {
             final InputStream instr = client.retrieveFileStream(relPath);
@@ -607,7 +605,7 @@ public class FtpFileObject extends Abstr
         }
         catch (Exception e)
         {
-            ftpFs.putClient(client);
+            getAbstractFileSystem().putClient(client);
             throw e;
         }
     }
@@ -625,7 +623,7 @@ public class FtpFileObject extends Abstr
     protected OutputStream doGetOutputStream(boolean bAppend)
         throws Exception
     {
-        final FtpClient client = ftpFs.getClient();
+        final FtpClient client = getAbstractFileSystem().getClient();
         try
         {
             OutputStream out = null;
@@ -649,7 +647,7 @@ public class FtpFileObject extends Abstr
         }
         catch (Exception e)
         {
-            ftpFs.putClient(client);
+            getAbstractFileSystem().putClient(client);
             throw e;
         }
     }
@@ -661,7 +659,7 @@ public class FtpFileObject extends Abstr
 
     FtpInputStream getInputStream(long filePointer) throws IOException
     {
-        final FtpClient client = ftpFs.getClient();
+        final FtpClient client = getAbstractFileSystem().getClient();
         try
         {
             final InputStream instr = client.retrieveFileStream(relPath, filePointer);
@@ -675,7 +673,7 @@ public class FtpFileObject extends Abstr
         }
         catch (IOException e)
         {
-            ftpFs.putClient(client);
+            getAbstractFileSystem().putClient(client);
             throw e;
         }
     }
@@ -713,7 +711,7 @@ public class FtpFileObject extends Abstr
             }
             finally
             {
-                ftpFs.putClient(client);
+                getAbstractFileSystem().putClient(client);
             }
 
             if (!ok)
@@ -750,7 +748,7 @@ public class FtpFileObject extends Abstr
             }
             finally
             {
-                ftpFs.putClient(client);
+                getAbstractFileSystem().putClient(client);
             }
 
             if (!ok)

Modified: commons/proper/vfs/trunk/core/src/main/java/org/apache/commons/vfs2/provider/gzip/GzipFileObject.java
URL: http://svn.apache.org/viewvc/commons/proper/vfs/trunk/core/src/main/java/org/apache/commons/vfs2/provider/gzip/GzipFileObject.java?rev=1363962&r1=1363961&r2=1363962&view=diff
==============================================================================
--- commons/proper/vfs/trunk/core/src/main/java/org/apache/commons/vfs2/provider/gzip/GzipFileObject.java
(original)
+++ commons/proper/vfs/trunk/core/src/main/java/org/apache/commons/vfs2/provider/gzip/GzipFileObject.java
Fri Jul 20 21:59:48 2012
@@ -24,14 +24,13 @@ import java.util.zip.GZIPOutputStream;
 import org.apache.commons.vfs2.FileObject;
 import org.apache.commons.vfs2.provider.AbstractFileName;
 import org.apache.commons.vfs2.provider.compressed.CompressedFileFileObject;
-import org.apache.commons.vfs2.provider.compressed.CompressedFileFileSystem;
 
 /**
  * the gzip file.
  */
-public class GzipFileObject extends CompressedFileFileObject
+public class GzipFileObject extends CompressedFileFileObject<GzipFileSystem>
 {
-    protected GzipFileObject(AbstractFileName name, FileObject container, CompressedFileFileSystem
fs)
+    protected GzipFileObject(AbstractFileName name, FileObject container, GzipFileSystem
fs)
     {
         super(name, container, fs);
     }

Modified: commons/proper/vfs/trunk/core/src/main/java/org/apache/commons/vfs2/provider/http/HttpFileObject.java
URL: http://svn.apache.org/viewvc/commons/proper/vfs/trunk/core/src/main/java/org/apache/commons/vfs2/provider/http/HttpFileObject.java?rev=1363962&r1=1363961&r2=1363962&view=diff
==============================================================================
--- commons/proper/vfs/trunk/core/src/main/java/org/apache/commons/vfs2/provider/http/HttpFileObject.java
(original)
+++ commons/proper/vfs/trunk/core/src/main/java/org/apache/commons/vfs2/provider/http/HttpFileObject.java
Fri Jul 20 21:59:48 2012
@@ -44,16 +44,14 @@ import org.apache.commons.vfs2.util.Rand
  *
  * @todo status codes
  */
-public class HttpFileObject extends AbstractFileObject
+public class HttpFileObject extends AbstractFileObject<HttpFileSystem>
 {
-    private final HttpFileSystem fileSystem;
     private final String urlCharset;
     private HeadMethod method;
 
     protected HttpFileObject(final AbstractFileName name, final HttpFileSystem fileSystem)
     {
         super(name, fileSystem);
-        this.fileSystem = fileSystem;
         urlCharset = HttpFileSystemConfigBuilder.getInstance().getUrlCharset(getFileSystem().getFileSystemOptions());
     }
 
@@ -144,7 +142,7 @@ public class HttpFileObject extends Abst
     {
         final GetMethod getMethod = new GetMethod();
         setupMethod(getMethod);
-        final int status = fileSystem.getClient().executeMethod(getMethod);
+        final int status = getAbstractFileSystem().getClient().executeMethod(getMethod);
         if (status == HttpURLConnection.HTTP_NOT_FOUND)
         {
             throw new FileNotFoundException(getName());
@@ -219,7 +217,7 @@ public class HttpFileObject extends Abst
         }
         method = new HeadMethod();
         setupMethod(method);
-        final HttpClient client = fileSystem.getClient();
+        final HttpClient client = getAbstractFileSystem().getClient();
         client.executeMethod(method);
         method.releaseConnection();
         return method;

Modified: commons/proper/vfs/trunk/core/src/main/java/org/apache/commons/vfs2/provider/local/LocalFile.java
URL: http://svn.apache.org/viewvc/commons/proper/vfs/trunk/core/src/main/java/org/apache/commons/vfs2/provider/local/LocalFile.java?rev=1363962&r1=1363961&r2=1363962&view=diff
==============================================================================
--- commons/proper/vfs/trunk/core/src/main/java/org/apache/commons/vfs2/provider/local/LocalFile.java
(original)
+++ commons/proper/vfs/trunk/core/src/main/java/org/apache/commons/vfs2/provider/local/LocalFile.java
Fri Jul 20 21:59:48 2012
@@ -36,7 +36,7 @@ import org.apache.commons.vfs2.util.Rand
 /**
  * A file object implementation which uses direct file access.
  */
-public class LocalFile extends AbstractFileObject
+public class LocalFile extends AbstractFileObject<LocalFileSystem>
 {
     private final String rootFile;
 

Modified: commons/proper/vfs/trunk/core/src/main/java/org/apache/commons/vfs2/provider/ram/RamFileObject.java
URL: http://svn.apache.org/viewvc/commons/proper/vfs/trunk/core/src/main/java/org/apache/commons/vfs2/provider/ram/RamFileObject.java?rev=1363962&r1=1363961&r2=1363962&view=diff
==============================================================================
--- commons/proper/vfs/trunk/core/src/main/java/org/apache/commons/vfs2/provider/ram/RamFileObject.java
(original)
+++ commons/proper/vfs/trunk/core/src/main/java/org/apache/commons/vfs2/provider/ram/RamFileObject.java
Fri Jul 20 21:59:48 2012
@@ -23,6 +23,7 @@ import java.io.OutputStream;
 
 import org.apache.commons.vfs2.FileObject;
 import org.apache.commons.vfs2.FileSystemException;
+import org.apache.commons.vfs2.FileSystemOptions;
 import org.apache.commons.vfs2.FileType;
 import org.apache.commons.vfs2.RandomAccessContent;
 import org.apache.commons.vfs2.provider.AbstractFileName;
@@ -34,14 +35,9 @@ import org.apache.commons.vfs2.util.Rand
  * A RAM File contains a single RAM FileData instance, it provides methods to access the
data by implementing FileObject
  * interface.
  */
-public class RamFileObject extends AbstractFileObject
+public class RamFileObject extends AbstractFileObject<RamFileSystem>
 {
     /**
-     * File System.
-     */
-    private final RamFileSystem fs;
-
-    /**
      * RAM File Object Data.
      */
     private RamFileData data;
@@ -55,13 +51,12 @@ public class RamFileObject extends Abstr
     protected RamFileObject(AbstractFileName name, RamFileSystem fs)
     {
         super(name, fs);
-        this.fs = fs;
-        this.fs.attach(this);
+        this.getAbstractFileSystem().attach(this);
     }
 
     private void save() throws FileSystemException
     {
-        this.fs.save(this);
+        this.getAbstractFileSystem().save(this);
     }
 
     /*
@@ -83,7 +78,7 @@ public class RamFileObject extends Abstr
     @Override
     protected String[] doListChildren() throws Exception
     {
-        return this.fs.listChildren(this.getName());
+        return this.getAbstractFileSystem().listChildren(this.getName());
     }
 
     /*
@@ -142,7 +137,7 @@ public class RamFileObject extends Abstr
         {
             throw new FileSystemException(this.getName() + " cannot be deleted while the
file is openg");
         }
-        fs.delete(this);
+        getAbstractFileSystem().delete(this);
     }
 
     /*
@@ -190,7 +185,7 @@ public class RamFileObject extends Abstr
     protected void doRename(FileObject newFile) throws Exception
     {
         RamFileObject newRamFileObject = (RamFileObject) FileObjectUtils.getAbstractFileObject(newFile);
-        fs.rename(this, newRamFileObject);
+        getAbstractFileSystem().rename(this, newRamFileObject);
     }
 
     /*
@@ -213,7 +208,7 @@ public class RamFileObject extends Abstr
     @Override
     protected void doAttach() throws Exception
     {
-        this.fs.attach(this);
+        this.getAbstractFileSystem().attach(this);
     }
 
     /**
@@ -272,11 +267,13 @@ public class RamFileObject extends Abstr
      */
     synchronized void resize(long newSize) throws IOException
     {
-        if (fs.getFileSystemOptions() != null)
+        final RamFileSystem afs = getAbstractFileSystem();
+        final FileSystemOptions afsOptions = afs.getFileSystemOptions();
+        if (afsOptions != null)
         {
             // A future implementation may allow longs...
-            int maxSize = RamFileSystemConfigBuilder.getInstance().getMaxSize(fs.getFileSystemOptions());
-            if (fs.size() + newSize - this.size() > maxSize)
+            int maxSize = RamFileSystemConfigBuilder.getInstance().getMaxSize(afsOptions);
+            if (afs.size() + newSize - this.size() > maxSize)
             {
                 throw new IOException("FileSystem capacity (" + maxSize + ") exceeded.");
             }

Modified: commons/proper/vfs/trunk/core/src/main/java/org/apache/commons/vfs2/provider/sftp/SftpFileObject.java
URL: http://svn.apache.org/viewvc/commons/proper/vfs/trunk/core/src/main/java/org/apache/commons/vfs2/provider/sftp/SftpFileObject.java?rev=1363962&r1=1363961&r2=1363962&view=diff
==============================================================================
--- commons/proper/vfs/trunk/core/src/main/java/org/apache/commons/vfs2/provider/sftp/SftpFileObject.java
(original)
+++ commons/proper/vfs/trunk/core/src/main/java/org/apache/commons/vfs2/provider/sftp/SftpFileObject.java
Fri Jul 20 21:59:48 2012
@@ -49,11 +49,10 @@ import com.jcraft.jsch.SftpException;
  *
  * @version $Id$
  */
-public class SftpFileObject extends AbstractFileObject
+public class SftpFileObject extends AbstractFileObject<SftpFileSystem>
 {
     private static final long MOD_TIME_FACTOR = 1000L;
 
-    private final SftpFileSystem fileSystem;
     private SftpATTRS attrs;
     private final String relPath;
 
@@ -63,7 +62,6 @@ public class SftpFileObject extends Abst
             final SftpFileSystem fileSystem) throws FileSystemException
     {
         super(name, fileSystem);
-        this.fileSystem = fileSystem;
         relPath = UriParser.decode(fileSystem.getRootName().getRelativeName(
                 name));
     }
@@ -153,7 +151,7 @@ public class SftpFileObject extends Abst
      */
     private void statSelf() throws IOException
     {
-        ChannelSftp channel = fileSystem.getChannel();
+        ChannelSftp channel = getAbstractFileSystem().getChannel();
         try
         {
             setStat(channel.stat(relPath));
@@ -166,7 +164,7 @@ public class SftpFileObject extends Abst
                 if (e.id != ChannelSftp.SSH_FX_NO_SUCH_FILE)
                 {
                     channel.disconnect();
-                    channel = fileSystem.getChannel();
+                    channel = getAbstractFileSystem().getChannel();
                     setStat(channel.stat(relPath));
                 }
                 else
@@ -190,7 +188,7 @@ public class SftpFileObject extends Abst
         }
         finally
         {
-            fileSystem.putChannel(channel);
+            getAbstractFileSystem().putChannel(channel);
         }
     }
 
@@ -208,14 +206,14 @@ public class SftpFileObject extends Abst
     @Override
     protected void doCreateFolder() throws Exception
     {
-        final ChannelSftp channel = fileSystem.getChannel();
+        final ChannelSftp channel = getAbstractFileSystem().getChannel();
         try
         {
             channel.mkdir(relPath);
         }
         finally
         {
-            fileSystem.putChannel(channel);
+            getAbstractFileSystem().putChannel(channel);
         }
     }
 
@@ -251,14 +249,14 @@ public class SftpFileObject extends Abst
 
     private void flushStat() throws IOException, SftpException
     {
-        final ChannelSftp channel = fileSystem.getChannel();
+        final ChannelSftp channel = getAbstractFileSystem().getChannel();
         try
         {
             channel.setStat(relPath, attrs);
         }
         finally
         {
-            fileSystem.putChannel(channel);
+            getAbstractFileSystem().putChannel(channel);
         }
     }
 
@@ -268,7 +266,7 @@ public class SftpFileObject extends Abst
     @Override
     protected void doDelete() throws Exception
     {
-        final ChannelSftp channel = fileSystem.getChannel();
+        final ChannelSftp channel = getAbstractFileSystem().getChannel();
         try
         {
             if (isFile())
@@ -282,7 +280,7 @@ public class SftpFileObject extends Abst
         }
         finally
         {
-            fileSystem.putChannel(channel);
+            getAbstractFileSystem().putChannel(channel);
         }
     }
 
@@ -292,7 +290,7 @@ public class SftpFileObject extends Abst
     @Override
     protected void doRename(FileObject newFile) throws Exception
     {
-        final ChannelSftp channel = fileSystem.getChannel();
+        final ChannelSftp channel = getAbstractFileSystem().getChannel();
         try
         {
             SftpFileObject newSftpFileObject = (SftpFileObject) FileObjectUtils.getAbstractFileObject(newFile);
@@ -300,7 +298,7 @@ public class SftpFileObject extends Abst
         }
         finally
         {
-            fileSystem.putChannel(channel);
+            getAbstractFileSystem().putChannel(channel);
         }
     }
 
@@ -318,7 +316,7 @@ public class SftpFileObject extends Abst
         boolean isInGroup = false;
         if (checkIds)
         {
-            for (int groupId : fileSystem.getGroupsIds())
+            for (int groupId : getAbstractFileSystem().getGroupsIds())
             {
                 if (groupId == attrs.getGId())
                 {
@@ -327,7 +325,7 @@ public class SftpFileObject extends Abst
                 }
             }
         }
-        final boolean isOwner = checkIds ?  attrs.getUId() == fileSystem.getUId() : false;
+        final boolean isOwner = checkIds ?  attrs.getUId() == getAbstractFileSystem().getUId()
: false;
         final PosixPermissions permissions = new PosixPermissions(attrs.getPermissions(),
isOwner, isInGroup);
 
         return permissions;
@@ -413,7 +411,7 @@ public class SftpFileObject extends Abst
         }
         // List the contents of the folder
         Vector<?> vector = null;
-        final ChannelSftp channel = fileSystem.getChannel();
+        final ChannelSftp channel = getAbstractFileSystem().getChannel();
 
         try
         {
@@ -469,7 +467,7 @@ public class SftpFileObject extends Abst
         }
         finally
         {
-            fileSystem.putChannel(channel);
+            getAbstractFileSystem().putChannel(channel);
         }
         if (vector == null)
         {
@@ -553,7 +551,7 @@ public class SftpFileObject extends Abst
      */
     InputStream getInputStream(long filePointer) throws IOException
     {
-        final ChannelSftp channel = fileSystem.getChannel();
+        final ChannelSftp channel = getAbstractFileSystem().getChannel();
         // Using InputStream directly from the channel
         // is much faster than the memory method.
         try
@@ -563,7 +561,7 @@ public class SftpFileObject extends Abst
         } 
         catch (SftpException e)
         {
-            fileSystem.putChannel(channel);
+            getAbstractFileSystem().putChannel(channel);
             throw new FileSystemException(e);
         }
     }
@@ -575,9 +573,9 @@ public class SftpFileObject extends Abst
     protected InputStream doGetInputStream() throws Exception
     {
         // VFS-113: avoid npe
-        synchronized (fileSystem)
+        synchronized (getAbstractFileSystem())
         {
-            final ChannelSftp channel = fileSystem.getChannel();
+            final ChannelSftp channel = getAbstractFileSystem().getChannel();
             try
             {
                 // return channel.get(getName().getPath());
@@ -620,7 +618,7 @@ public class SftpFileObject extends Abst
             }
             finally
             {
-//              fileSystem.putChannel(channel);
+//              getAbstractFileSystem().putChannel(channel);
             }
         }
     }
@@ -634,11 +632,11 @@ public class SftpFileObject extends Abst
         // TODO - Don't write the entire file into memory. Use the stream-based
         // methods on ChannelSftp once the work properly
         /*
-        final ChannelSftp channel = fileSystem.getChannel();
+        final ChannelSftp channel = getAbstractFileSystem().getChannel();
         return new SftpOutputStream(channel);
         */
 
-        final ChannelSftp channel = fileSystem.getChannel();
+        final ChannelSftp channel = getAbstractFileSystem().getChannel();
         return new SftpOutputStream(channel, channel.put(relPath));
     }
 
@@ -661,7 +659,7 @@ public class SftpFileObject extends Abst
         @Override
         protected void onClose() throws IOException
         {
-            fileSystem.putChannel(channel);
+            getAbstractFileSystem().putChannel(channel);
         }
     }
 
@@ -685,7 +683,7 @@ public class SftpFileObject extends Abst
         @Override
         protected void onClose() throws IOException
         {
-            fileSystem.putChannel(channel);
+            getAbstractFileSystem().putChannel(channel);
         }
     }
 

Modified: commons/proper/vfs/trunk/core/src/main/java/org/apache/commons/vfs2/provider/tar/TarFileObject.java
URL: http://svn.apache.org/viewvc/commons/proper/vfs/trunk/core/src/main/java/org/apache/commons/vfs2/provider/tar/TarFileObject.java?rev=1363962&r1=1363961&r2=1363962&view=diff
==============================================================================
--- commons/proper/vfs/trunk/core/src/main/java/org/apache/commons/vfs2/provider/tar/TarFileObject.java
(original)
+++ commons/proper/vfs/trunk/core/src/main/java/org/apache/commons/vfs2/provider/tar/TarFileObject.java
Fri Jul 20 21:59:48 2012
@@ -29,12 +29,11 @@ import org.apache.commons.vfs2.provider.
 /**
  * A file in a Tar file system.
  */
-public class TarFileObject extends AbstractFileObject
+public class TarFileObject extends AbstractFileObject<TarFileSystem>
 {
     /** The TarArchiveEntry */
     private TarArchiveEntry entry;
     private final HashSet<String> children = new HashSet<String>();
-    private final TarFileSystem fs;
     private FileType type;
 
     protected TarFileObject(AbstractFileName name,
@@ -43,7 +42,6 @@ public class TarFileObject extends Abstr
                             boolean tarExists) throws FileSystemException
     {
         super(name, fs);
-        this.fs = fs;
         setTarEntry(entry);
         if (!tarExists)
         {
@@ -170,6 +168,6 @@ public class TarFileObject extends Abstr
             throw new FileSystemException("vfs.provider/read-not-file.error", getName());
         }
 
-        return fs.getInputStream(entry);
+        return getAbstractFileSystem().getInputStream(entry);
     }
 }

Modified: commons/proper/vfs/trunk/core/src/main/java/org/apache/commons/vfs2/provider/url/UrlFileObject.java
URL: http://svn.apache.org/viewvc/commons/proper/vfs/trunk/core/src/main/java/org/apache/commons/vfs2/provider/url/UrlFileObject.java?rev=1363962&r1=1363961&r2=1363962&view=diff
==============================================================================
--- commons/proper/vfs/trunk/core/src/main/java/org/apache/commons/vfs2/provider/url/UrlFileObject.java
(original)
+++ commons/proper/vfs/trunk/core/src/main/java/org/apache/commons/vfs2/provider/url/UrlFileObject.java
Fri Jul 20 21:59:48 2012
@@ -38,7 +38,7 @@ import org.apache.commons.vfs2.provider.
  * @todo Implement set lastModified and get/set attribute
  * @todo Implement getOutputStream()
  */
-public class UrlFileObject extends AbstractFileObject
+public class UrlFileObject extends AbstractFileObject<UrlFileSystem>
 {
     private URL url;
 

Modified: commons/proper/vfs/trunk/core/src/main/java/org/apache/commons/vfs2/provider/zip/ZipFileObject.java
URL: http://svn.apache.org/viewvc/commons/proper/vfs/trunk/core/src/main/java/org/apache/commons/vfs2/provider/zip/ZipFileObject.java?rev=1363962&r1=1363961&r2=1363962&view=diff
==============================================================================
--- commons/proper/vfs/trunk/core/src/main/java/org/apache/commons/vfs2/provider/zip/ZipFileObject.java
(original)
+++ commons/proper/vfs/trunk/core/src/main/java/org/apache/commons/vfs2/provider/zip/ZipFileObject.java
Fri Jul 20 21:59:48 2012
@@ -29,12 +29,11 @@ import org.apache.commons.vfs2.provider.
 /**
  * A file in a Zip file system.
  */
-public class ZipFileObject extends AbstractFileObject
+public class ZipFileObject extends AbstractFileObject<ZipFileSystem>
 {
     /** The ZipEntry. */
     protected ZipEntry entry;
     private final HashSet<String> children = new HashSet<String>();
-    private final ZipFileSystem fs;
     // protected final ZipFile file;
 
     private FileType type;
@@ -45,7 +44,6 @@ public class ZipFileObject extends Abstr
                             boolean zipExists) throws FileSystemException
     {
         super(name, fs);
-        this.fs = fs;
         setZipEntry(entry);
         if (!zipExists)
         {
@@ -163,6 +161,6 @@ public class ZipFileObject extends Abstr
             throw new FileSystemException("vfs.provider/read-not-file.error", getName());
         }
 
-        return fs.getZipFile().getInputStream(entry);
+        return getAbstractFileSystem().getZipFile().getInputStream(entry);
     }
 }

Modified: commons/proper/vfs/trunk/src/changes/changes.xml
URL: http://svn.apache.org/viewvc/commons/proper/vfs/trunk/src/changes/changes.xml?rev=1363962&r1=1363961&r2=1363962&view=diff
==============================================================================
--- commons/proper/vfs/trunk/src/changes/changes.xml (original)
+++ commons/proper/vfs/trunk/src/changes/changes.xml Fri Jul 20 21:59:48 2012
@@ -23,6 +23,9 @@
 
   <body>
     <release version="2.1" date="TBD" description="New features and bug fix release.">
+      <action issue="VFS-429" dev="ggregory" type="add" due-to="awelynant">
+        Remove extra FileSystem ivar in AbstractFileObject subclasses with generics.
+      </action>
       <action issue="VFS-427" dev="ggregory" type="add" due-to="awelynant">
         [HTTP] NPE on HttpFileObject.getContent().getContentInfo().
       </action>



Mime
View raw message