diff --git a/src/java/com/samskivert/io/StreamUtil.java b/src/java/com/samskivert/io/StreamUtil.java index 58d387ec..9adfea0c 100644 --- a/src/java/com/samskivert/io/StreamUtil.java +++ b/src/java/com/samskivert/io/StreamUtil.java @@ -3,9 +3,11 @@ package com.samskivert.io; -import java.io.InputStream; import java.io.IOException; +import java.io.InputStream; import java.io.OutputStream; +import java.io.Reader; +import java.io.Writer; import com.samskivert.Log; @@ -23,8 +25,7 @@ public class StreamUtil try { in.close(); } catch (IOException ioe) { - Log.warning("Error closing input stream [stream=" + in + - ", cause=" + ioe + "]."); + Log.warning("Error closing input stream [stream=" + in + ", cause=" + ioe + "]."); } } } @@ -38,8 +39,35 @@ public class StreamUtil try { out.close(); } catch (IOException ioe) { - Log.warning("Error closing output stream [stream=" + out + - ", cause=" + ioe + "]."); + Log.warning("Error closing output stream [stream=" + out + ", cause=" + ioe + "]."); + } + } + } + + /** + * Convenient close for a reader. Use in a finally clause and love life. + */ + public static void close (Reader in) + { + if (in != null) { + try { + in.close(); + } catch (IOException ioe) { + Log.warning("Error closing input reader [reader=" + in + ", cause=" + ioe + "]."); + } + } + } + + /** + * Convenient close for a writer. Use in a finally clause and love life. + */ + public static void close (Writer out) + { + if (out != null) { + try { + out.close(); + } catch (IOException ioe) { + Log.warning("Error closing output writer [writer=" + out + ", cause=" + ioe + "]."); } } }