harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From telli...@apache.org
Subject svn commit: r492652 [1/13] - /harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/io/
Date Thu, 04 Jan 2007 17:47:05 GMT
Author: tellison
Date: Thu Jan  4 09:47:01 2007
New Revision: 492652

URL: http://svn.apache.org/viewvc?view=rev&rev=492652
Log:
Results of manual code review of all types in java.io for clarity, formatting, comments, etc.


Modified:
    harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/io/BufferedReader.java
    harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/io/BufferedWriter.java
    harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/io/ByteArrayInputStream.java
    harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/io/ByteArrayOutputStream.java
    harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/io/CharArrayReader.java
    harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/io/CharArrayWriter.java
    harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/io/CharConversionException.java
    harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/io/Closeable.java
    harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/io/DataInput.java
    harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/io/DataInputStream.java
    harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/io/DataOutput.java
    harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/io/DataOutputStream.java
    harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/io/EOFException.java
    harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/io/EmulatedFields.java
    harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/io/EmulatedFieldsForDumping.java
    harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/io/EmulatedFieldsForLoading.java
    harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/io/Externalizable.java
    harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/io/File.java
    harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/io/FileDescriptor.java
    harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/io/FileInputStream.java
    harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/io/FileNotFoundException.java
    harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/io/FileOutputStream.java
    harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/io/FilePermission.java
    harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/io/FilePermissionCollection.java
    harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/io/FileReader.java
    harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/io/FileWriter.java
    harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/io/FilenameFilter.java
    harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/io/FilterInputStream.java
    harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/io/FilterOutputStream.java
    harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/io/FilterReader.java
    harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/io/FilterWriter.java
    harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/io/Flushable.java
    harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/io/IOException.java
    harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/io/InputStream.java
    harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/io/InputStreamReader.java
    harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/io/InterruptedIOException.java
    harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/io/InvalidClassException.java
    harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/io/InvalidObjectException.java
    harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/io/LineNumberInputStream.java
    harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/io/LineNumberReader.java
    harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/io/NotActiveException.java
    harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/io/NotSerializableException.java
    harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/io/ObjectInput.java
    harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/io/ObjectInputStream.java
    harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/io/ObjectInputValidation.java
    harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/io/ObjectOutput.java
    harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/io/ObjectOutputStream.java
    harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/io/ObjectStreamClass.java
    harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/io/ObjectStreamConstants.java
    harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/io/ObjectStreamException.java
    harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/io/ObjectStreamField.java
    harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/io/OptionalDataException.java
    harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/io/OutputStream.java
    harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/io/OutputStreamWriter.java
    harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/io/PipedInputStream.java
    harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/io/PipedOutputStream.java
    harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/io/PipedReader.java
    harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/io/PipedWriter.java
    harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/io/PrintStream.java
    harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/io/PrintWriter.java
    harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/io/PushbackInputStream.java
    harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/io/PushbackReader.java
    harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/io/RandomAccessFile.java
    harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/io/Reader.java
    harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/io/SequenceInputStream.java
    harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/io/Serializable.java
    harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/io/SerializablePermission.java
    harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/io/StreamCorruptedException.java
    harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/io/StreamTokenizer.java
    harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/io/StringBufferInputStream.java
    harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/io/StringReader.java
    harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/io/StringWriter.java
    harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/io/SyncFailedException.java
    harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/io/UTFDataFormatException.java
    harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/io/UnsupportedEncodingException.java
    harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/io/WriteAbortedException.java
    harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/io/Writer.java

Modified: harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/io/BufferedReader.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/io/BufferedReader.java?view=diff&rev=492652&r1=492651&r2=492652
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/io/BufferedReader.java (original)
+++ harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/io/BufferedReader.java Thu Jan  4 09:47:01 2007
@@ -19,7 +19,6 @@
 
 import org.apache.harmony.luni.util.Msg;
 
-
 /**
  * BufferedReader is a buffered character input reader. Buffering allows reading
  * from character streams more efficiently. If the default size of the buffer is
@@ -38,466 +37,451 @@
  * @see BufferedWriter
  * @since 1.1
  */
-
 public class BufferedReader extends Reader {
-	private Reader in;
 
-	private char[] buf;
+    private Reader in;
+
+    private char[] buf;
 
-	private int marklimit = -1;
+    private int marklimit = -1;
 
-	private int count;
+    private int count;
 
-	private int markpos = -1;
-
-	private int pos;
-
-	/**
-	 * Constructs a new BufferedReader on the Reader <code>in</code>. The
-	 * default buffer size (8K) is allocated and all reads can now be filtered
-	 * through this BufferedReader.
-	 * 
-	 * @param in
-	 *            the Reader to buffer reads on.
-	 */
-
-	public BufferedReader(Reader in) {
-		super(in);
-		this.in = in;
-		buf = new char[8192];
-	}
-
-	/**
-	 * Constructs a new BufferedReader on the Reader <code>in</code>. The
-	 * buffer size is specified by the parameter <code>size</code> and all
-	 * reads can now be filtered through this BufferedReader.
-	 * 
-	 * @param in
-	 *            the Reader to buffer reads on.
-	 * @param size
-	 *            the size of buffer to allocate.
-	 * @throws IllegalArgumentException 
-	 *            if the size is <= 0         
-	 */
-
-	public BufferedReader(Reader in, int size) {
-		super(in);
-		if (size > 0) {
-			this.in = in;
-			buf = new char[size];
-		} else {
+    private int markpos = -1;
+
+    private int pos;
+
+    /**
+     * Constructs a new BufferedReader on the Reader <code>in</code>. The
+     * default buffer size (8K) is allocated and all reads can now be filtered
+     * through this BufferedReader.
+     * 
+     * @param in
+     *            the Reader to buffer reads on.
+     */
+    public BufferedReader(Reader in) {
+        super(in);
+        this.in = in;
+        buf = new char[8192];
+    }
+
+    /**
+     * Constructs a new BufferedReader on the Reader <code>in</code>. The
+     * buffer size is specified by the parameter <code>size</code> and all
+     * reads can now be filtered through this BufferedReader.
+     * 
+     * @param in
+     *            the Reader to buffer reads on.
+     * @param size
+     *            the size of buffer to allocate.
+     * @throws IllegalArgumentException
+     *             if the size is <= 0
+     */
+    public BufferedReader(Reader in, int size) {
+        super(in);
+        if (size <= 0) {
             throw new IllegalArgumentException(Msg.getString("K0058")); //$NON-NLS-1$
         }
-	}
-
-	/**
-	 * Close the Reader. This implementation closes the Reader being filtered
-	 * and releases the buffer used by this reader. If this BufferedReader has
-	 * already been closed, nothing is done.
-	 * 
-	 * @throws IOException
-	 *             If an error occurs attempting to close this BufferedReader.
-	 */
-
-	@Override
+        this.in = in;
+        buf = new char[size];
+    }
+
+    /**
+     * Close the Reader. This implementation closes the Reader being filtered
+     * and releases the buffer used by this reader. If this BufferedReader has
+     * already been closed, nothing is done.
+     * 
+     * @throws IOException
+     *             If an error occurs attempting to close this BufferedReader.
+     */
+    @Override
     public void close() throws IOException {
-		synchronized (lock) {
-			if (isOpen()) {
-				in.close();
-				buf = null;
-			}
-		}
-	}
-
-	private int fillbuf() throws IOException {
-		if (markpos == -1 || (pos - markpos >= marklimit)) {
-			/* Mark position not set or exceeded readlimit */
-			int result = in.read(buf, 0, buf.length);
-			if (result > 0) {
-				markpos = -1;
-				pos = 0;
-				count = result == -1 ? 0 : result;
-			}
-			return result;
-		}
-		if (markpos == 0 && marklimit > buf.length) {
-			/* Increase buffer size to accommodate the readlimit */
-			int newLength = buf.length * 2;
-			if (newLength > marklimit) {
+        synchronized (lock) {
+            if (!isClosed()) {
+                in.close();
+                buf = null;
+            }
+        }
+    }
+
+    private int fillbuf() throws IOException {
+        if (markpos == -1 || (pos - markpos >= marklimit)) {
+            /* Mark position not set or exceeded readlimit */
+            int result = in.read(buf, 0, buf.length);
+            if (result > 0) {
+                markpos = -1;
+                pos = 0;
+                count = result == -1 ? 0 : result;
+            }
+            return result;
+        }
+        if (markpos == 0 && marklimit > buf.length) {
+            /* Increase buffer size to accommodate the readlimit */
+            int newLength = buf.length * 2;
+            if (newLength > marklimit) {
                 newLength = marklimit;
             }
-			char[] newbuf = new char[newLength];
-			System.arraycopy(buf, 0, newbuf, 0, buf.length);
-			buf = newbuf;
-		} else if (markpos > 0) {
-			System.arraycopy(buf, markpos, buf, 0, buf.length - markpos);
-		}
-
-		/* Set the new position and mark position */
-		pos -= markpos;
-		count = markpos = 0;
-		int charsread = in.read(buf, pos, buf.length - pos);
-		count = charsread == -1 ? pos : pos + charsread;
-		return charsread;
-	}
-
-	/**
-	 * Answer a boolean indicating whether or not this BufferedReader is open.
-	 * 
-	 * @return <code>true</code> if this reader is open, <code>false</code>
-	 *         otherwise
-	 */
-	private boolean isOpen() {
-		return buf != null;
-	}
-
-	/**
-	 * Set a Mark position in this BufferedReader. The parameter
-	 * <code>readLimit</code> indicates how many characters can be read before
-	 * a mark is invalidated. Sending reset() will reposition the reader back to
-	 * the marked position provided <code>readLimit</code> has not been
-	 * surpassed.
-	 * 
-	 * @param readlimit
-	 *            an int representing how many characters must be read
-	 *            before invalidating the mark.
-	 * 
-	 * @throws IOException
-	 *             If an error occurs attempting mark this BufferedReader.
-	 * @throws IllegalArgumentException
-	 *             If readlimit is < 0      
-	 */
+            char[] newbuf = new char[newLength];
+            System.arraycopy(buf, 0, newbuf, 0, buf.length);
+            buf = newbuf;
+        } else if (markpos > 0) {
+            System.arraycopy(buf, markpos, buf, 0, buf.length - markpos);
+        }
 
-	@Override
+        /* Set the new position and mark position */
+        pos -= markpos;
+        count = markpos = 0;
+        int charsread = in.read(buf, pos, buf.length - pos);
+        count = charsread == -1 ? pos : pos + charsread;
+        return charsread;
+    }
+
+    /**
+     * Answer a boolean indicating whether or not this BufferedReader is closed.
+     * 
+     * @return <code>true</code> if this reader is closed, <code>false</code>
+     *         otherwise
+     */
+    private boolean isClosed() {
+        return buf == null;
+    }
+
+    /**
+     * Set a Mark position in this BufferedReader. The parameter
+     * <code>readLimit</code> indicates how many characters can be read before
+     * a mark is invalidated. Sending reset() will reposition the reader back to
+     * the marked position provided <code>readLimit</code> has not been
+     * surpassed.
+     * 
+     * @param readlimit
+     *            an int representing how many characters must be read before
+     *            invalidating the mark.
+     * 
+     * @throws IOException
+     *             If an error occurs attempting mark this BufferedReader.
+     * @throws IllegalArgumentException
+     *             If readlimit is < 0
+     */
+    @Override
     public void mark(int readlimit) throws IOException {
-		if (readlimit >= 0) {
-			synchronized (lock) {
-				if (isOpen()) {
-					marklimit = readlimit;
-					markpos = pos;
-				} else {
-                    throw new IOException(Msg.getString("K005b")); //$NON-NLS-1$
-                }
-			}
-		} else {
+        if (readlimit < 0) {
             throw new IllegalArgumentException();
         }
-	}
-
-	/**
-	 * Answers a boolean indicating whether or not this Reader supports mark()
-	 * and reset(). This implementation answers <code>true</code>.
-	 * 
-	 * @return <code>true</code> if mark() and reset() are supported,
-	 *         <code>false</code> otherwise
-	 */
+        synchronized (lock) {
+            if (isClosed()) {
+                throw new IOException(Msg.getString("K005b")); //$NON-NLS-1$
+            }
+            marklimit = readlimit;
+            markpos = pos;
+        }
+    }
 
-	@Override
+    /**
+     * Answers a boolean indicating whether or not this Reader supports mark()
+     * and reset(). This implementation answers <code>true</code>.
+     * 
+     * @return <code>true</code> if mark() and reset() are supported,
+     *         <code>false</code> otherwise
+     */
+    @Override
     public boolean markSupported() {
-		return true;
-	}
-
-	/**
-	 * Reads a single character from this reader and returns the result as an
-	 * int. The 2 higher-order characters are set to 0. If the end of reader was
-	 * encountered then return -1. This implementation either returns a
-	 * character from the buffer or if there are no characters available, fill
-	 * the buffer then return a character or -1.
-	 * 
-	 * @return the character read or -1 if end of reader.
-	 * 
-	 * @throws IOException
-	 *             If the BufferedReader is already closed or some other IO
-	 *             error occurs.
-	 */
+        return true;
+    }
 
-	@Override
+    /**
+     * Reads a single character from this reader and returns the result as an
+     * int. The 2 higher-order characters are set to 0. If the end of reader was
+     * encountered then return -1. This implementation either returns a
+     * character from the buffer or if there are no characters available, fill
+     * the buffer then return a character or -1.
+     * 
+     * @return the character read or -1 if end of reader.
+     * 
+     * @throws IOException
+     *             If the BufferedReader is already closed or some other IO
+     *             error occurs.
+     */
+    @Override
     public int read() throws IOException {
-		synchronized (lock) {
-			if (isOpen()) {
-				/* Are there buffered characters available? */
-				if (pos < count || fillbuf() != -1) {
-                    return buf[pos++];
-                }
-				return -1;
-			}
-			throw new IOException(Msg.getString("K005b")); //$NON-NLS-1$
-		}
-	}
-
-	/**
-	 * Reads at most <code>length</code> characters from this BufferedReader
-	 * and stores them at <code>offset</code> in the character array
-	 * <code>buffer</code>. Returns the number of characters actually read or
-	 * -1 if the end of reader was encountered. If all the buffered characters
-	 * have been used, a mark has not been set, and the requested number of
-	 * characters is larger than this Readers buffer size, this implementation
-	 * bypasses the buffer and simply places the results directly into
-	 * <code>buffer</code>.
-	 * 
-	 * @param buffer
-	 *            character array to store the read characters
-	 * @param offset
-	 *            offset in buf to store the read characters
-	 * @param length
-	 *            maximum number of characters to read
-	 * @return number of characters read or -1 if end of reader.
-	 * 
-	 * @throws IOException
-	 *             If the BufferedReader is already closed or some other IO
-	 *             error occurs.
-	 */
+        synchronized (lock) {
+            if (isClosed()) {
+                throw new IOException(Msg.getString("K005b")); //$NON-NLS-1$
+            }
+            /* Are there buffered characters available? */
+            if (pos < count || fillbuf() != -1) {
+                return buf[pos++];
+            }
+            return -1;
+        }
+    }
 
-	@Override
+    /**
+     * Reads at most <code>length</code> characters from this BufferedReader
+     * and stores them at <code>offset</code> in the character array
+     * <code>buffer</code>. Returns the number of characters actually read or
+     * -1 if the end of reader was encountered. If all the buffered characters
+     * have been used, a mark has not been set, and the requested number of
+     * characters is larger than this Readers buffer size, this implementation
+     * bypasses the buffer and simply places the results directly into
+     * <code>buffer</code>.
+     * 
+     * @param buffer
+     *            character array to store the read characters
+     * @param offset
+     *            offset in buf to store the read characters
+     * @param length
+     *            maximum number of characters to read
+     * @return number of characters read or -1 if end of reader.
+     * 
+     * @throws IOException
+     *             If the BufferedReader is already closed or some other IO
+     *             error occurs.
+     */
+    @Override
     public int read(char[] buffer, int offset, int length) throws IOException {
-		synchronized (lock) {
-			if (!isOpen()) {
-				throw new IOException(Msg.getString("K005b")); //$NON-NLS-1$
-			}
+        synchronized (lock) {
+            if (isClosed()) {
+                throw new IOException(Msg.getString("K005b")); //$NON-NLS-1$
+            }
             if (offset < 0 || offset > buffer.length - length || length < 0) {
-				throw new IndexOutOfBoundsException();
-			}
-			if (length == 0) {
-				return 0;
-			}
-			int required;
-			if (pos < count) {
-				/* There are bytes available in the buffer. */
-				int copylength = count - pos >= length ? length : count - pos;
-				System.arraycopy(buf, pos, buffer, offset, copylength);
-				pos += copylength;
-				if (copylength == length || !in.ready()) {
-					return copylength;
-				}
-				offset += copylength;
-				required = length - copylength;
-			} else {
-				required = length;
-			}
-
-			while (true) {
-				int read;
-				/*
-				 * If we're not marked and the required size is greater than the
-				 * buffer, simply read the bytes directly bypassing the buffer.
-				 */
-				if (markpos == -1 && required >= buf.length) {
-					read = in.read(buffer, offset, required);
-					if (read == -1) {
-						return required == length ? -1 : length - required;
-					}
-				} else {
-					if (fillbuf() == -1) {
-						return required == length ? -1 : length - required;
-					}
-					read = count - pos >= required ? required : count - pos;
-					System.arraycopy(buf, pos, buffer, offset, read);
-					pos += read;
-				}
-				required -= read;
-				if (required == 0) {
-					return length;
-				}
-				if (!in.ready()) {
-					return length - required;
-				}
-				offset += read;
-			}
-		}
-	}
-
-	/**
-	 * Answers a <code>String</code> representing the next line of text
-	 * available in this BufferedReader. A line is represented by 0 or more
-	 * characters followed by <code>'\n'</code>, <code>'\r'</code>,
-	 * <code>'\r\n'</code> or end of stream. The <code>String</code> does
-	 * not include the newline sequence.
-	 * 
-	 * @return the contents of the line or null if no characters were read
-	 *         before end of stream.
-	 * 
-	 * @throws IOException
-	 *             If the BufferedReader is already closed or some other IO
-	 *             error occurs.
-	 */
-
-	public String readLine() throws IOException {
-		synchronized (lock) {
-			if (isOpen()) {
-				/* Are there buffered characters available? */
-				if ((pos >= count) && (fillbuf() == -1)) {
-					return null;
-				}
-				for (int charPos = pos; charPos < count; charPos++) {
-					char ch = buf[charPos];
-					if (ch > '\r')
-						continue;
-					if (ch == '\n') {
-						String res = new String(buf, pos, charPos - pos);
-						pos = charPos + 1;
-						return res;
-					} else if (ch == '\r') {
-						String res = new String(buf, pos, charPos - pos);
-						pos = charPos + 1;
-						if (((pos < count) || (fillbuf() != -1))
-								&& (buf[pos] == '\n')) {
-							pos++;
-						}
-						return res;
-					}
-				}
-
-				char eol = '\0';
-				StringBuilder result = new StringBuilder(80);
-				/* Typical Line Length */
-
-				result.append(buf, pos, count - pos);
-				pos = count;
-				while (true) {
-					/* Are there buffered characters available? */
-					if (pos >= count) {
-						if (eol == '\n') {
-                            return result.toString();
+                throw new IndexOutOfBoundsException();
+            }
+            if (length == 0) {
+                return 0;
+            }
+            int required;
+            if (pos < count) {
+                /* There are bytes available in the buffer. */
+                int copylength = count - pos >= length ? length : count - pos;
+                System.arraycopy(buf, pos, buffer, offset, copylength);
+                pos += copylength;
+                if (copylength == length || !in.ready()) {
+                    return copylength;
+                }
+                offset += copylength;
+                required = length - copylength;
+            } else {
+                required = length;
+            }
+
+            while (true) {
+                int read;
+                /*
+                 * If we're not marked and the required size is greater than the
+                 * buffer, simply read the bytes directly bypassing the buffer.
+                 */
+                if (markpos == -1 && required >= buf.length) {
+                    read = in.read(buffer, offset, required);
+                    if (read == -1) {
+                        return required == length ? -1 : length - required;
+                    }
+                } else {
+                    if (fillbuf() == -1) {
+                        return required == length ? -1 : length - required;
+                    }
+                    read = count - pos >= required ? required : count - pos;
+                    System.arraycopy(buf, pos, buffer, offset, read);
+                    pos += read;
+                }
+                required -= read;
+                if (required == 0) {
+                    return length;
+                }
+                if (!in.ready()) {
+                    return length - required;
+                }
+                offset += read;
+            }
+        }
+    }
+
+    /**
+     * Answers a <code>String</code> representing the next line of text
+     * available in this BufferedReader. A line is represented by 0 or more
+     * characters followed by <code>'\n'</code>, <code>'\r'</code>,
+     * <code>'\r\n'</code> or end of stream. The <code>String</code> does
+     * not include the newline sequence.
+     * 
+     * @return the contents of the line or null if no characters were read
+     *         before end of stream.
+     * 
+     * @throws IOException
+     *             If the BufferedReader is already closed or some other IO
+     *             error occurs.
+     */
+    public String readLine() throws IOException {
+        synchronized (lock) {
+            if (isClosed()) {
+                throw new IOException(Msg.getString("K005b")); //$NON-NLS-1$
+            }
+            /* Are there buffered characters available? */
+            if ((pos >= count) && (fillbuf() == -1)) {
+                return null;
+            }
+            for (int charPos = pos; charPos < count; charPos++) {
+                char ch = buf[charPos];
+                if (ch > '\r') {
+                    continue;
+                }
+                if (ch == '\n') {
+                    String res = new String(buf, pos, charPos - pos);
+                    pos = charPos + 1;
+                    return res;
+                } else if (ch == '\r') {
+                    String res = new String(buf, pos, charPos - pos);
+                    pos = charPos + 1;
+                    if (((pos < count) || (fillbuf() != -1))
+                            && (buf[pos] == '\n')) {
+                        pos++;
+                    }
+                    return res;
+                }
+            }
+
+            char eol = '\0';
+            StringBuilder result = new StringBuilder(80);
+            /* Typical Line Length */
+
+            result.append(buf, pos, count - pos);
+            pos = count;
+            while (true) {
+                /* Are there buffered characters available? */
+                if (pos >= count) {
+                    if (eol == '\n') {
+                        return result.toString();
+                    }
+                    // attempt to fill buffer
+                    if (fillbuf() == -1) {
+                        // characters or null.
+                        return result.length() > 0 || eol != '\0' ? result
+                                .toString() : null;
+                    }
+                }
+                for (int charPos = pos; charPos < count; charPos++) {
+                    if (eol == '\0') {
+                        if ((buf[charPos] == '\n' || buf[charPos] == '\r')) {
+                            eol = buf[charPos];
+                        }
+                    } else if (eol == '\r' && (buf[charPos] == '\n')) {
+                        if (charPos > pos) {
+                            result.append(buf, pos, charPos - pos - 1);
                         }
-						// attempt to fill buffer
-						if (fillbuf() == -1) {
-                            // characters or null.
-							return result.length() > 0 || eol != '\0' ? result
-									.toString() : null;
+                        pos = charPos + 1;
+                        return result.toString();
+                    } else if (eol != '\0') {
+                        if (charPos > pos) {
+                            result.append(buf, pos, charPos - pos - 1);
                         }
-					}
-					for (int charPos = pos; charPos < count; charPos++) {
-						if (eol == '\0') {
-							if ((buf[charPos] == '\n' || buf[charPos] == '\r')) {
-								eol = buf[charPos];
-							}
-						} else if (eol == '\r' && (buf[charPos] == '\n')) {
-							if (charPos > pos) {
-                                result.append(buf, pos, charPos - pos - 1);
-                            }
-							pos = charPos + 1;
-							return result.toString();
-						} else if (eol != '\0') {
-							if (charPos > pos) {
-                                result.append(buf, pos, charPos - pos - 1);
-                            }
-							pos = charPos;
-							return result.toString();
-						}
-					}
-					if (eol == '\0') {
-						result.append(buf, pos, count - pos);
-					} else {
-						result.append(buf, pos, count - pos - 1);
-					}
-					pos = count;
-				}
-			}
-			throw new IOException(Msg.getString("K005b")); //$NON-NLS-1$
-		}
-	}
-
-	/**
-	 * Answers a <code>boolean</code> indicating whether or not this Reader is
-	 * ready to be read without blocking. If the result is <code>true</code>,
-	 * the next <code>read()</code> will not block. If the result is
-	 * <code>false</code> this Reader may or may not block when
-	 * <code>read()</code> is sent.
-	 * 
-	 * @return <code>true</code> if the receiver will not block when
-	 *         <code>read()</code> is called, <code>false</code> if unknown
-	 *         or blocking will occur.
-	 * 
-	 * @throws IOException
-	 *             If the BufferedReader is already closed or some other IO
-	 *             error occurs.
-	 */
+                        pos = charPos;
+                        return result.toString();
+                    }
+                }
+                if (eol == '\0') {
+                    result.append(buf, pos, count - pos);
+                } else {
+                    result.append(buf, pos, count - pos - 1);
+                }
+                pos = count;
+            }
+        }
+
+    }
 
-	@Override
+    /**
+     * Answers a <code>boolean</code> indicating whether or not this Reader is
+     * ready to be read without blocking. If the result is <code>true</code>,
+     * the next <code>read()</code> will not block. If the result is
+     * <code>false</code> this Reader may or may not block when
+     * <code>read()</code> is sent.
+     * 
+     * @return <code>true</code> if the receiver will not block when
+     *         <code>read()</code> is called, <code>false</code> if unknown
+     *         or blocking will occur.
+     * 
+     * @throws IOException
+     *             If the BufferedReader is already closed or some other IO
+     *             error occurs.
+     */
+    @Override
     public boolean ready() throws IOException {
-		synchronized (lock) {
-			if (isOpen()) {
-                return ((count - pos) > 0) || in.ready();
-            }
-			throw new IOException(Msg.getString("K005b")); //$NON-NLS-1$
-		}
-	}
-
-	/**
-	 * Reset this BufferedReader's position to the last <code>mark()</code>
-	 * location. Invocations of <code>read()/skip()</code> will occur from
-	 * this new location. If this Reader was not marked, throw IOException.
-	 * 
-	 * @throws IOException
-	 *             If a problem occurred, the receiver does not support
-	 *             <code>mark()/reset()</code>, or no mark has been set.
-	 */
+        synchronized (lock) {
+            if (isClosed()) {
+                throw new IOException(Msg.getString("K005b")); //$NON-NLS-1$
+            }
+            return ((count - pos) > 0) || in.ready();
+        }
+    }
 
-	@Override
+    /**
+     * Reset this BufferedReader's position to the last <code>mark()</code>
+     * location. Invocations of <code>read()/skip()</code> will occur from
+     * this new location. If this Reader was not marked, throw IOException.
+     * 
+     * @throws IOException
+     *             If a problem occurred, the receiver does not support
+     *             <code>mark()/reset()</code>, or no mark has been set.
+     */
+    @Override
     public void reset() throws IOException {
-		synchronized (lock) {
-			if (isOpen()) {
-				if (markpos != -1) {
-                    pos = markpos;
-                } else {
-                    throw new IOException(Msg
-							.getString("K005c")); //$NON-NLS-1$
-                }
-			} else {
+        synchronized (lock) {
+            if (isClosed()) {
                 throw new IOException(Msg.getString("K005b")); //$NON-NLS-1$
             }
-		}
-	}
-
-	/**
-	 * Skips <code>amount</code> number of characters in this Reader.
-	 * Subsequent <code>read()</code>'s will not return these characters
-	 * unless <code>reset()</code> is used. Skipping characters may invalidate
-	 * a mark if marklimit is surpassed.
-	 * 
-	 * @param amount
-	 *            the maximum number of characters to skip.
-	 * @return the number of characters actually skipped.
-	 * 
-	 * @throws IOException
-	 *             If the BufferedReader is already closed or some other IO
-	 *             error occurs.
-	 * @throws  IllegalArgumentException
-	 *              If amount is negative
-	 */
+            if (markpos == -1) {
+                throw new IOException(Msg.getString("K005c")); //$NON-NLS-1$
+            }
+            pos = markpos;
+        }
+    }
 
-	@Override
+    /**
+     * Skips <code>amount</code> number of characters in this Reader.
+     * Subsequent <code>read()</code>'s will not return these characters
+     * unless <code>reset()</code> is used. Skipping characters may invalidate
+     * a mark if marklimit is surpassed.
+     * 
+     * @param amount
+     *            the maximum number of characters to skip.
+     * @return the number of characters actually skipped.
+     * 
+     * @throws IOException
+     *             If the BufferedReader is already closed or some other IO
+     *             error occurs.
+     * @throws IllegalArgumentException
+     *             If amount is negative
+     */
+    @Override
     public long skip(long amount) throws IOException {
-		if (amount >= 0) {
-			synchronized (lock) {
-				if (isOpen()) {
-					if (amount < 1) {
-                        return 0;
-                    }
-					if (count - pos >= amount) {
-						pos += amount;
-						return amount;
-					}
-
-					long read = count - pos;
-					pos = count;
-					while (read < amount) {
-						if (fillbuf() == -1) {
-                            return read;
-                        }
-						if (count - pos >= amount - read) {
-							pos += amount - read;
-							return amount;
-						}
-						// Couldn't get all the characters, skip what we read
-						read += (count - pos);
-						pos = count;
-					}
-					return amount;
-				}
-				throw new IOException(Msg.getString("K005b")); //$NON-NLS-1$
-			}
-		}
-		throw new IllegalArgumentException();
-	}
+        if (amount < 0) {
+            throw new IllegalArgumentException();
+        }
+        synchronized (lock) {
+            if (isClosed()) {
+                throw new IOException(Msg.getString("K005b")); //$NON-NLS-1$
+            }
+            if (amount < 1) {
+                return 0;
+            }
+            if (count - pos >= amount) {
+                pos += amount;
+                return amount;
+            }
+
+            long read = count - pos;
+            pos = count;
+            while (read < amount) {
+                if (fillbuf() == -1) {
+                    return read;
+                }
+                if (count - pos >= amount - read) {
+                    pos += amount - read;
+                    return amount;
+                }
+                // Couldn't get all the characters, skip what we read
+                read += (count - pos);
+                pos = count;
+            }
+            return amount;
+        }
+    }
 }

Modified: harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/io/BufferedWriter.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/io/BufferedWriter.java?view=diff&rev=492652&r1=492651&r2=492652
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/io/BufferedWriter.java (original)
+++ harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/io/BufferedWriter.java Thu Jan  4 09:47:01 2007
@@ -30,6 +30,7 @@
  * @see BufferedReader
  */
 public class BufferedWriter extends Writer {
+
     private Writer out;
 
     private char buf[];
@@ -65,12 +66,11 @@
      */
     public BufferedWriter(Writer out, int size) {
         super(out);
-        if (size > 0) {
-            this.out = out;
-            this.buf = new char[size];
-        } else {
+        if (size <= 0) {
             throw new IllegalArgumentException(Msg.getString("K0058")); //$NON-NLS-1$
         }
+        this.out = out;
+        this.buf = new char[size];
     }
 
     /**
@@ -84,7 +84,7 @@
     @Override
     public void close() throws IOException {
         synchronized (lock) {
-            if (isOpen()) {
+            if (!isClosed()) {
                 flush();
                 out.close();
                 buf = null;
@@ -103,26 +103,25 @@
     @Override
     public void flush() throws IOException {
         synchronized (lock) {
-            if (isOpen()) {
-                if (pos > 0) {
-                    out.write(buf, 0, pos);
-                }
-                pos = 0;
-                out.flush();
-            } else {
+            if (isClosed()) {
                 throw new IOException(Msg.getString("K005d")); //$NON-NLS-1$
             }
+            if (pos > 0) {
+                out.write(buf, 0, pos);
+            }
+            pos = 0;
+            out.flush();
         }
     }
 
     /**
-     * Answer a boolean indicating whether or not this BufferedWriter is open.
+     * Answer a boolean indicating whether or not this BufferedWriter is closed.
      * 
-     * @return <code>true</code> if this reader is open, <code>false</code>
+     * @return <code>true</code> if this reader is closed, <code>false</code>
      *         otherwise
      */
-    private boolean isOpen() {
-        return out != null;
+    private boolean isClosed() {
+        return out == null;
     }
 
     /**
@@ -159,7 +158,7 @@
     @Override
     public void write(char[] cbuf, int offset, int count) throws IOException {
         synchronized (lock) {
-            if (!isOpen()) {
+            if (isClosed()) {
                 throw new IOException(Msg.getString("K005d")); //$NON-NLS-1$
             }
             if (offset < 0 || offset > cbuf.length - count || count < 0) {
@@ -210,15 +209,14 @@
     @Override
     public void write(int oneChar) throws IOException {
         synchronized (lock) {
-            if (isOpen()) {
-                if (pos >= buf.length) {
-                    out.write(buf, 0, buf.length);
-                    pos = 0;
-                }
-                buf[pos++] = (char) oneChar;
-            } else {
+            if (isClosed()) {
                 throw new IOException(Msg.getString("K005d")); //$NON-NLS-1$
             }
+            if (pos >= buf.length) {
+                out.write(buf, 0, buf.length);
+                pos = 0;
+            }
+            buf[pos++] = (char) oneChar;
         }
     }
 
@@ -244,9 +242,8 @@
     @Override
     public void write(String str, int offset, int count) throws IOException {
         synchronized (lock) {
-            if (!isOpen()) {
-                throw new IOException(org.apache.harmony.luni.util.Msg
-                        .getString("K005d")); //$NON-NLS-1$
+            if (isClosed()) {
+                throw new IOException(Msg.getString("K005d")); //$NON-NLS-1$
             }
             if (count <= 0) {
                 return;

Modified: harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/io/ByteArrayInputStream.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/io/ByteArrayInputStream.java?view=diff&rev=492652&r1=492651&r2=492652
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/io/ByteArrayInputStream.java (original)
+++ harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/io/ByteArrayInputStream.java Thu Jan  4 09:47:01 2007
@@ -23,193 +23,190 @@
  * @see ByteArrayOutputStream
  */
 public class ByteArrayInputStream extends InputStream {
-	/**
-	 * The <code>byte</code> array containing the bytes to stream over.
-	 */
-	protected byte[] buf;
-
-	/**
-	 * The current position within the byte array.
-	 */
-	protected int pos;
-
-	/**
-	 * The current mark position. Initially set to 0 or the <code>offset</code>
-	 * parameter within the constructor.
-	 */
-	protected int mark;
-
-	/**
-	 * The total number of bytes initially available in the byte array
-	 * <code>buf</code>.
-	 */
-	protected int count;
-
-	/**
-	 * Constructs a new ByteArrayInputStream on the byte array <code>buf</code>.
-	 * 
-	 * @param buf
-	 *            the byte array to stream over
-	 */
-	public ByteArrayInputStream(byte buf[]) {
-		this.mark = 0;
-		this.buf = buf;
-		this.count = buf.length;
-	}
-
-	/**
-	 * Constructs a new ByteArrayInputStream on the byte array <code>buf</code>
-	 * with the position set to <code>offset</code> and the number of bytes
-	 * available set to <code>offset</code> + <code>length</code>.
-	 * 
-	 * @param buf
-	 *            the byte array to stream over
-	 * @param offset
-	 *            the offset in <code>buf</code> to start streaming at
-	 * @param length
-	 *            the number of bytes available to stream over.
-	 */
-	public ByteArrayInputStream(byte buf[], int offset, int length) {
-		this.buf = buf;
-		pos = offset;
-		mark = offset;
-		count = offset + length > buf.length ? buf.length : offset + length;
-		}
-
-	/**
-	 * Answers a int representing then number of bytes that are available before
-	 * this ByteArrayInputStream will block. This method returns the number of
-	 * bytes yet to be read from the underlying byte array.
-	 * 
-	 * @return the number of bytes available before blocking.
-	 */
-	@Override
+    /**
+     * The <code>byte</code> array containing the bytes to stream over.
+     */
+    protected byte[] buf;
+
+    /**
+     * The current position within the byte array.
+     */
+    protected int pos;
+
+    /**
+     * The current mark position. Initially set to 0 or the <code>offset</code>
+     * parameter within the constructor.
+     */
+    protected int mark;
+
+    /**
+     * The total number of bytes initially available in the byte array
+     * <code>buf</code>.
+     */
+    protected int count;
+
+    /**
+     * Constructs a new ByteArrayInputStream on the byte array <code>buf</code>.
+     * 
+     * @param buf
+     *            the byte array to stream over
+     */
+    public ByteArrayInputStream(byte buf[]) {
+        this.mark = 0;
+        this.buf = buf;
+        this.count = buf.length;
+    }
+
+    /**
+     * Constructs a new ByteArrayInputStream on the byte array <code>buf</code>
+     * with the position set to <code>offset</code> and the number of bytes
+     * available set to <code>offset</code> + <code>length</code>.
+     * 
+     * @param buf
+     *            the byte array to stream over
+     * @param offset
+     *            the offset in <code>buf</code> to start streaming at
+     * @param length
+     *            the number of bytes available to stream over.
+     */
+    public ByteArrayInputStream(byte buf[], int offset, int length) {
+        this.buf = buf;
+        pos = offset;
+        mark = offset;
+        count = offset + length > buf.length ? buf.length : offset + length;
+    }
+
+    /**
+     * Answers a int representing then number of bytes that are available before
+     * this ByteArrayInputStream will block. This method returns the number of
+     * bytes yet to be read from the underlying byte array.
+     * 
+     * @return the number of bytes available before blocking.
+     */
+    @Override
     public synchronized int available() {
-		return count - pos;
-	}
+        return count - pos;
+    }
 
-	/**
-	 * Close the ByteArrayInputStream. This implementation frees up resources
-	 * associated with this stream.
-	 * 
-	 * @throws IOException
-	 *             If an error occurs attempting to close this InputStream.
-	 */
-	@Override
+    /**
+     * Close the ByteArrayInputStream. This implementation frees up resources
+     * associated with this stream.
+     * 
+     * @throws IOException
+     *             If an error occurs attempting to close this InputStream.
+     */
+    @Override
     public void close() throws IOException {
-		// Do nothing on close, this matches JDK behaviour.
-	}
+        // Do nothing on close, this matches JDK behaviour.
+    }
 
-	/**
-	 * Set a Mark position in this ByteArrayInputStream. The parameter
-	 * <code>readLimit</code> is ignored. Sending reset() will reposition the
-	 * stream back to the marked position.
-	 * 
-	 * @param readlimit
-	 *            ignored.
-	 */
-	@Override
+    /**
+     * Set a Mark position in this ByteArrayInputStream. The parameter
+     * <code>readLimit</code> is ignored. Sending reset() will reposition the
+     * stream back to the marked position.
+     * 
+     * @param readlimit
+     *            ignored.
+     */
+    @Override
     public synchronized void mark(int readlimit) {
-		mark = pos;
-	}
+        mark = pos;
+    }
 
-	/**
-	 * Answers a boolean indicating whether or not this ByteArrayInputStream
-	 * supports mark() and reset(). This implementation answers
-	 * <code>true</code>.
-	 * 
-	 * @return <code>true</code> indicates this stream supports mark/reset,
-	 *         <code>false
-	 *				<code> otherwise.
-	 */
-	@Override
+    /**
+     * Answers a boolean indicating whether or not this ByteArrayInputStream
+     * supports mark() and reset(). This implementation answers
+     * <code>true</code>.
+     * 
+     * @return <code>true</code> indicates this stream supports mark/reset,
+     *         <code>false
+     *				<code> otherwise.
+     */
+    @Override
     public boolean markSupported() {
-		return true;
-	}
+        return true;
+    }
 
-	/**
-	 * Reads a single byte from this ByteArrayInputStream and returns the result
-	 * as an int. The low-order byte is returned or -1 of the end of stream was
-	 * encountered. This implementation returns the next available byte from the
-	 * target byte array.
-	 * 
-	 * @return the byte read or -1 if end of stream.
-	 */
-	@Override
+    /**
+     * Reads a single byte from this ByteArrayInputStream and returns the result
+     * as an int. The low-order byte is returned or -1 of the end of stream was
+     * encountered. This implementation returns the next available byte from the
+     * target byte array.
+     * 
+     * @return the byte read or -1 if end of stream.
+     */
+    @Override
     public synchronized int read() {
-		return pos < count ? buf[pos++] & 0xFF : -1;
-	}
+        return pos < count ? buf[pos++] & 0xFF : -1;
+    }
 
-	/**
-	 * Reads at most <code>len</code> bytes from this ByteArrayInputStream and
-	 * stores them in byte array <code>b</code> starting at offset
-	 * <code>off</code>. Answer the number of bytes actually read or -1 if no
-	 * bytes were read and end of stream was encountered. This implementation
-	 * reads bytes from the target byte array.
-	 * 
-	 * @param b
-	 *            the byte array in which to store the read bytes.
-	 * @param offset
-	 *            the offset in <code>b</code> to store the read bytes.
-	 * @param length
-	 *            the maximum number of bytes to store in <code>b</code>.
-	 * @return the number of bytes actually read or -1 if end of stream.
-	 */
-	@Override
+    /**
+     * Reads at most <code>len</code> bytes from this ByteArrayInputStream and
+     * stores them in byte array <code>b</code> starting at offset
+     * <code>off</code>. Answer the number of bytes actually read or -1 if no
+     * bytes were read and end of stream was encountered. This implementation
+     * reads bytes from the target byte array.
+     * 
+     * @param b
+     *            the byte array in which to store the read bytes.
+     * @param offset
+     *            the offset in <code>b</code> to store the read bytes.
+     * @param length
+     *            the maximum number of bytes to store in <code>b</code>.
+     * @return the number of bytes actually read or -1 if end of stream.
+     */
+    @Override
     public synchronized int read(byte b[], int offset, int length) {
-		// Are there any bytes available
-		if (this.pos >= this.count) {
+        if (b == null) {
+            throw new NullPointerException();
+        }
+        // avoid int overflow
+        if (offset < 0 || offset > b.length || length < 0
+                || length > b.length - offset) {
+            throw new IndexOutOfBoundsException();
+        }
+        // Are there any bytes available?
+        if (this.pos >= this.count) {
             return -1;
         }
+        if (length == 0) {
+            return 0;
+        }
 
-		if (b != null) {
-			// avoid int overflow
-			if (0 <= offset && offset <= b.length && 0 <= length
-					&& length <= b.length - offset) {
-				if (length == 0) {
-                    return 0;
-                }
-
-				int copylen = this.count - pos < length ? this.count - pos
-						: length;
-				System.arraycopy(buf, pos, b, offset, copylen);
-				pos += copylen;
-				return copylen;
-			}
-			throw new ArrayIndexOutOfBoundsException();
-		}
-		throw new NullPointerException();
-	}
-
-	/**
-	 * Reset this ByteArrayInputStream to the last marked location. This
-	 * implementation resets the position to either the marked position, the
-	 * start position supplied in the constructor or <code>0</code> if neither
-	 * is provided.
-	 * 
-	 */
-	@Override
+        int copylen = this.count - pos < length ? this.count - pos : length;
+        System.arraycopy(buf, pos, b, offset, copylen);
+        pos += copylen;
+        return copylen;
+    }
+
+    /**
+     * Reset this ByteArrayInputStream to the last marked location. This
+     * implementation resets the position to either the marked position, the
+     * start position supplied in the constructor or <code>0</code> if neither
+     * is provided.
+     */
+    @Override
     public synchronized void reset() {
-		pos = mark;
-	}
+        pos = mark;
+    }
 
-	/**
-	 * Skips <code>count</code> number of bytes in this InputStream.
-	 * Subsequent <code>read()</code>'s will not return these bytes unless
-	 * <code>reset()</code> is used. This implementation skips
-	 * <code>count</code> number of bytes in the target stream.
-	 * 
-	 * @param n
-	 *            the number of bytes to skip.
-	 * @return the number of bytes actually skipped.
-	 */
-	@Override
+    /**
+     * Skips <code>count</code> number of bytes in this InputStream.
+     * Subsequent <code>read()</code>'s will not return these bytes unless
+     * <code>reset()</code> is used. This implementation skips
+     * <code>count</code> number of bytes in the target stream.
+     * 
+     * @param n
+     *            the number of bytes to skip.
+     * @return the number of bytes actually skipped.
+     */
+    @Override
     public synchronized long skip(long n) {
-		if (n <= 0) {
+        if (n <= 0) {
             return 0;
         }
-		int temp = pos;
-		pos = this.count - pos < n ? this.count : (int) (pos + n);
-		return pos - temp;
-	}
+        int temp = pos;
+        pos = this.count - pos < n ? this.count : (int) (pos + n);
+        return pos - temp;
+    }
 }

Modified: harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/io/ByteArrayOutputStream.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/io/ByteArrayOutputStream.java?view=diff&rev=492652&r1=492651&r2=492652
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/io/ByteArrayOutputStream.java (original)
+++ harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/io/ByteArrayOutputStream.java Thu Jan  4 09:47:01 2007
@@ -27,229 +27,224 @@
  * @see ByteArrayInputStream
  */
 public class ByteArrayOutputStream extends OutputStream {
-	/**
-	 * The byte array containing the bytes written.
-	 */
-	protected byte[] buf;
-
-	/**
-	 * The number of bytes written.
-	 */
-	protected int count;
-
-	/**
-	 * Constructs a new ByteArrayOutputStream with a default size of 32 bytes.
-	 * If more than 32 bytes are written to this instance, the underlying byte
-	 * array will expand to accommodate.
-	 * 
-	 */
-	public ByteArrayOutputStream() {
-		super();
-		buf = new byte[32];
-	}
-
-	/**
-	 * Constructs a new ByteArrayOutputStream with a default size of
-	 * <code>size</code> bytes. If more than <code>size</code> bytes are
-	 * written to this instance, the underlying byte array will expand to
-	 * accommodate.
-	 * 
-	 * @param size
-	 *            an non-negative integer representing the initial size for the
-	 *            underlying byte array.
-	 */
-	public ByteArrayOutputStream(int size) {
-		super();
-		if (size >= 0) {
+    /**
+     * The byte array containing the bytes written.
+     */
+    protected byte[] buf;
+
+    /**
+     * The number of bytes written.
+     */
+    protected int count;
+
+    /**
+     * Constructs a new ByteArrayOutputStream with a default size of 32 bytes.
+     * If more than 32 bytes are written to this instance, the underlying byte
+     * array will expand to accommodate.
+     * 
+     */
+    public ByteArrayOutputStream() {
+        super();
+        buf = new byte[32];
+    }
+
+    /**
+     * Constructs a new ByteArrayOutputStream with a default size of
+     * <code>size</code> bytes. If more than <code>size</code> bytes are
+     * written to this instance, the underlying byte array will expand to
+     * accommodate.
+     * 
+     * @param size
+     *            an non-negative integer representing the initial size for the
+     *            underlying byte array.
+     */
+    public ByteArrayOutputStream(int size) {
+        super();
+        if (size >= 0) {
             buf = new byte[size];
         } else {
             throw new IllegalArgumentException(Msg.getString("K005e")); //$NON-NLS-1$
         }
-	}
+    }
 
-	/**
-	 * Close this ByteArrayOutputStream. This implementation releases System
-	 * resources used for this stream.
-	 * 
-	 * @throws IOException
-	 *             If an error occurs attempting to close this OutputStream.
-	 */
-	@Override
+    /**
+     * Close this ByteArrayOutputStream. This implementation releases System
+     * resources used for this stream.
+     * 
+     * @throws IOException
+     *             If an error occurs attempting to close this OutputStream.
+     */
+    @Override
     public void close() throws IOException {
-		/**
-		 * Although the spec claims "A closed stream cannot perform output
-		 * operations and cannot be reopened.", this implementation must do
-		 * nothing.
-		 */
-		super.close();
-	}
-
-	private void expand(int i) {
-		/* Can the buffer handle @i more bytes, if not expand it */
-		if (count + i <= buf.length) {
+        /**
+         * Although the spec claims "A closed stream cannot perform output
+         * operations and cannot be reopened.", this implementation must do
+         * nothing.
+         */
+        super.close();
+    }
+
+    private void expand(int i) {
+        /* Can the buffer handle @i more bytes, if not expand it */
+        if (count + i <= buf.length) {
             return;
         }
 
-		byte[] newbuf = new byte[(count + i) * 2];
-		System.arraycopy(buf, 0, newbuf, 0, count);
-		buf = newbuf;
-	}
-
-	/**
-	 * Reset this ByteArrayOutputStream to the beginning of the underlying byte
-	 * array. All subsequent writes will overwrite any bytes previously stored
-	 * in this stream.
-	 * 
-	 */
-	public synchronized void reset() {
-		count = 0;
-	}
-
-	/**
-	 * Answers the total number of bytes written to this stream thus far.
-	 * 
-	 * @return the number of bytes written to this Stream.
-	 */
-	public int size() {
-		return count;
-	}
-
-	/**
-	 * Answer the contents of this ByteArrayOutputStream as a byte array. Any
-	 * changes made to the receiver after returning will not be reflected in the
-	 * byte array returned to the caller.
-	 * 
-	 * @return this streams current contents as a byte array.
-	 */
-	public synchronized byte[] toByteArray() {
-		byte[] newArray = new byte[count];
-		System.arraycopy(buf, 0, newArray, 0, count);
-		return newArray;
-	}
-
-	/**
-	 * Answer the contents of this ByteArrayOutputStream as a String. Any
-	 * changes made to the receiver after returning will not be reflected in the
-	 * String returned to the caller.
-	 * 
-	 * @return this streams current contents as a String.
-	 */
+        byte[] newbuf = new byte[(count + i) * 2];
+        System.arraycopy(buf, 0, newbuf, 0, count);
+        buf = newbuf;
+    }
+
+    /**
+     * Reset this ByteArrayOutputStream to the beginning of the underlying byte
+     * array. All subsequent writes will overwrite any bytes previously stored
+     * in this stream.
+     * 
+     */
+    public synchronized void reset() {
+        count = 0;
+    }
+
+    /**
+     * Answers the total number of bytes written to this stream thus far.
+     * 
+     * @return the number of bytes written to this Stream.
+     */
+    public int size() {
+        return count;
+    }
+
+    /**
+     * Answer the contents of this ByteArrayOutputStream as a byte array. Any
+     * changes made to the receiver after returning will not be reflected in the
+     * byte array returned to the caller.
+     * 
+     * @return this streams current contents as a byte array.
+     */
+    public synchronized byte[] toByteArray() {
+        byte[] newArray = new byte[count];
+        System.arraycopy(buf, 0, newArray, 0, count);
+        return newArray;
+    }
+
+    /**
+     * Answer the contents of this ByteArrayOutputStream as a String. Any
+     * changes made to the receiver after returning will not be reflected in the
+     * String returned to the caller.
+     * 
+     * @return this streams current contents as a String.
+     */
 
-	@Override
+    @Override
     public String toString() {
-		return new String(buf, 0, count);
-	}
+        return new String(buf, 0, count);
+    }
 
-	/**
-	 * Answer the contents of this ByteArrayOutputStream as a String. Each byte
-	 * <code>b</code> in this stream is converted to a character
-	 * <code>c</code> using the following function:
-	 * <code>c == (char)(((hibyte & 0xff) << 8) | (b & 0xff))</code>. This
-	 * method is deprecated and either toString(), or toString(enc) should be
-	 * used.
-	 * 
-	 * @param hibyte
-	 *            the high byte of each resulting Unicode character
-	 * @return this streams current contents as a String with the high byte set
-	 *         to <code>hibyte</code>
-	 * 
-	 * @deprecated Use toString()
-	 */
-	@Deprecated
+    /**
+     * Answer the contents of this ByteArrayOutputStream as a String. Each byte
+     * <code>b</code> in this stream is converted to a character
+     * <code>c</code> using the following function:
+     * <code>c == (char)(((hibyte & 0xff) << 8) | (b & 0xff))</code>. This
+     * method is deprecated and either toString(), or toString(enc) should be
+     * used.
+     * 
+     * @param hibyte
+     *            the high byte of each resulting Unicode character
+     * @return this streams current contents as a String with the high byte set
+     *         to <code>hibyte</code>
+     * 
+     * @deprecated Use toString()
+     */
+    @Deprecated
     public String toString(int hibyte) {
-		char[] newBuf = new char[size()];
-		for (int i = 0; i < newBuf.length; i++) {
+        char[] newBuf = new char[size()];
+        for (int i = 0; i < newBuf.length; i++) {
             newBuf[i] = (char) (((hibyte & 0xff) << 8) | (buf[i] & 0xff));
         }
-		return new String(newBuf);
-	}
+        return new String(newBuf);
+    }
 
-	/**
-	 * Answer the contents of this ByteArrayOutputStream as a String converted
-	 * using the encoding declared in <code>enc</code>.
-	 * 
-	 * @param enc
-	 *            A String representing the encoding to use when translating
-	 *            this stream to a String.
-	 * @return this streams current contents as a String.
-	 * 
-	 * @throws UnsupportedEncodingException
-	 *             If declared encoding is not supported
-	 */
-	public String toString(String enc) throws UnsupportedEncodingException {
-		return new String(buf, 0, count, enc);
-	}
-
-	/**
-	 * Writes <code>count</code> <code>bytes</code> from the byte array
-	 * <code>buffer</code> starting at offset <code>index</code> to the
-	 * ByteArrayOutputStream.
-	 * 
-	 * @param buffer
-	 *            the buffer to be written
-	 * @param offset
-	 *            offset in buffer to get bytes
-	 * @param len
-	 *            number of bytes in buffer to write
-	 * 
-	 * @throws NullPointerException
-	 *             If buffer is null.
-	 * @throws IndexOutOfBoundsException
-	 *             If offset or count are outside of bounds.
-	 */
-	@Override
+    /**
+     * Answer the contents of this ByteArrayOutputStream as a String converted
+     * using the encoding declared in <code>enc</code>.
+     * 
+     * @param enc
+     *            A String representing the encoding to use when translating
+     *            this stream to a String.
+     * @return this streams current contents as a String.
+     * 
+     * @throws UnsupportedEncodingException
+     *             If declared encoding is not supported
+     */
+    public String toString(String enc) throws UnsupportedEncodingException {
+        return new String(buf, 0, count, enc);
+    }
+
+    /**
+     * Writes <code>count</code> <code>bytes</code> from the byte array
+     * <code>buffer</code> starting at offset <code>index</code> to the
+     * ByteArrayOutputStream.
+     * 
+     * @param buffer
+     *            the buffer to be written
+     * @param offset
+     *            offset in buffer to get bytes
+     * @param len
+     *            number of bytes in buffer to write
+     * 
+     * @throws NullPointerException
+     *             If buffer is null.
+     * @throws IndexOutOfBoundsException
+     *             If offset or count are outside of bounds.
+     */
+    @Override
     public synchronized void write(byte[] buffer, int offset, int len) {
-		/* Unsure what to do here, spec is unclear */
-		if (buf == null) {
+        // avoid int overflow
+        if (offset < 0 || offset > buffer.length || len < 0
+                || len > buffer.length - offset) {
+            throw new IndexOutOfBoundsException(Msg.getString("K002f")); //$NON-NLS-1$
+        }
+        if (len == 0) {
             return;
         }
-		if (buffer != null) {
-			// avoid int overflow
-			if (0 <= offset && offset <= buffer.length && 0 <= len
-					&& len <= buffer.length - offset) {
-				/* Expand if necessary */
-				expand(len);
-				System.arraycopy(buffer, offset, buf, this.count, len);
-				this.count += len;
-			} else {
-                throw new IndexOutOfBoundsException(Msg.getString("K002f")); //$NON-NLS-1$
-            }
-		} else {
-            throw new NullPointerException(Msg.getString("K0047")); //$NON-NLS-1$
-        }
-	}
-
-	/**
-	 * Writes the specified byte <code>oneByte</code> to the OutputStream.
-	 * Only the low order byte of <code>oneByte</code> is written.
-	 * 
-	 * @param oneByte
-	 *            the byte to be written
-	 */
-	@Override
+
+        /* Expand if necessary */
+        expand(len);
+        System.arraycopy(buffer, offset, buf, this.count, len);
+        this.count += len;
+    }
+
+    /**
+     * Writes the specified byte <code>oneByte</code> to the OutputStream.
+     * Only the low order byte of <code>oneByte</code> is written.
+     * 
+     * @param oneByte
+     *            the byte to be written
+     */
+    @Override
     public synchronized void write(int oneByte) {
-		try {
-			buf[count] = (byte) oneByte;
-			count++;
-		} catch (IndexOutOfBoundsException e) {
-			// Expand when necessary
-			expand(1);
-			buf[count++] = (byte) oneByte;
-		} catch (NullPointerException e) {
-		}
-	}
-
-	/**
-	 * Take the contents of this stream and write it to the output stream
-	 * <code>out</code>.
-	 * 
-	 * @param out
-	 *            An OutputStream on which to write the contents of this stream.
-	 * 
-	 * @throws IOException
-	 *             If an error occurs when writing to output stream
-	 */
-	public synchronized void writeTo(OutputStream out) throws IOException {
-		out.write(buf, 0, count);
-	}
+        try {
+            buf[count] = (byte) oneByte;
+            count++;
+        } catch (IndexOutOfBoundsException e) {
+            // Expand when necessary
+            expand(1);
+            buf[count++] = (byte) oneByte;
+        } catch (NullPointerException e) {
+        }
+    }
+
+    /**
+     * Take the contents of this stream and write it to the output stream
+     * <code>out</code>.
+     * 
+     * @param out
+     *            An OutputStream on which to write the contents of this stream.
+     * 
+     * @throws IOException
+     *             If an error occurs when writing to output stream
+     */
+    public synchronized void writeTo(OutputStream out) throws IOException {
+        out.write(buf, 0, count);
+    }
 }

Modified: harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/io/CharArrayReader.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/io/CharArrayReader.java?view=diff&rev=492652&r1=492651&r2=492652
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/io/CharArrayReader.java (original)
+++ harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/io/CharArrayReader.java Thu Jan  4 09:47:01 2007
@@ -22,268 +22,272 @@
 /**
  * CharArrayReader is used as a buffered character input stream on a character
  * array.
- * 
  */
 public class CharArrayReader extends Reader {
-	/**
-	 * Buffer for characters
-	 */
-	protected char buf[];
-
-	/**
-	 * Current buffer position.
-	 */
-	protected int pos;
-
-	/**
-	 * Current mark position.
-	 */
-	protected int markedPos = -1;
-
-	/**
-	 * The ending index of the buffer.
-	 */
-	protected int count;
-
-	/**
-	 * Construct a CharArrayReader on the char array <code>buffer</code>. The
-	 * size of the reader is set to the <code>length()</code> of the buffer
-	 * and the Object to synchronize access through is set to
-	 * <code>buffer</code>.
-	 * 
-	 * @param buf
-	 *            the char array to filter reads on.
-	 */
-	public CharArrayReader(char[] buf) {
-		super(buf);
-		this.buf = buf;
-		this.count = buf.length;
-	}
-
-	/**
-	 * Construct a CharArrayReader on the char array <code>buffer</code>. The
-	 * size of the reader is set to the parameter <code>length()</code> and
-	 * the original offset is set to <code>offset</code>.
-	 * 
-	 * @param buf
-	 *            the char array to filter reads on.
-	 * @param offset
-	 *            the offset in <code>buf</code> to start streaming at.
-	 * @param length
-	 *            the number of characters available to stream over.
-	 */
-
-	public CharArrayReader(char[] buf, int offset, int length) {
-		super(buf);
-		if (0 <= offset && offset <= buf.length && length >= 0) {
-			this.buf = buf;
-			this.pos = offset;
-
-			/* This is according to spec */
-			this.count = this.pos + length < buf.length ? length : buf.length;
-		} else {
+    /**
+     * Buffer for characters
+     */
+    protected char buf[];
+
+    /**
+     * Current buffer position.
+     */
+    protected int pos;
+
+    /**
+     * Current mark position.
+     */
+    protected int markedPos = -1;
+
+    /**
+     * The ending index of the buffer.
+     */
+    protected int count;
+
+    /**
+     * Construct a CharArrayReader on the char array <code>buffer</code>. The
+     * size of the reader is set to the <code>length()</code> of the buffer
+     * and the Object to synchronize access through is set to
+     * <code>buffer</code>.
+     * 
+     * @param buf
+     *            the char array to filter reads on.
+     */
+    public CharArrayReader(char[] buf) {
+        super(buf);
+        this.buf = buf;
+        this.count = buf.length;
+    }
+
+    /**
+     * Construct a CharArrayReader on the char array <code>buffer</code>. The
+     * size of the reader is set to the parameter <code>length()</code> and
+     * the original offset is set to <code>offset</code>.
+     * 
+     * @param buf
+     *            the char array to filter reads on.
+     * @param offset
+     *            the offset in <code>buf</code> to start streaming at.
+     * @param length
+     *            the number of characters available to stream over.
+     */
+
+    public CharArrayReader(char[] buf, int offset, int length) {
+        super(buf);
+        if (offset < 0 || offset > buf.length || length < 0) {
             throw new IllegalArgumentException();
         }
-	}
+        this.buf = buf;
+        this.pos = offset;
 
-	/**
-	 * This method closes this CharArrayReader. Once it is closed, you can no
-	 * longer read from it. Only the first invocation of this method has any
-	 * effect.
-	 * 
-	 */
-	@Override
+        /* This is according to spec */
+        this.count = this.pos + length < buf.length ? length : buf.length;
+    }
+
+    /**
+     * This method closes this CharArrayReader. Once it is closed, you can no
+     * longer read from it. Only the first invocation of this method has any
+     * effect.
+     */
+    @Override
     public void close() {
-		synchronized (lock) {
-			if (isOpen()) {
+        synchronized (lock) {
+            if (isOpen()) {
                 buf = null;
             }
-		}
-	}
+        }
+    }
 
-	/**
-	 * Answer a boolean indicating whether or not this CharArrayReader is open.
-	 * 
-	 * @return <code>true</code> if the reader is open, <code>false</code>
-	 *         otherwise.
-	 */
-	private boolean isOpen() {
-		return buf != null;
-	}
-
-	/**
-	 * Set a Mark position in this Reader. The parameter <code>readLimit</code>
-	 * is ignored for CharArrayReaders. Sending reset() will reposition the
-	 * reader back to the marked position provided the mark has not been
-	 * invalidated.
-	 * @param readLimit
-	 *            ignored for CharArrayReaders.
-	 * 
-	 * @throws IOException
-	 *             If an error occurs attempting to mark this CharArrayReader.
-	 */
-	@Override
+    /**
+     * Answer a boolean indicating whether or not this CharArrayReader is open.
+     * 
+     * @return <code>true</code> if the reader is open, <code>false</code>
+     *         otherwise.
+     */
+    private boolean isOpen() {
+        return buf != null;
+    }
+
+    /**
+     * Answer a boolean indicating whether or not this CharArrayReader is
+     * closed.
+     * 
+     * @return <code>true</code> if the reader is closed, <code>false</code>
+     *         otherwise.
+     */
+    private boolean isClosed() {
+        return buf == null;
+    }
+
+    /**
+     * Set a Mark position in this Reader. The parameter <code>readLimit</code>
+     * is ignored for CharArrayReaders. Sending reset() will reposition the
+     * reader back to the marked position provided the mark has not been
+     * invalidated.
+     * 
+     * @param readLimit
+     *            ignored for CharArrayReaders.
+     * 
+     * @throws IOException
+     *             If an error occurs attempting to mark this CharArrayReader.
+     */
+    @Override
     public void mark(int readLimit) throws IOException {
-		synchronized (lock) {
-			if (isOpen()) {
-                markedPos = pos;
-            } else {
+        synchronized (lock) {
+            if (isClosed()) {
                 throw new IOException(Msg.getString("K0060")); //$NON-NLS-1$
             }
-		}
-	}
+            markedPos = pos;
+        }
+    }
 
-	/**
-	 * Answers a boolean indicating whether or not this CharArrayReader supports
-	 * mark() and reset(). This method always returns true.
-	 * 
-	 * @return indicates whether or not mark() and reset() are supported.
-	 */
-	@Override
+    /**
+     * Answers a boolean indicating whether or not this CharArrayReader supports
+     * mark() and reset(). This method always returns true.
+     * 
+     * @return indicates whether or not mark() and reset() are supported.
+     */
+    @Override
     public boolean markSupported() {
-		return true;
-	}
+        return true;
+    }
 
-	/**
-	 * Reads a single character from this CharArrayReader and returns the result
-	 * as an int. The 2 higher-order bytes are set to 0. If the end of reader
-	 * was encountered then return -1.
-	 * 
-	 * @return int the character read or -1 if end of reader.
-	 * 
-	 * @throws IOException
-	 *             If the CharArrayReader is already closed.
-	 */
-	@Override
+    /**
+     * Reads a single character from this CharArrayReader and returns the result
+     * as an int. The 2 higher-order bytes are set to 0. If the end of reader
+     * was encountered then return -1.
+     * 
+     * @return int the character read or -1 if end of reader.
+     * 
+     * @throws IOException
+     *             If the CharArrayReader is already closed.
+     */
+    @Override
     public int read() throws IOException {
-		synchronized (lock) {
-			if (isOpen()) {
-				if (pos != count) {
-                    return buf[pos++];
-                }
-				return -1;
-			}
-			throw new IOException(Msg.getString("K0060")); //$NON-NLS-1$
-		}
-	}
-
-	/**
-	 * Reads at most <code>count</code> characters from this CharArrayReader
-	 * and stores them at <code>offset</code> in the character array
-	 * <code>buf</code>. Returns the number of characters actually read or -1
-	 * if the end of reader was encountered.
-	 * 
-	 * 
-	 * @param buffer
-	 *            character array to store the read characters
-	 * @param offset
-	 *            offset in buf to store the read characters
-	 * @param len
-	 *            maximum number of characters to read
-	 * @return number of characters read or -1 if end of reader.
-	 * 
-	 * @throws IOException
-	 *             If the CharArrayReader is closed.
-	 */
+        synchronized (lock) {
+            if (isClosed()) {
+                throw new IOException(Msg.getString("K0060")); //$NON-NLS-1$
+            }
+            if (pos == count) {
+                return -1;
+            }
+            return buf[pos++];
+        }
+    }
 
-	@Override
+    /**
+     * Reads at most <code>count</code> characters from this CharArrayReader
+     * and stores them at <code>offset</code> in the character array
+     * <code>buf</code>. Returns the number of characters actually read or -1
+     * if the end of reader was encountered.
+     * 
+     * 
+     * @param buffer
+     *            character array to store the read characters
+     * @param offset
+     *            offset in buf to store the read characters
+     * @param len
+     *            maximum number of characters to read
+     * @return number of characters read or -1 if end of reader.
+     * 
+     * @throws IOException
+     *             If the CharArrayReader is closed.
+     */
+    @Override
     public int read(char buffer[], int offset, int len) throws IOException {
-		// avoid int overflow
-		if (0 <= offset && offset <= buffer.length && 0 <= len
-				&& len <= buffer.length - offset) {
-			synchronized (lock) {
-				if (isOpen()) {
-					if (pos < this.count) {
-						int bytesRead = pos + len > this.count ? this.count
-								- pos : len;
-						System.arraycopy(this.buf, pos, buffer, offset,
-								bytesRead);
-						pos += bytesRead;
-						return bytesRead;
-					}
-					return -1;
-				}
-				throw new IOException(Msg.getString("K0060")); //$NON-NLS-1$
-			}
-		}
-		throw new ArrayIndexOutOfBoundsException();
-	}
-
-	/**
-	 * Answers a <code>boolean</code> indicating whether or not this
-	 * CharArrayReader is ready to be read without blocking. If the result is
-	 * <code>true</code>, the next <code>read()</code> will not block. If
-	 * the result is <code>false</code> this Reader may or may not block when
-	 * <code>read()</code> is sent. The implementation in CharArrayReader
-	 * always returns <code>true</code> even when it has been closed.
-	 * 
-	 * @return <code>true</code> if the receiver will not block when
-	 *         <code>read()</code> is called, <code>false</code> if unknown
-	 *         or blocking will occur.
-	 * 
-	 * @throws IOException
-	 *             If the CharArrayReader is closed.
-	 */
-	@Override
+        // avoid int overflow
+        if (offset < 0 || offset > buffer.length || len < 0
+                || len > buffer.length - offset) {
+            throw new ArrayIndexOutOfBoundsException();
+        }
+        synchronized (lock) {
+            if (isClosed()) {
+                throw new IOException(Msg.getString("K0060")); //$NON-NLS-1$
+            }
+            if (pos < this.count) {
+                int bytesRead = pos + len > this.count ? this.count - pos : len;
+                System.arraycopy(this.buf, pos, buffer, offset, bytesRead);
+                pos += bytesRead;
+                return bytesRead;
+            }
+            return -1;
+        }
+    }
+
+    /**
+     * Answers a <code>boolean</code> indicating whether or not this
+     * CharArrayReader is ready to be read without blocking. If the result is
+     * <code>true</code>, the next <code>read()</code> will not block. If
+     * the result is <code>false</code> this Reader may or may not block when
+     * <code>read()</code> is sent. The implementation in CharArrayReader
+     * always returns <code>true</code> even when it has been closed.
+     * 
+     * @return <code>true</code> if the receiver will not block when
+     *         <code>read()</code> is called, <code>false</code> if unknown
+     *         or blocking will occur.
+     * 
+     * @throws IOException
+     *             If the CharArrayReader is closed.
+     */
+    @Override
     public boolean ready() throws IOException {
-		synchronized (lock) {
-			if (isOpen()) {
-				return pos != count;
-			}
-			throw new IOException(Msg.getString("K0060")); //$NON-NLS-1$
-		}
-	}
-
-	/**
-	 * Reset this CharArrayReader's position to the last <code>mark()</code>
-	 * location. Invocations of <code>read()/skip()</code> will occur from
-	 * this new location. If this Reader was not marked, the CharArrayReader is
-	 * reset to the beginning of the String.
-	 * 
-	 * @throws IOException
-	 *             If this CharArrayReader has already been closed.
-	 */
-	@Override
+        synchronized (lock) {
+            if (isClosed()) {
+                throw new IOException(Msg.getString("K0060")); //$NON-NLS-1$
+            }
+            return pos != count;
+        }
+    }
+
+    /**
+     * Reset this CharArrayReader's position to the last <code>mark()</code>
+     * location. Invocations of <code>read()/skip()</code> will occur from
+     * this new location. If this Reader was not marked, the CharArrayReader is
+     * reset to the beginning of the String.
+     * 
+     * @throws IOException
+     *             If this CharArrayReader has already been closed.
+     */
+    @Override
     public void reset() throws IOException {
-		synchronized (lock) {
-			if (isOpen()) {
-                pos = markedPos != -1 ? markedPos : 0;
-            } else {
+        synchronized (lock) {
+            if (isClosed()) {
                 throw new IOException(Msg.getString("K0060")); //$NON-NLS-1$
             }
-		}
-	}
+            pos = markedPos != -1 ? markedPos : 0;
+        }
+    }
 
-	/**
-	 * Skips <code>count</code> number of characters in this CharArrayReader.
-	 * Subsequent <code>read()</code>'s will not return these characters
-	 * unless <code>reset()</code> is used.
-	 * 
-	 * @param n
-	 *            The number of characters to skip.
-	 * @return long The number of characters actually skipped.
-	 * 
-	 * @throws IOException
-	 *             If this CharArrayReader has already been closed.
-	 */
-	@Override
+    /**
+     * Skips <code>count</code> number of characters in this CharArrayReader.
+     * Subsequent <code>read()</code>'s will not return these characters
+     * unless <code>reset()</code> is used.
+     * 
+     * @param n
+     *            The number of characters to skip.
+     * @return long The number of characters actually skipped.
+     * 
+     * @throws IOException
+     *             If this CharArrayReader has already been closed.
+     */
+    @Override
     public long skip(long n) throws IOException {
-		synchronized (lock) {
-			if (isOpen()) {
-				if (n <= 0) {
-                    return 0;
-                }
-				long skipped = 0;
-				if (n < this.count - pos) {
-					pos = pos + (int) n;
-					skipped = n;
-				} else {
-					skipped = this.count - pos;
-					pos = this.count;
-				}
-				return skipped;
-			}
-			throw new IOException(Msg.getString("K0060")); //$NON-NLS-1$
-		}
-	}
+        synchronized (lock) {
+            if (isClosed()) {
+                throw new IOException(Msg.getString("K0060")); //$NON-NLS-1$
+            }
+            if (n <= 0) {
+                return 0;
+            }
+            long skipped = 0;
+            if (n < this.count - pos) {
+                pos = pos + (int) n;
+                skipped = n;
+            } else {
+                skipped = this.count - pos;
+                pos = this.count;
+            }
+            return skipped;
+        }
+    }
 }



Mime
View raw message