diff -ru CVS/classpath/java/io/BufferedInputStream.java updated/classpath/java/io/BufferedInputStream.java
--- CVS/classpath/java/io/BufferedInputStream.java	2010-06-18 20:19:44.000000000 +0400
+++ updated/classpath/java/io/BufferedInputStream.java	2010-06-18 21:00:44.000000000 +0400
@@ -1,5 +1,6 @@
 /* BufferedInputStream.java -- An input stream that implements buffering
-   Copyright (C) 1998, 1999, 2001, 2005  Free Software Foundation, Inc.
+   Copyright (C) 1998, 1999, 2001, 2005, 2010
+   Free Software Foundation, Inc.
 
 This file is part of GNU Classpath.
 
@@ -137,10 +138,15 @@
     super(in);
     if (size <= 0)
       throw new IllegalArgumentException();
-    buf = new byte[size];
-    // initialize pos & count to bufferSize, to prevent refill from
-    // allocating a new buffer (if the caller starts out by calling mark()).
-    pos = count = bufferSize = size;
+    if (in != null)
+      {
+        buf = new byte[size];
+        // initialize pos & count to bufferSize, to prevent refill from
+        // allocating a new buffer (if the caller starts out by calling
+        // mark()).
+        pos = count = size;
+      }
+    bufferSize = size;
   }
 
   /**
@@ -158,6 +164,8 @@
    */
   public synchronized int available() throws IOException
   {
+    if (buf == null)
+      throw new IOException("Stream closed");
     return count - pos + super.available();
   }
 
@@ -169,11 +177,14 @@
    */
   public void close() throws IOException
   {
-    // Free up the array memory.
-    buf = null;
-    pos = count = 0;
-    markpos = -1;
-    super.close();
+    if (buf != null)
+      {
+        // Free up the array memory.
+        buf = null;
+        pos = count = 0;
+        markpos = -1;
+        super.close();
+      }
   }
 
   /**
@@ -302,7 +313,7 @@
   public synchronized void reset() throws IOException
   {
     if (markpos == -1)
-      throw new IOException(buf == null ? "Stream closed." : "Invalid mark.");
+      throw new IOException(buf == null ? "Stream closed" : "Invalid mark");
 
     pos = markpos;
   }
@@ -320,9 +331,6 @@
    */
   public synchronized long skip(long n) throws IOException
   {
-    if (buf == null)
-      throw new IOException("Stream closed.");
-
     final long origN = n;
 
     while (n > 0L)
@@ -347,7 +355,7 @@
   private boolean refill() throws IOException
   {
     if (buf == null)
-      throw new IOException("Stream closed.");
+      throw new IOException("Stream closed");
 
     if (markpos == -1 || count - markpos >= marklimit)
       {
diff -ru CVS/classpath/java/io/BufferedOutputStream.java updated/classpath/java/io/BufferedOutputStream.java
--- CVS/classpath/java/io/BufferedOutputStream.java	2010-06-18 20:19:58.000000000 +0400
+++ updated/classpath/java/io/BufferedOutputStream.java	2010-06-18 21:05:40.000000000 +0400
@@ -1,5 +1,5 @@
 /* BufferedOutputStream.java -- Buffer output into large blocks before writing
-   Copyright (C) 1998, 2000, 2003 Free Software Foundation, Inc.
+   Copyright (C) 1998, 2000, 2003, 2010  Free Software Foundation, Inc.
 
 This file is part of GNU Classpath.
 
@@ -87,14 +87,27 @@
    *
    * @param out The underlying <code>OutputStream</code> to write data to
    * @param size The size of the internal buffer
+   *
+   * @exception IllegalArgumentException If <code>size</code> is non-positive
    */
   public BufferedOutputStream(OutputStream out, int size)
   {
     super(out);
 
+    if (size <= 0)
+      throw new IllegalArgumentException();
     buf = new byte[size];
   }
 
+  private void flushBuffer() throws IOException
+  {
+    if (count == 0)
+      return;
+
+    out.write(buf, 0, count);
+    count = 0;
+  }
+
   /**
    * This method causes any currently buffered bytes to be immediately
    * written to the underlying output stream.
@@ -103,11 +116,7 @@
    */
   public synchronized void flush() throws IOException
   {
-    if (count == 0)
-      return;
-
-    out.write(buf, 0, count);
-    count = 0;
+    flushBuffer();
     out.flush();
   }
 
@@ -149,10 +158,9 @@
   public synchronized void write(int b) throws IOException
   {
     if (count == buf.length)
-      flush();
+      flushBuffer();
 
-    buf[count] = (byte)(b & 0xFF);
-    ++count;
+    buf[count++] = (byte)b;
   }
 
   /**
@@ -171,10 +179,11 @@
   public synchronized void write(byte[] buf, int offset, int len)
     throws IOException
   {
-    // Buffer can hold everything.  Note that the case where LEN < 0
-    // is automatically handled by the downstream write.
-    if (len < (this.buf.length - count))
+    if (len < this.buf.length)
       {
+        if (len > this.buf.length - count)
+          flushBuffer();
+        // Buffer can hold everything.
         System.arraycopy(buf, offset, this.buf, count, len);
         count += len;
       }
@@ -183,8 +192,8 @@
         // The write was too big.  So flush the buffer and write the new
         // bytes directly to the underlying stream, per the JDK 1.2
         // docs.
-        flush();
-        out.write (buf, offset, len);
+        flushBuffer();
+        out.write(buf, offset, len);
       }
   }
 
diff -ru CVS/classpath/java/io/BufferedWriter.java updated/classpath/java/io/BufferedWriter.java
--- CVS/classpath/java/io/BufferedWriter.java	2010-06-18 20:21:16.000000000 +0400
+++ updated/classpath/java/io/BufferedWriter.java	2010-06-18 21:10:38.000000000 +0400
@@ -1,5 +1,5 @@
 /* BufferedWriter.java -- Buffer output into large blocks before writing
-   Copyright (C) 1998, 1999, 2000, 2001 Free Software Foundation, Inc.
+   Copyright (C) 1998, 1999, 2000, 2001, 2010  Free Software Foundation, Inc.
 
 This file is part of GNU Classpath.
 
@@ -66,20 +66,20 @@
    * This is the underlying <code>Writer</code> to which this object
    * sends its output.
    */
-  private Writer out;
+  private final Writer out;
 
   /**
    * This is the internal char array used for buffering output before
    * writing it.
    */
-  char[] buffer;
+  private char[] buffer;
 
   /**
    * This is the number of chars that are currently in the buffer and
    * are waiting to be written to the underlying stream.  It always points to
    * the index into the buffer where the next char of data will be stored
    */
-  int count;
+  private int count;
 
   /**
    * This method initializes a new <code>BufferedWriter</code> instance
@@ -100,12 +100,16 @@
    *
    * @param out The underlying <code>Writer</code> to write data to
    * @param size The size of the internal buffer
+   *
+   * @exception IllegalArgumentException If <code>size</code> is non-positive
    */
   public BufferedWriter (Writer out, int size)
   {
     super(out.lock);
+    if (size <= 0)
+      throw new IllegalArgumentException();
     this.out = out;
-    this.buffer = new char[size];
+    this.buffer = out != null ? new char[size] : null;
     this.count = 0;
   }
 
@@ -122,9 +126,17 @@
       {
         // It is safe to call localFlush even if the stream is already
         // closed.
-        localFlush ();
-        out.close();
-        buffer = null;
+        try
+          {
+            localFlush();
+            // Close the stream even if an error occurred while flushing.
+          }
+        finally
+          {
+            if (out != null)
+	      out.close();
+	    buffer = null;
+          }
       }
   }
 
diff -ru CVS/classpath/java/io/FilterOutputStream.java updated/classpath/java/io/FilterOutputStream.java
--- CVS/classpath/java/io/FilterOutputStream.java	2010-06-18 20:21:46.000000000 +0400
+++ updated/classpath/java/io/FilterOutputStream.java	2010-06-18 21:00:44.000000000 +0400
@@ -1,5 +1,6 @@
 /* FilterOutputStream.java -- Parent class for output streams that filter
-   Copyright (C) 1998, 1999, 2001, 2003, 2005  Free Software Foundation, Inc.
+   Copyright (C) 1998, 1999, 2001, 2003, 2005, 2010
+   Free Software Foundation, Inc.
 
 This file is part of GNU Classpath.
 
@@ -81,7 +82,14 @@
     */
   public void close() throws IOException
   {
-    flush();
+    try
+      {
+        flush();
+      }
+    catch (IOException e)
+      {
+        // ignore
+      }
     out.close();
   }
 
diff -ru CVS/classpath/java/io/PushbackInputStream.java updated/classpath/java/io/PushbackInputStream.java
--- CVS/classpath/java/io/PushbackInputStream.java	2010-06-18 20:20:30.000000000 +0400
+++ updated/classpath/java/io/PushbackInputStream.java	2010-06-18 21:05:18.000000000 +0400
@@ -1,5 +1,6 @@
 /* PushbackInputStream.java -- An input stream that can unread bytes
-   Copyright (C) 1998, 1999, 2001, 2002, 2005  Free Software Foundation, Inc.
+   Copyright (C) 1998, 1999, 2001, 2002, 2005, 2010
+   Free Software Foundation, Inc.
 
 This file is part of GNU Classpath.
 
@@ -91,14 +92,23 @@
    *
    * @param in The subordinate <code>InputStream</code> to read from
    * @param size The pushback buffer size to use
+   *
+   * @exception IllegalArgumentException If <code>size</code> is non-positive
    */
   public PushbackInputStream(InputStream in, int size)
   {
     super(in);
-    if (size < 0)
+    if (size <= 0)
       throw new IllegalArgumentException();
-    buf = new byte[size];
-    pos = buf.length;
+    if (in != null)
+      buf = new byte[size];
+    pos = size;
+  }
+
+  private void ensureOpen() throws IOException
+  {
+    if (buf == null)
+      throw new IOException("Stream closed");
   }
 
   /**
@@ -116,15 +126,9 @@
    */
   public int available() throws IOException
   {
-    try
-      {
-        return (buf.length - pos) + super.available();
-      }
-    catch (NullPointerException npe)
-      {
-        throw new IOException ("Stream closed");
-      }
-  }
+    ensureOpen();
+    return (buf.length - pos) + super.available();
+  } 
 
   /**
    * This method closes the stream and releases any associated resources.
@@ -133,8 +137,11 @@
    */
   public synchronized void close() throws IOException
   {
-    buf = null;
-    super.close();
+    if (buf != null)
+      {
+        buf = null;
+        super.close();
+      }
   }
 
   /**
@@ -175,6 +182,7 @@
    */
   public synchronized int read() throws IOException
   {
+    ensureOpen();
     if (pos < buf.length)
       return ((int) buf[pos++]) & 0xFF;
 
@@ -207,6 +215,7 @@
    */
   public synchronized int read(byte[] b, int off, int len) throws IOException
   {
+    ensureOpen();
     int numBytes = Math.min(buf.length - pos, len);
 
     if (numBytes > 0)
@@ -243,6 +252,7 @@
    */
   public synchronized void unread(int b) throws IOException
   {
+    ensureOpen();
     if (pos <= 0)
       throw new IOException("Insufficient space in pushback buffer");
 
@@ -287,6 +297,7 @@
   public synchronized void unread(byte[] b, int off, int len)
     throws IOException
   {
+    ensureOpen();
     if (pos < len)
       throw new IOException("Insufficient space in pushback buffer");
 
@@ -319,6 +330,7 @@
    */
   public synchronized long skip(long n) throws IOException
   {
+    ensureOpen();
     final long origN = n;
 
     if (n > 0L)
diff -ru CVS/classpath/java/io/RandomAccessFile.java updated/classpath/java/io/RandomAccessFile.java
--- CVS/classpath/java/io/RandomAccessFile.java	2010-06-18 20:21:04.000000000 +0400
+++ updated/classpath/java/io/RandomAccessFile.java	2010-06-18 21:00:44.000000000 +0400
@@ -1,5 +1,6 @@
 /* RandomAccessFile.java -- Class supporting random file I/O
-   Copyright (C) 1998, 1999, 2001, 2002, 2003, 2004, 2005  Free Software Foundation, Inc.
+   Copyright (C) 1998, 1999, 2001, 2002, 2003, 2004, 2005, 2010
+   Free Software Foundation, Inc.
 
 This file is part of GNU Classpath.
 
@@ -62,11 +63,11 @@
 {
 
   // The underlying file.
-  private FileChannelImpl ch;
-  private FileDescriptor fd;
+  private final FileChannelImpl ch;
+  private final FileDescriptor fd;
   // The corresponding input and output streams.
-  private DataOutputStream out;
-  private DataInputStream in;
+  private final DataOutputStream out;
+  private final DataInputStream in;
 
 
   /**
@@ -193,12 +194,7 @@
    */
   public final FileDescriptor getFD () throws IOException
   {
-    synchronized (this)
-      {
-        if (fd == null)
-          fd = new FileDescriptor (ch);
-        return fd;
-      }
+    return fd;
   }
 
   /**
@@ -235,14 +231,22 @@
 
     // FileChannel.truncate() can only shrink a file.
     // To expand it we need to seek forward and write at least one byte.
-    if (newLen < length())
+    long length = length();
+    if (newLen < length)
       ch.truncate (newLen);
-    else if (newLen > length())
+    else if (newLen > length)
       {
         long pos = getFilePointer();
-        seek(newLen - 1);
-        write(0);
-        seek(pos);
+        try
+          {
+            if (newLen - 1 != pos)
+              seek(newLen - 1);
+            write(0);
+          }
+        finally
+          {
+            seek(pos);
+          }
       }
   }
 
diff -ru CVS/classpath/java/io/Reader.java updated/classpath/java/io/Reader.java
--- CVS/classpath/java/io/Reader.java	2010-06-18 20:22:00.000000000 +0400
+++ updated/classpath/java/io/Reader.java	2010-06-18 21:05:00.000000000 +0400
@@ -1,5 +1,6 @@
 /* Reader.java -- base class of classes that read input as a stream of chars
-   Copyright (C) 1998, 1999, 2000, 2003, 2004, 2005  Free Software Foundation
+   Copyright (C) 1998, 1999, 2000, 2003, 2004, 2005, 2010
+   Free Software Foundation, Inc.
 
 This file is part of GNU Classpath.
 
@@ -262,11 +263,14 @@
     *
     * @return The actual number of chars skipped.
     *
+    * @exception IllegalArgumentException If <code>count</code> is negative
     * @exception IOException If an error occurs
     */
   public long skip(long count) throws IOException
   {
-    if (count <= 0)
+    if (count < 0)
+      throw new IllegalArgumentException("Skip value is negative");
+    if (count == 0)
       return 0;
     int bsize = count > 1024 ? 1024 : (int) count;
     char[] buffer = new char[bsize];
diff -ru CVS/classpath/java/io/Writer.java updated/classpath/java/io/Writer.java
--- CVS/classpath/java/io/Writer.java	2010-06-18 20:56:06.000000000 +0400
+++ updated/classpath/java/io/Writer.java	2010-06-18 21:00:44.000000000 +0400
@@ -1,5 +1,6 @@
 /* Writer.java -- Base class for character output streams
-   Copyright (C) 1998, 1999, 2001, 2003, 2004, 2005  Free Software Foundation, Inc.
+   Copyright (C) 1998, 1999, 2001, 2003, 2004, 2005, 2010
+   Free Software Foundation, Inc.
 
 This file is part of GNU Classpath.
 
@@ -205,7 +206,7 @@
   /** @since 1.5 */
   public Writer append(CharSequence cs, int start, int end) throws IOException
   {
-    write(cs == null ? "null" : cs.subSequence(start, end).toString());
+    write((cs == null ? "null" : cs).subSequence(start, end).toString());
     return this;
   }
 }
