commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ima...@apache.org
Subject svn commit: r484946 - in /jakarta/commons/proper/vfs/trunk: core/src/main/java/org/apache/commons/vfs/ core/src/main/java/org/apache/commons/vfs/provider/ core/src/main/java/org/apache/commons/vfs/provider/ftp/ core/src/main/java/org/apache/commons/vfs...
Date Sat, 09 Dec 2006 08:18:53 GMT
Author: imario
Date: Sat Dec  9 00:18:52 2006
New Revision: 484946

URL: http://svn.apache.org/viewvc?view=rev&rev=484946
Log:
VFS-99: refactored RandomAccessContent so that stream based rac content has to implement only
a basic set of methods

Added:
    jakarta/commons/proper/vfs/trunk/core/src/main/java/org/apache/commons/vfs/provider/AbstractRandomAccessStreamContent.java
  (with props)
Modified:
    jakarta/commons/proper/vfs/trunk/core/src/main/java/org/apache/commons/vfs/RandomAccessContent.java
    jakarta/commons/proper/vfs/trunk/core/src/main/java/org/apache/commons/vfs/provider/ftp/FtpRandomAccessContent.java
    jakarta/commons/proper/vfs/trunk/core/src/main/java/org/apache/commons/vfs/provider/http/HttpRandomAccesContent.java
    jakarta/commons/proper/vfs/trunk/core/src/main/java/org/apache/commons/vfs/provider/sftp/SftpRandomAccessContent.java
    jakarta/commons/proper/vfs/trunk/sandbox/src/main/java/org/apache/commons/vfs/provider/webdav/WebdavFileObject.java

Modified: jakarta/commons/proper/vfs/trunk/core/src/main/java/org/apache/commons/vfs/RandomAccessContent.java
URL: http://svn.apache.org/viewvc/jakarta/commons/proper/vfs/trunk/core/src/main/java/org/apache/commons/vfs/RandomAccessContent.java?view=diff&rev=484946&r1=484945&r2=484946
==============================================================================
--- jakarta/commons/proper/vfs/trunk/core/src/main/java/org/apache/commons/vfs/RandomAccessContent.java
(original)
+++ jakarta/commons/proper/vfs/trunk/core/src/main/java/org/apache/commons/vfs/RandomAccessContent.java
Sat Dec  9 00:18:52 2006
@@ -78,7 +78,7 @@
     public void close() throws IOException;
 
     /**
-     * get the inputstream interface
+     * get the input stream
      * <br/>
      * <b>Notice: If you use {@link #seek(long)} you have to reget the InputStream</b>
      */

Added: jakarta/commons/proper/vfs/trunk/core/src/main/java/org/apache/commons/vfs/provider/AbstractRandomAccessStreamContent.java
URL: http://svn.apache.org/viewvc/jakarta/commons/proper/vfs/trunk/core/src/main/java/org/apache/commons/vfs/provider/AbstractRandomAccessStreamContent.java?view=auto&rev=484946
==============================================================================
--- jakarta/commons/proper/vfs/trunk/core/src/main/java/org/apache/commons/vfs/provider/AbstractRandomAccessStreamContent.java
(added)
+++ jakarta/commons/proper/vfs/trunk/core/src/main/java/org/apache/commons/vfs/provider/AbstractRandomAccessStreamContent.java
Sat Dec  9 00:18:52 2006
@@ -0,0 +1,111 @@
+package org.apache.commons.vfs.provider;
+
+import org.apache.commons.vfs.RandomAccessContent;
+import org.apache.commons.vfs.util.RandomAccessMode;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.DataInputStream;
+
+/**
+ * Implements the part usable for all stream base random access implementations
+ *
+ * @author <a href="mailto:imario@apache.org">Mario Ivankovits</a>
+ * @version $Revision$ $Date$
+ */
+public abstract class AbstractRandomAccessStreamContent extends AbstractRandomAccessContent
+{
+    protected AbstractRandomAccessStreamContent(final RandomAccessMode mode)
+    {
+		super(mode);
+    }
+
+	protected abstract DataInputStream getDataInputStream() throws IOException;
+
+	public byte readByte() throws IOException
+	{
+		byte data = getDataInputStream().readByte();
+		return data;
+	}
+
+	public char readChar() throws IOException
+	{
+		char data = getDataInputStream().readChar();
+		return data;
+	}
+
+	public double readDouble() throws IOException
+	{
+		double data = getDataInputStream().readDouble();
+		return data;
+	}
+
+	public float readFloat() throws IOException
+	{
+		float data = getDataInputStream().readFloat();
+		return data;
+	}
+
+	public int readInt() throws IOException
+	{
+		int data = getDataInputStream().readInt();
+		return data;
+	}
+
+	public int readUnsignedByte() throws IOException
+	{
+		int data = getDataInputStream().readUnsignedByte();
+		return data;
+	}
+
+	public int readUnsignedShort() throws IOException
+	{
+		int data = getDataInputStream().readUnsignedShort();
+		return data;
+	}
+
+	public long readLong() throws IOException
+	{
+		long data = getDataInputStream().readLong();
+		return data;
+	}
+
+	public short readShort() throws IOException
+	{
+		short data = getDataInputStream().readShort();
+		return data;
+	}
+
+	public boolean readBoolean() throws IOException
+	{
+		boolean data = getDataInputStream().readBoolean();
+		return data;
+	}
+
+	public int skipBytes(int n) throws IOException
+	{
+		int data = getDataInputStream().skipBytes(n);
+		return data;
+	}
+
+	public void readFully(byte b[]) throws IOException
+	{
+		getDataInputStream().readFully(b);
+	}
+
+	public void readFully(byte b[], int off, int len) throws IOException
+	{
+		getDataInputStream().readFully(b, off, len);
+	}
+
+	public String readUTF() throws IOException
+	{
+		String data = getDataInputStream().readUTF();
+		return data;
+	}
+
+	public InputStream getInputStream() throws IOException
+	{
+		return getDataInputStream();
+	}
+}

Propchange: jakarta/commons/proper/vfs/trunk/core/src/main/java/org/apache/commons/vfs/provider/AbstractRandomAccessStreamContent.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: jakarta/commons/proper/vfs/trunk/core/src/main/java/org/apache/commons/vfs/provider/AbstractRandomAccessStreamContent.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Propchange: jakarta/commons/proper/vfs/trunk/core/src/main/java/org/apache/commons/vfs/provider/AbstractRandomAccessStreamContent.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Modified: jakarta/commons/proper/vfs/trunk/core/src/main/java/org/apache/commons/vfs/provider/ftp/FtpRandomAccessContent.java
URL: http://svn.apache.org/viewvc/jakarta/commons/proper/vfs/trunk/core/src/main/java/org/apache/commons/vfs/provider/ftp/FtpRandomAccessContent.java?view=diff&rev=484946&r1=484945&r2=484946
==============================================================================
--- jakarta/commons/proper/vfs/trunk/core/src/main/java/org/apache/commons/vfs/provider/ftp/FtpRandomAccessContent.java
(original)
+++ jakarta/commons/proper/vfs/trunk/core/src/main/java/org/apache/commons/vfs/provider/ftp/FtpRandomAccessContent.java
Sat Dec  9 00:18:52 2006
@@ -17,15 +17,14 @@
 package org.apache.commons.vfs.provider.ftp;
 
 import org.apache.commons.vfs.FileSystemException;
-import org.apache.commons.vfs.provider.AbstractRandomAccessContent;
+import org.apache.commons.vfs.provider.AbstractRandomAccessStreamContent;
 import org.apache.commons.vfs.util.RandomAccessMode;
 
 import java.io.DataInputStream;
 import java.io.FilterInputStream;
 import java.io.IOException;
-import java.io.InputStream;
 
-class FtpRandomAccessContent extends AbstractRandomAccessContent
+class FtpRandomAccessContent extends AbstractRandomAccessStreamContent
 {
     private final FtpFileObject fileObject;
 
@@ -70,11 +69,11 @@
         filePointer = pos;
     }
 
-    private void createStream() throws IOException
-    {
+	protected DataInputStream getDataInputStream() throws IOException
+	{
         if (dis != null)
         {
-            return;
+            return dis;
         }
 
         // FtpClient client = fileSystem.getClient();
@@ -116,7 +115,9 @@
                 FtpRandomAccessContent.this.close();
             }
         });
-    }
+
+		return dis;
+	}
 
 
     public void close() throws IOException
@@ -136,107 +137,5 @@
     public long length() throws IOException
     {
         return fileObject.getContent().getSize();
-    }
-
-    public byte readByte() throws IOException
-    {
-        createStream();
-        byte data = dis.readByte();
-        return data;
-    }
-
-    public char readChar() throws IOException
-    {
-        createStream();
-        char data = dis.readChar();
-        return data;
-    }
-
-    public double readDouble() throws IOException
-    {
-        createStream();
-        double data = dis.readDouble();
-        return data;
-    }
-
-    public float readFloat() throws IOException
-    {
-        createStream();
-        float data = dis.readFloat();
-        return data;
-    }
-
-    public int readInt() throws IOException
-    {
-        createStream();
-        int data = dis.readInt();
-        return data;
-    }
-
-    public int readUnsignedByte() throws IOException
-    {
-        createStream();
-        int data = dis.readUnsignedByte();
-        return data;
-    }
-
-    public int readUnsignedShort() throws IOException
-    {
-        createStream();
-        int data = dis.readUnsignedShort();
-        return data;
-    }
-
-    public long readLong() throws IOException
-    {
-        createStream();
-        long data = dis.readLong();
-        return data;
-    }
-
-    public short readShort() throws IOException
-    {
-        createStream();
-        short data = dis.readShort();
-        return data;
-    }
-
-    public boolean readBoolean() throws IOException
-    {
-        createStream();
-        boolean data = dis.readBoolean();
-        return data;
-    }
-
-    public int skipBytes(int n) throws IOException
-    {
-        createStream();
-        int data = dis.skipBytes(n);
-        return data;
-    }
-
-    public void readFully(byte b[]) throws IOException
-    {
-        createStream();
-        dis.readFully(b);
-    }
-
-    public void readFully(byte b[], int off, int len) throws IOException
-    {
-        createStream();
-        dis.readFully(b, off, len);
-    }
-
-    public String readUTF() throws IOException
-    {
-        createStream();
-        String data = dis.readUTF();
-        return data;
-    }
-
-    public InputStream getInputStream() throws IOException
-    {
-        createStream();
-        return dis;
     }
 }

Modified: jakarta/commons/proper/vfs/trunk/core/src/main/java/org/apache/commons/vfs/provider/http/HttpRandomAccesContent.java
URL: http://svn.apache.org/viewvc/jakarta/commons/proper/vfs/trunk/core/src/main/java/org/apache/commons/vfs/provider/http/HttpRandomAccesContent.java?view=diff&rev=484946&r1=484945&r2=484946
==============================================================================
--- jakarta/commons/proper/vfs/trunk/core/src/main/java/org/apache/commons/vfs/provider/http/HttpRandomAccesContent.java
(original)
+++ jakarta/commons/proper/vfs/trunk/core/src/main/java/org/apache/commons/vfs/provider/http/HttpRandomAccesContent.java
Sat Dec  9 00:18:52 2006
@@ -18,17 +18,16 @@
 
 import org.apache.commons.httpclient.methods.GetMethod;
 import org.apache.commons.vfs.FileSystemException;
-import org.apache.commons.vfs.provider.AbstractRandomAccessContent;
+import org.apache.commons.vfs.provider.AbstractRandomAccessStreamContent;
 import org.apache.commons.vfs.util.MonitorInputStream;
 import org.apache.commons.vfs.util.RandomAccessMode;
 
 import java.io.DataInputStream;
 import java.io.FilterInputStream;
 import java.io.IOException;
-import java.io.InputStream;
 import java.net.HttpURLConnection;
 
-class HttpRandomAccesContent extends AbstractRandomAccessContent
+class HttpRandomAccesContent extends AbstractRandomAccessStreamContent
 {
     private final HttpFileObject fileObject;
     private final HttpFileSystem fileSystem;
@@ -74,11 +73,11 @@
         filePointer = pos;
     }
 
-    private void createStream() throws IOException
-    {
+	protected DataInputStream getDataInputStream() throws IOException
+	{
         if (dis != null)
         {
-            return;
+            return dis;
         }
 
         final GetMethod getMethod = new GetMethod();
@@ -127,7 +126,9 @@
                 return ret;
             }
         });
-    }
+
+		return dis;
+	}
 
 
     public void close() throws IOException
@@ -143,107 +144,5 @@
     public long length() throws IOException
     {
         return fileObject.getContent().getSize();
-    }
-
-    public byte readByte() throws IOException
-    {
-        createStream();
-        byte data = dis.readByte();
-        return data;
-    }
-
-    public char readChar() throws IOException
-    {
-        createStream();
-        char data = dis.readChar();
-        return data;
-    }
-
-    public double readDouble() throws IOException
-    {
-        createStream();
-        double data = dis.readDouble();
-        return data;
-    }
-
-    public float readFloat() throws IOException
-    {
-        createStream();
-        float data = dis.readFloat();
-        return data;
-    }
-
-    public int readInt() throws IOException
-    {
-        createStream();
-        int data = dis.readInt();
-        return data;
-    }
-
-    public int readUnsignedByte() throws IOException
-    {
-        createStream();
-        int data = dis.readUnsignedByte();
-        return data;
-    }
-
-    public int readUnsignedShort() throws IOException
-    {
-        createStream();
-        int data = dis.readUnsignedShort();
-        return data;
-    }
-
-    public long readLong() throws IOException
-    {
-        createStream();
-        long data = dis.readLong();
-        return data;
-    }
-
-    public short readShort() throws IOException
-    {
-        createStream();
-        short data = dis.readShort();
-        return data;
-    }
-
-    public boolean readBoolean() throws IOException
-    {
-        createStream();
-        boolean data = dis.readBoolean();
-        return data;
-    }
-
-    public int skipBytes(int n) throws IOException
-    {
-        createStream();
-        int data = dis.skipBytes(n);
-        return data;
-    }
-
-    public void readFully(byte b[]) throws IOException
-    {
-        createStream();
-        dis.readFully(b);
-    }
-
-    public void readFully(byte b[], int off, int len) throws IOException
-    {
-        createStream();
-        dis.readFully(b, off, len);
-    }
-
-    public String readUTF() throws IOException
-    {
-        createStream();
-        String data = dis.readUTF();
-        return data;
-    }
-
-    public InputStream getInputStream() throws IOException
-    {
-        createStream();
-        return dis;
     }
 }

Modified: jakarta/commons/proper/vfs/trunk/core/src/main/java/org/apache/commons/vfs/provider/sftp/SftpRandomAccessContent.java
URL: http://svn.apache.org/viewvc/jakarta/commons/proper/vfs/trunk/core/src/main/java/org/apache/commons/vfs/provider/sftp/SftpRandomAccessContent.java?view=diff&rev=484946&r1=484945&r2=484946
==============================================================================
--- jakarta/commons/proper/vfs/trunk/core/src/main/java/org/apache/commons/vfs/provider/sftp/SftpRandomAccessContent.java
(original)
+++ jakarta/commons/proper/vfs/trunk/core/src/main/java/org/apache/commons/vfs/provider/sftp/SftpRandomAccessContent.java
Sat Dec  9 00:18:52 2006
@@ -17,7 +17,7 @@
 package org.apache.commons.vfs.provider.sftp;
 
 import org.apache.commons.vfs.FileSystemException;
-import org.apache.commons.vfs.provider.AbstractRandomAccessContent;
+import org.apache.commons.vfs.provider.AbstractRandomAccessStreamContent;
 import org.apache.commons.vfs.util.RandomAccessMode;
 
 import java.io.DataInputStream;
@@ -25,7 +25,7 @@
 import java.io.IOException;
 import java.io.InputStream;
 
-class SftpRandomAccessContent extends AbstractRandomAccessContent
+class SftpRandomAccessContent extends AbstractRandomAccessStreamContent
 {
     private final SftpFileObject fileObject;
 
@@ -70,11 +70,11 @@
         filePointer = pos;
     }
 
-    private void createStream() throws IOException
+	protected DataInputStream getDataInputStream() throws IOException
     {
         if (dis != null)
         {
-            return;
+            return dis;
         }
 
         // FtpClient client = fileSystem.getClient();
@@ -116,7 +116,9 @@
                 SftpRandomAccessContent.this.close();
             }
         });
-    }
+
+		return dis;
+	}
 
 
     public void close() throws IOException
@@ -137,107 +139,5 @@
     public long length() throws IOException
     {
         return fileObject.getContent().getSize();
-    }
-
-    public byte readByte() throws IOException
-    {
-        createStream();
-        byte data = dis.readByte();
-        return data;
-    }
-
-    public char readChar() throws IOException
-    {
-        createStream();
-        char data = dis.readChar();
-        return data;
-    }
-
-    public double readDouble() throws IOException
-    {
-        createStream();
-        double data = dis.readDouble();
-        return data;
-    }
-
-    public float readFloat() throws IOException
-    {
-        createStream();
-        float data = dis.readFloat();
-        return data;
-    }
-
-    public int readInt() throws IOException
-    {
-        createStream();
-        int data = dis.readInt();
-        return data;
-    }
-
-    public int readUnsignedByte() throws IOException
-    {
-        createStream();
-        int data = dis.readUnsignedByte();
-        return data;
-    }
-
-    public int readUnsignedShort() throws IOException
-    {
-        createStream();
-        int data = dis.readUnsignedShort();
-        return data;
-    }
-
-    public long readLong() throws IOException
-    {
-        createStream();
-        long data = dis.readLong();
-        return data;
-    }
-
-    public short readShort() throws IOException
-    {
-        createStream();
-        short data = dis.readShort();
-        return data;
-    }
-
-    public boolean readBoolean() throws IOException
-    {
-        createStream();
-        boolean data = dis.readBoolean();
-        return data;
-    }
-
-    public int skipBytes(int n) throws IOException
-    {
-        createStream();
-        int data = dis.skipBytes(n);
-        return data;
-    }
-
-    public void readFully(byte b[]) throws IOException
-    {
-        createStream();
-        dis.readFully(b);
-    }
-
-    public void readFully(byte b[], int off, int len) throws IOException
-    {
-        createStream();
-        dis.readFully(b, off, len);
-    }
-
-    public String readUTF() throws IOException
-    {
-        createStream();
-        String data = dis.readUTF();
-        return data;
-    }
-
-    public InputStream getInputStream() throws IOException
-    {
-        createStream();
-        return dis;
     }
 }

Modified: jakarta/commons/proper/vfs/trunk/sandbox/src/main/java/org/apache/commons/vfs/provider/webdav/WebdavFileObject.java
URL: http://svn.apache.org/viewvc/jakarta/commons/proper/vfs/trunk/sandbox/src/main/java/org/apache/commons/vfs/provider/webdav/WebdavFileObject.java?view=diff&rev=484946&r1=484945&r2=484946
==============================================================================
--- jakarta/commons/proper/vfs/trunk/sandbox/src/main/java/org/apache/commons/vfs/provider/webdav/WebdavFileObject.java
(original)
+++ jakarta/commons/proper/vfs/trunk/sandbox/src/main/java/org/apache/commons/vfs/provider/webdav/WebdavFileObject.java
Sat Dec  9 00:18:52 2006
@@ -29,6 +29,7 @@
 import org.apache.commons.vfs.provider.AbstractRandomAccessContent;
 import org.apache.commons.vfs.provider.GenericFileName;
 import org.apache.commons.vfs.provider.URLFileName;
+import org.apache.commons.vfs.provider.AbstractRandomAccessStreamContent;
 import org.apache.commons.vfs.util.FileObjectUtils;
 import org.apache.commons.vfs.util.MonitorOutputStream;
 import org.apache.commons.vfs.util.RandomAccessMode;
@@ -587,8 +588,8 @@
         return new WebdavRandomAccesContent(this, mode);
     }
 
-    public static class WebdavRandomAccesContent extends AbstractRandomAccessContent
-    {
+    public static class WebdavRandomAccesContent extends AbstractRandomAccessStreamContent
+	{
         private final WebdavFileObject fileObject;
 
         protected long filePointer = 0;
@@ -631,11 +632,11 @@
             filePointer = pos;
         }
 
-        private void createStream() throws IOException
+		protected DataInputStream getDataInputStream() throws IOException
         {
             if (dis != null)
             {
-                return;
+                return dis;
             }
 
             fileObject.resource.addRequestHeader("Range", "bytes="
@@ -684,7 +685,9 @@
                     return ret;
                 }
             });
-        }
+
+			return dis;
+		}
 
         public void close() throws IOException
         {
@@ -700,108 +703,5 @@
         {
             return fileObject.getContent().getSize();
         }
-
-        public byte readByte() throws IOException
-        {
-            createStream();
-            byte data = dis.readByte();
-            return data;
-        }
-
-        public char readChar() throws IOException
-        {
-            createStream();
-            char data = dis.readChar();
-            return data;
-        }
-
-        public double readDouble() throws IOException
-        {
-            createStream();
-            double data = dis.readDouble();
-            return data;
-        }
-
-        public float readFloat() throws IOException
-        {
-            createStream();
-            float data = dis.readFloat();
-            return data;
-        }
-
-        public int readInt() throws IOException
-        {
-            createStream();
-            int data = dis.readInt();
-            return data;
-        }
-
-        public int readUnsignedByte() throws IOException
-        {
-            createStream();
-            int data = dis.readUnsignedByte();
-            return data;
-        }
-
-        public int readUnsignedShort() throws IOException
-        {
-            createStream();
-            int data = dis.readUnsignedShort();
-            return data;
-        }
-
-        public long readLong() throws IOException
-        {
-            createStream();
-            long data = dis.readLong();
-            return data;
-        }
-
-        public short readShort() throws IOException
-        {
-            createStream();
-            short data = dis.readShort();
-            return data;
-        }
-
-        public boolean readBoolean() throws IOException
-        {
-            createStream();
-            boolean data = dis.readBoolean();
-            return data;
-        }
-
-        public int skipBytes(int n) throws IOException
-        {
-            createStream();
-            int data = dis.skipBytes(n);
-            return data;
-        }
-
-        public void readFully(byte b[]) throws IOException
-        {
-            createStream();
-            dis.readFully(b);
-        }
-
-        public void readFully(byte b[], int off, int len) throws IOException
-        {
-            createStream();
-            dis.readFully(b, off, len);
-        }
-
-        public String readUTF() throws IOException
-        {
-            createStream();
-            String data = dis.readUTF();
-            return data;
-        }
-
-        public InputStream getInputStream() throws IOException
-        {
-            createStream();
-            return dis;
-        }
     }
-
 }



---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org


Mime
View raw message