You are viewing a plain text version of this content. The canonical link for it is here.
Posted to server-dev@james.apache.org by ba...@apache.org on 2008/08/07 11:01:32 UTC

svn commit: r683563 - in /james/mime4j/trunk/src/main/java/org/apache/james/mime4j/stream: CloseShieldInputStream.java PositionInputStream.java RootInputStream.java

Author: bago
Date: Thu Aug  7 02:01:31 2008
New Revision: 683563

URL: http://svn.apache.org/viewvc?rev=683563&view=rev
Log:
Make it explicit this InputStreams act as FilterInputStreams (they take another InputStream in the constructor).

Modified:
    james/mime4j/trunk/src/main/java/org/apache/james/mime4j/stream/CloseShieldInputStream.java
    james/mime4j/trunk/src/main/java/org/apache/james/mime4j/stream/PositionInputStream.java
    james/mime4j/trunk/src/main/java/org/apache/james/mime4j/stream/RootInputStream.java

Modified: james/mime4j/trunk/src/main/java/org/apache/james/mime4j/stream/CloseShieldInputStream.java
URL: http://svn.apache.org/viewvc/james/mime4j/trunk/src/main/java/org/apache/james/mime4j/stream/CloseShieldInputStream.java?rev=683563&r1=683562&r2=683563&view=diff
==============================================================================
--- james/mime4j/trunk/src/main/java/org/apache/james/mime4j/stream/CloseShieldInputStream.java (original)
+++ james/mime4j/trunk/src/main/java/org/apache/james/mime4j/stream/CloseShieldInputStream.java Thu Aug  7 02:01:31 2008
@@ -19,29 +19,22 @@
 
 package org.apache.james.mime4j.stream;
 
+import java.io.FilterInputStream;
 import java.io.InputStream;
 import java.io.IOException;
 
 /**
  * InputStream that shields its underlying input stream from
  * being closed.
- * 
- * 
- * @version $Id: CloseShieldInputStream.java,v 1.2 2004/10/02 12:41:10 ntherning Exp $
  */
-public class CloseShieldInputStream extends InputStream {
-
-    /**
-     * Underlying InputStream
-     */
-    private InputStream is;
+public class CloseShieldInputStream extends FilterInputStream {
 
     public CloseShieldInputStream(InputStream is) {
-        this.is = is;
+        super(is);
     }
 
     public InputStream getUnderlyingStream() {
-        return is;
+        return in;
     }
 
     /**
@@ -49,7 +42,7 @@
      */
     public int read() throws IOException {
         checkIfClosed();
-        return is.read();
+        return in.read();
     }
 
     /**
@@ -57,7 +50,7 @@
      */
     public int available() throws IOException {
         checkIfClosed();
-        return is.available();
+        return in.available();
     }
 
     
@@ -65,7 +58,7 @@
      * Set the underlying InputStream to null
      */
     public void close() throws IOException {
-        is = null;
+        in = null;
     }
 
     /**
@@ -73,24 +66,24 @@
      */
     public synchronized void reset() throws IOException {
         checkIfClosed();
-        is.reset();
+        in.reset();
     }
 
     /**
      * @see java.io.FilterInputStream#markSupported()
      */
     public boolean markSupported() {
-        if (is == null)
+        if (in == null)
             return false;
-        return is.markSupported();
+        return in.markSupported();
     }
 
     /**
      * @see java.io.FilterInputStream#mark(int)
      */
     public synchronized void mark(int readlimit) {
-        if (is != null)
-            is.mark(readlimit);
+        if (in != null)
+            in.mark(readlimit);
     }
 
     /**
@@ -98,7 +91,7 @@
      */
     public long skip(long n) throws IOException {
         checkIfClosed();
-        return is.skip(n);
+        return in.skip(n);
     }
 
     /**
@@ -106,7 +99,7 @@
      */
     public int read(byte b[]) throws IOException {
         checkIfClosed();
-        return is.read(b);
+        return in.read(b);
     }
 
     /**
@@ -114,7 +107,7 @@
      */
     public int read(byte b[], int off, int len) throws IOException {
         checkIfClosed();
-        return is.read(b, off, len);
+        return in.read(b, off, len);
     }
 
     /**
@@ -123,7 +116,7 @@
      * @throws IOException if the underlying InputStream is null
      */
     private void checkIfClosed() throws IOException {
-        if (is == null)
+        if (in == null)
             throw new IOException("Stream is closed");
     }
 }

Modified: james/mime4j/trunk/src/main/java/org/apache/james/mime4j/stream/PositionInputStream.java
URL: http://svn.apache.org/viewvc/james/mime4j/trunk/src/main/java/org/apache/james/mime4j/stream/PositionInputStream.java?rev=683563&r1=683562&r2=683563&view=diff
==============================================================================
--- james/mime4j/trunk/src/main/java/org/apache/james/mime4j/stream/PositionInputStream.java (original)
+++ james/mime4j/trunk/src/main/java/org/apache/james/mime4j/stream/PositionInputStream.java Thu Aug  7 02:01:31 2008
@@ -20,17 +20,17 @@
 
 package org.apache.james.mime4j.stream;
 
+import java.io.FilterInputStream;
 import java.io.InputStream;
 import java.io.IOException;
 
-public class PositionInputStream extends InputStream {
+public class PositionInputStream extends FilterInputStream {
 
-    private final InputStream inputStream;
     protected long position = 0;
     private long markedPosition = 0;
 
     public PositionInputStream(InputStream inputStream) {
-        this.inputStream = inputStream;
+        super(inputStream);
     }
 
     public long getPosition() {
@@ -38,42 +38,42 @@
     }
 
     public int available() throws IOException {
-        return inputStream.available();
+        return in.available();
     }
 
     public int read() throws IOException {
-        int b = inputStream.read();
+        int b = in.read();
         if (b != -1)
             position++;
         return b;
     }
 
     public void close() throws IOException {
-        inputStream.close();
+        in.close();
     }
 
     public void reset() throws IOException {
-        inputStream.reset();
+        in.reset();
         position = markedPosition;
     }
 
     public boolean markSupported() {
-        return inputStream.markSupported();
+        return in.markSupported();
     }
 
     public void mark(int readlimit) {
-        inputStream.mark(readlimit);
+        in.mark(readlimit);
         markedPosition = position;
     }
 
     public long skip(long n) throws IOException {
-        final long c = inputStream.skip(n);
+        final long c = in.skip(n);
         position += c;
         return c;
     }
 
     public int read(byte b[], int off, int len) throws IOException {
-        final int c = inputStream.read(b, off, len);
+        final int c = in.read(b, off, len);
         position += c;
         return c;
     }

Modified: james/mime4j/trunk/src/main/java/org/apache/james/mime4j/stream/RootInputStream.java
URL: http://svn.apache.org/viewvc/james/mime4j/trunk/src/main/java/org/apache/james/mime4j/stream/RootInputStream.java?rev=683563&r1=683562&r2=683563&view=diff
==============================================================================
--- james/mime4j/trunk/src/main/java/org/apache/james/mime4j/stream/RootInputStream.java (original)
+++ james/mime4j/trunk/src/main/java/org/apache/james/mime4j/stream/RootInputStream.java Thu Aug  7 02:01:31 2008
@@ -19,6 +19,7 @@
 
 package org.apache.james.mime4j.stream;
 
+import java.io.FilterInputStream;
 import java.io.IOException;
 import java.io.InputStream;
 
@@ -28,12 +29,8 @@
  * can also be truncated. When truncated the stream will appear to have
  * reached end of file. This is used by the parser's 
  * {@link org.apache.james.mime4j.parser.MimeStreamParser#stop()} method.
- *
- * 
- * @version $Id: RootInputStream.java,v 1.2 2004/10/02 12:41:10 ntherning Exp $
  */
-public class RootInputStream extends InputStream {
-    private InputStream is = null;
+public class RootInputStream extends FilterInputStream {
     private int lineNumber = 1;
     private int prev = -1;
     private boolean truncated = false;
@@ -44,7 +41,7 @@
      * @param in the stream to read from.
      */
     public RootInputStream(InputStream is) {
-        this.is = is;
+        super(is);
     }
 
     /**
@@ -75,7 +72,7 @@
             return -1;
         }
         
-        int b = is.read();
+        int b = in.read();
         if (prev == '\r' && b == '\n') {
             lineNumber++;
         }
@@ -92,7 +89,7 @@
             return -1;
         }
         
-        int n = is.read(b, off, len);
+        int n = in.read(b, off, len);
         for (int i = off; i < off + n; i++) {
             if (prev == '\r' && b[i] == '\n') {
                 lineNumber++;



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