commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From nia...@apache.org
Subject svn commit: r744371 - in /commons/proper/io/trunk/src/java/org/apache/commons/io: input/ProxyInputStream.java input/ProxyReader.java output/ProxyOutputStream.java output/ProxyWriter.java
Date Sat, 14 Feb 2009 02:32:20 GMT
Author: niallp
Date: Sat Feb 14 02:32:19 2009
New Revision: 744371

URL: http://svn.apache.org/viewvc?rev=744371&view=rev
Log:
IO-195 Provide exception handling methods in the Proxy streams/readers

Modified:
    commons/proper/io/trunk/src/java/org/apache/commons/io/input/ProxyInputStream.java
    commons/proper/io/trunk/src/java/org/apache/commons/io/input/ProxyReader.java
    commons/proper/io/trunk/src/java/org/apache/commons/io/output/ProxyOutputStream.java
    commons/proper/io/trunk/src/java/org/apache/commons/io/output/ProxyWriter.java

Modified: commons/proper/io/trunk/src/java/org/apache/commons/io/input/ProxyInputStream.java
URL: http://svn.apache.org/viewvc/commons/proper/io/trunk/src/java/org/apache/commons/io/input/ProxyInputStream.java?rev=744371&r1=744370&r2=744371&view=diff
==============================================================================
--- commons/proper/io/trunk/src/java/org/apache/commons/io/input/ProxyInputStream.java (original)
+++ commons/proper/io/trunk/src/java/org/apache/commons/io/input/ProxyInputStream.java Sat
Feb 14 02:32:19 2009
@@ -51,7 +51,12 @@
      */
     @Override
     public int read() throws IOException {
-        return in.read();
+        try {
+            return in.read();
+        } catch (IOException e) {
+            handleIOException(e);
+            return -1;
+        }
     }
 
     /**
@@ -62,7 +67,12 @@
      */
     @Override
     public int read(byte[] bts) throws IOException {
-        return in.read(bts);
+        try {
+            return in.read(bts);
+        } catch (IOException e) {
+            handleIOException(e);
+            return -1;
+        }
     }
 
     /**
@@ -75,7 +85,12 @@
      */
     @Override
     public int read(byte[] bts, int st, int end) throws IOException {
-        return in.read(bts, st, end);
+        try {
+            return in.read(bts, st, end);
+        } catch (IOException e) {
+            handleIOException(e);
+            return -1;
+        }
     }
 
     /**
@@ -86,7 +101,12 @@
      */
     @Override
     public long skip(long ln) throws IOException {
-        return in.skip(ln);
+        try {
+            return in.skip(ln);
+        } catch (IOException e) {
+            handleIOException(e);
+            return 0;
+        }
     }
 
     /**
@@ -96,7 +116,12 @@
      */
     @Override
     public int available() throws IOException {
-        return in.available();
+        try {
+            return super.available();
+        } catch (IOException e) {
+            handleIOException(e);
+            return 0;
+        }
     }
 
     /**
@@ -105,7 +130,11 @@
      */
     @Override
     public void close() throws IOException {
-        in.close();
+        try {
+            in.close();
+        } catch (IOException e) {
+            handleIOException(e);
+        }
     }
 
     /**
@@ -123,7 +152,11 @@
      */
     @Override
     public synchronized void reset() throws IOException {
-        in.reset();
+        try {
+            in.reset();
+        } catch (IOException e) {
+            handleIOException(e);
+        }
     }
 
     /**
@@ -135,4 +168,18 @@
         return in.markSupported();
     }
 
+
+    /**
+     * Handle any IOExceptions thrown.
+     * <p>
+     * This method provides a point to implement custom exception
+     * handling. The default behaviour is to re-throw the exception.
+     * @param e The IOException thrown
+     * @throws IOException if an I/O error occurs
+     * @since Commons IO 2.0
+     */
+    protected void handleIOException(IOException e) throws IOException {
+        throw e;
+    }
+ 
 }

Modified: commons/proper/io/trunk/src/java/org/apache/commons/io/input/ProxyReader.java
URL: http://svn.apache.org/viewvc/commons/proper/io/trunk/src/java/org/apache/commons/io/input/ProxyReader.java?rev=744371&r1=744370&r2=744371&view=diff
==============================================================================
--- commons/proper/io/trunk/src/java/org/apache/commons/io/input/ProxyReader.java (original)
+++ commons/proper/io/trunk/src/java/org/apache/commons/io/input/ProxyReader.java Sat Feb
14 02:32:19 2009
@@ -52,7 +52,12 @@
      */
     @Override
     public int read() throws IOException {
-        return in.read();
+        try {
+            return in.read();
+        } catch (IOException e) {
+            handleIOException(e);
+            return -1;
+        }
     }
 
     /**
@@ -63,7 +68,12 @@
      */
     @Override
     public int read(char[] chr) throws IOException {
-        return in.read(chr);
+        try {
+            return in.read(chr);
+        } catch (IOException e) {
+            handleIOException(e);
+            return -1;
+        }
     }
 
     /**
@@ -76,7 +86,12 @@
      */
     @Override
     public int read(char[] chr, int st, int end) throws IOException {
-        return in.read(chr, st, end);
+        try {
+            return in.read(chr, st, end);
+        } catch (IOException e) {
+            handleIOException(e);
+            return -1;
+        }
     }
 
     /**
@@ -88,7 +103,12 @@
      */
     @Override
     public int read(CharBuffer target) throws IOException {
-        return in.read(target);
+        try {
+            return in.read(target);
+        } catch (IOException e) {
+            handleIOException(e);
+            return -1;
+        }
     }
 
     /**
@@ -99,7 +119,12 @@
      */
     @Override
     public long skip(long ln) throws IOException {
-        return in.skip(ln);
+        try {
+            return in.skip(ln);
+        } catch (IOException e) {
+            handleIOException(e);
+            return 0;
+        }
     }
 
     /**
@@ -109,7 +134,12 @@
      */
     @Override
     public boolean ready() throws IOException {
-        return in.ready();
+        try {
+            return in.ready();
+        } catch (IOException e) {
+            handleIOException(e);
+            return false;
+        }
     }
 
     /**
@@ -118,7 +148,11 @@
      */
     @Override
     public void close() throws IOException {
-        in.close();
+        try {
+            in.close();
+        } catch (IOException e) {
+            handleIOException(e);
+        }
     }
 
     /**
@@ -128,7 +162,11 @@
      */
     @Override
     public synchronized void mark(int idx) throws IOException {
-        in.mark(idx);
+        try {
+            in.mark(idx);
+        } catch (IOException e) {
+            handleIOException(e);
+        }
     }
 
     /**
@@ -137,7 +175,11 @@
      */
     @Override
     public synchronized void reset() throws IOException {
-        in.reset();
+        try {
+            in.reset();
+        } catch (IOException e) {
+            handleIOException(e);
+        }
     }
 
     /**
@@ -149,4 +191,17 @@
         return in.markSupported();
     }
 
+    /**
+     * Handle any IOExceptions thrown.
+     * <p>
+     * This method provides a point to implement custom exception
+     * handling. The default behaviour is to re-throw the exception.
+     * @param e The IOException thrown
+     * @throws IOException if an I/O error occurs
+     * @since Commons IO 2.0
+     */
+    protected void handleIOException(IOException e) throws IOException {
+        throw e;
+    }
+
 }

Modified: commons/proper/io/trunk/src/java/org/apache/commons/io/output/ProxyOutputStream.java
URL: http://svn.apache.org/viewvc/commons/proper/io/trunk/src/java/org/apache/commons/io/output/ProxyOutputStream.java?rev=744371&r1=744370&r2=744371&view=diff
==============================================================================
--- commons/proper/io/trunk/src/java/org/apache/commons/io/output/ProxyOutputStream.java (original)
+++ commons/proper/io/trunk/src/java/org/apache/commons/io/output/ProxyOutputStream.java Sat
Feb 14 02:32:19 2009
@@ -48,7 +48,11 @@
      */
     @Override
     public void write(int idx) throws IOException {
-        out.write(idx);
+        try {
+            out.write(idx);
+        } catch (IOException e) {
+            handleIOException(e);
+        }
     }
 
     /**
@@ -58,7 +62,11 @@
      */
     @Override
     public void write(byte[] bts) throws IOException {
-        out.write(bts);
+        try {
+            out.write(bts);
+        } catch (IOException e) {
+            handleIOException(e);
+        }
     }
 
     /**
@@ -70,7 +78,11 @@
      */
     @Override
     public void write(byte[] bts, int st, int end) throws IOException {
-        out.write(bts, st, end);
+        try {
+            out.write(bts, st, end);
+        } catch (IOException e) {
+            handleIOException(e);
+        }
     }
 
     /**
@@ -79,7 +91,11 @@
      */
     @Override
     public void flush() throws IOException {
-        out.flush();
+        try {
+            out.flush();
+        } catch (IOException e) {
+            handleIOException(e);
+        }
     }
 
     /**
@@ -88,7 +104,24 @@
      */
     @Override
     public void close() throws IOException {
-        out.close();
+        try {
+            out.close();
+        } catch (IOException e) {
+            handleIOException(e);
+        }
+    }
+
+    /**
+     * Handle any IOExceptions thrown.
+     * <p>
+     * This method provides a point to implement custom exception
+     * handling. The default behaviour is to re-throw the exception.
+     * @param e The IOException thrown
+     * @throws IOException if an I/O error occurs
+     * @since Commons IO 2.0
+     */
+    protected void handleIOException(IOException e) throws IOException {
+        throw e;
     }
 
 }

Modified: commons/proper/io/trunk/src/java/org/apache/commons/io/output/ProxyWriter.java
URL: http://svn.apache.org/viewvc/commons/proper/io/trunk/src/java/org/apache/commons/io/output/ProxyWriter.java?rev=744371&r1=744370&r2=744371&view=diff
==============================================================================
--- commons/proper/io/trunk/src/java/org/apache/commons/io/output/ProxyWriter.java (original)
+++ commons/proper/io/trunk/src/java/org/apache/commons/io/output/ProxyWriter.java Sat Feb
14 02:32:19 2009
@@ -52,7 +52,11 @@
      */
     @Override
     public Writer append(char c) throws IOException {
-        out.append(c);
+        try {
+            out.append(c);
+        } catch (IOException e) {
+            handleIOException(e);
+        }
         return this;
     }
 
@@ -67,7 +71,11 @@
      */
     @Override
     public Writer append(CharSequence csq, int start, int end) throws IOException {
-        out.append(csq, start, end);
+        try {
+            out.append(csq, start, end);
+        } catch (IOException e) {
+            handleIOException(e);
+        }
         return this;
     }
 
@@ -80,7 +88,11 @@
      */
     @Override
     public Writer append(CharSequence csq) throws IOException {
-        out.append(csq);
+        try {
+            out.append(csq);
+        } catch (IOException e) {
+            handleIOException(e);
+        }
         return this;
     }
 
@@ -91,7 +103,11 @@
      */
     @Override
     public void write(int idx) throws IOException {
-        out.write(idx);
+        try {
+            out.write(idx);
+        } catch (IOException e) {
+            handleIOException(e);
+        }
     }
 
     /**
@@ -101,7 +117,11 @@
      */
     @Override
     public void write(char[] chr) throws IOException {
-        out.write(chr);
+        try {
+            out.write(chr);
+        } catch (IOException e) {
+            handleIOException(e);
+        }
     }
 
     /**
@@ -113,7 +133,11 @@
      */
     @Override
     public void write(char[] chr, int st, int end) throws IOException {
-        out.write(chr, st, end);
+        try {
+            out.write(chr, st, end);
+        } catch (IOException e) {
+            handleIOException(e);
+        }
     }
 
     /**
@@ -123,7 +147,11 @@
      */
     @Override
     public void write(String str) throws IOException {
-        out.write(str);
+        try {
+            out.write(str);
+        } catch (IOException e) {
+            handleIOException(e);
+        }
     }
 
     /**
@@ -135,7 +163,11 @@
      */
     @Override
     public void write(String str, int st, int end) throws IOException {
-        out.write(str, st, end);
+        try {
+            out.write(str, st, end);
+        } catch (IOException e) {
+            handleIOException(e);
+        }
     }
 
     /**
@@ -144,7 +176,11 @@
      */
     @Override
     public void flush() throws IOException {
-        out.flush();
+        try {
+            out.flush();
+        } catch (IOException e) {
+            handleIOException(e);
+        }
     }
 
     /**
@@ -153,7 +189,24 @@
      */
     @Override
     public void close() throws IOException {
-        out.close();
+        try {
+            out.close();
+        } catch (IOException e) {
+            handleIOException(e);
+        }
+    }
+
+    /**
+     * Handle any IOExceptions thrown.
+     * <p>
+     * This method provides a point to implement custom exception
+     * handling. The default behaviour is to re-throw the exception.
+     * @param e The IOException thrown
+     * @throws IOException if an I/O error occurs
+     * @since Commons IO 2.0
+     */
+    protected void handleIOException(IOException e) throws IOException {
+        throw e;
     }
 
 }



Mime
View raw message