|
From: <ls...@us...> - 2007-11-03 18:17:02
|
Revision: 3579
http://jnode.svn.sourceforge.net/jnode/?rev=3579&view=rev
Author: lsantha
Date: 2007-11-03 11:16:58 -0700 (Sat, 03 Nov 2007)
Log Message:
-----------
Openjdk integration.
Added Paths:
-----------
trunk/core/src/openjdk/java/java/io/BufferedInputStream.java
trunk/core/src/openjdk/java/java/io/BufferedOutputStream.java
trunk/core/src/openjdk/java/java/io/BufferedReader.java
trunk/core/src/openjdk/java/java/io/BufferedWriter.java
trunk/core/src/openjdk/java/java/io/ByteArrayInputStream.java
trunk/core/src/openjdk/java/java/io/ByteArrayOutputStream.java
trunk/core/src/openjdk/java/java/io/CharArrayReader.java
trunk/core/src/openjdk/java/java/io/CharArrayWriter.java
trunk/core/src/openjdk/java/java/io/DataInputStream.java
trunk/core/src/openjdk/java/java/io/DataOutputStream.java
trunk/core/src/openjdk/java/java/io/FileReader.java
trunk/core/src/openjdk/java/java/io/FileWriter.java
trunk/core/src/openjdk/java/java/io/FilterInputStream.java
trunk/core/src/openjdk/java/java/io/FilterOutputStream.java
trunk/core/src/openjdk/java/java/io/FilterReader.java
trunk/core/src/openjdk/java/java/io/FilterWriter.java
trunk/core/src/openjdk/java/java/io/InputStream.java
trunk/core/src/openjdk/java/java/io/InputStreamReader.java
trunk/core/src/openjdk/java/java/io/LineNumberInputStream.java
trunk/core/src/openjdk/java/java/io/LineNumberReader.java
trunk/core/src/openjdk/java/java/io/OutputStream.java
trunk/core/src/openjdk/java/java/io/OutputStreamWriter.java
trunk/core/src/openjdk/java/java/io/PipedInputStream.java
trunk/core/src/openjdk/java/java/io/PipedOutputStream.java
trunk/core/src/openjdk/java/java/io/PipedReader.java
trunk/core/src/openjdk/java/java/io/PipedWriter.java
trunk/core/src/openjdk/java/java/io/PrintWriter.java
trunk/core/src/openjdk/java/java/io/PushbackInputStream.java
trunk/core/src/openjdk/java/java/io/PushbackReader.java
trunk/core/src/openjdk/java/java/io/Reader.java
trunk/core/src/openjdk/java/java/io/SequenceInputStream.java
trunk/core/src/openjdk/java/java/io/StringBufferInputStream.java
trunk/core/src/openjdk/java/java/io/StringReader.java
trunk/core/src/openjdk/java/java/io/StringWriter.java
trunk/core/src/openjdk/java/java/io/Writer.java
Removed Paths:
-------------
trunk/core/src/classpath/java/java/io/BufferedInputStream.java
trunk/core/src/classpath/java/java/io/BufferedOutputStream.java
trunk/core/src/classpath/java/java/io/BufferedReader.java
trunk/core/src/classpath/java/java/io/BufferedWriter.java
trunk/core/src/classpath/java/java/io/ByteArrayInputStream.java
trunk/core/src/classpath/java/java/io/ByteArrayOutputStream.java
trunk/core/src/classpath/java/java/io/CharArrayReader.java
trunk/core/src/classpath/java/java/io/CharArrayWriter.java
trunk/core/src/classpath/java/java/io/DataInputStream.java
trunk/core/src/classpath/java/java/io/DataOutputStream.java
trunk/core/src/classpath/java/java/io/DeleteFileHelper.java
trunk/core/src/classpath/java/java/io/FileReader.java
trunk/core/src/classpath/java/java/io/FileWriter.java
trunk/core/src/classpath/java/java/io/FilterInputStream.java
trunk/core/src/classpath/java/java/io/FilterOutputStream.java
trunk/core/src/classpath/java/java/io/FilterReader.java
trunk/core/src/classpath/java/java/io/FilterWriter.java
trunk/core/src/classpath/java/java/io/InputStream.java
trunk/core/src/classpath/java/java/io/InputStreamReader.java
trunk/core/src/classpath/java/java/io/LineNumberInputStream.java
trunk/core/src/classpath/java/java/io/LineNumberReader.java
trunk/core/src/classpath/java/java/io/OutputStream.java
trunk/core/src/classpath/java/java/io/OutputStreamWriter.java
trunk/core/src/classpath/java/java/io/PipedInputStream.java
trunk/core/src/classpath/java/java/io/PipedOutputStream.java
trunk/core/src/classpath/java/java/io/PipedReader.java
trunk/core/src/classpath/java/java/io/PipedWriter.java
trunk/core/src/classpath/java/java/io/PrintWriter.java
trunk/core/src/classpath/java/java/io/PushbackInputStream.java
trunk/core/src/classpath/java/java/io/PushbackReader.java
trunk/core/src/classpath/java/java/io/Reader.java
trunk/core/src/classpath/java/java/io/SequenceInputStream.java
trunk/core/src/classpath/java/java/io/StringBufferInputStream.java
trunk/core/src/classpath/java/java/io/StringReader.java
trunk/core/src/classpath/java/java/io/StringWriter.java
trunk/core/src/classpath/java/java/io/Writer.java
trunk/core/src/classpath/java/java/io/class-dependencies.conf
Deleted: trunk/core/src/classpath/java/java/io/BufferedInputStream.java
===================================================================
--- trunk/core/src/classpath/java/java/io/BufferedInputStream.java 2007-11-03 18:08:09 UTC (rev 3578)
+++ trunk/core/src/classpath/java/java/io/BufferedInputStream.java 2007-11-03 18:16:58 UTC (rev 3579)
@@ -1,379 +0,0 @@
-/* BufferedInputStream.java -- An input stream that implements buffering
- Copyright (C) 1998, 1999, 2001, 2005 Free Software Foundation, Inc.
-
-This file is part of GNU Classpath.
-
-GNU Classpath is free software; you can redistribute it and/or modify
-it under the terms of the GNU General Public License as published by
-the Free Software Foundation; either version 2, or (at your option)
-any later version.
-
-GNU Classpath is distributed in the hope that it will be useful, but
-WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-General Public License for more details.
-
-You should have received a copy of the GNU General Public License
-along with GNU Classpath; see the file COPYING. If not, write to the
-Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
-02110-1301 USA.
-
-Linking this library statically or dynamically with other modules is
-making a combined work based on this library. Thus, the terms and
-conditions of the GNU General Public License cover the whole
-combination.
-
-As a special exception, the copyright holders of this library give you
-permission to link this library with independent modules to produce an
-executable, regardless of the license terms of these independent
-modules, and to copy and distribute the resulting executable under
-terms of your choice, provided that you also meet, for each linked
-independent module, the terms and conditions of the license of that
-module. An independent module is a module which is not derived from
-or based on this library. If you modify this library, you may extend
-this exception to your version of the library, but you are not
-obligated to do so. If you do not wish to do so, delete this
-exception statement from your version. */
-
-
-package java.io;
-
-/* Written using "Java Class Libraries", 2nd edition, ISBN 0-201-31002-3
- * "The Java Language Specification", ISBN 0-201-63451-1
- * plus online API docs for JDK 1.2 beta from http://www.javasoft.com.
- * Status: Believed complete and correct.
- */
-
-/**
- * This subclass of <code>FilterInputStream</code> buffers input from an
- * underlying implementation to provide a possibly more efficient read
- * mechanism. It maintains the buffer and buffer state in instance
- * variables that are available to subclasses. The default buffer size
- * of 2048 bytes can be overridden by the creator of the stream.
- * <p>
- * This class also implements mark/reset functionality. It is capable
- * of remembering any number of input bytes, to the limits of
- * system memory or the size of <code>Integer.MAX_VALUE</code>
- * <p>
- * Please note that this class does not properly handle character
- * encodings. Consider using the <code>BufferedReader</code> class which
- * does.
- *
- * @author Aaron M. Renn (ar...@ur...)
- * @author Warren Levy (wa...@cy...)
- * @author Jeroen Frijters (je...@fr...)
- */
-public class BufferedInputStream extends FilterInputStream
-{
-
- /**
- * This is the default buffer size
- */
- private static final int DEFAULT_BUFFER_SIZE = 2048;
-
- /**
- * The buffer used for storing data from the underlying stream.
- */
- protected byte[] buf;
-
- /**
- * The number of valid bytes currently in the buffer. It is also the index
- * of the buffer position one byte past the end of the valid data.
- */
- protected int count;
-
- /**
- * The index of the next character that will by read from the buffer.
- * When <code>pos == count</code>, the buffer is empty.
- */
- protected int pos;
-
- /**
- * The value of <code>pos</code> when the <code>mark()</code> method was
- * called.
- * This is set to -1 if there is no mark set.
- */
- protected int markpos = -1;
-
- /**
- * This is the maximum number of bytes than can be read after a
- * call to <code>mark()</code> before the mark can be discarded.
- * After this may bytes are read, the <code>reset()</code> method
- * may not be called successfully.
- */
- protected int marklimit;
-
- /**
- * This is the initial buffer size. When the buffer is grown because
- * of marking requirements, it will be grown by bufferSize increments.
- * The underlying stream will be read in chunks of bufferSize.
- */
- private final int bufferSize;
-
- /**
- * This method initializes a new <code>BufferedInputStream</code> that will
- * read from the specified subordinate stream with a default buffer size
- * of 2048 bytes
- *
- * @param in The subordinate stream to read from
- */
- public BufferedInputStream(InputStream in)
- {
- this(in, DEFAULT_BUFFER_SIZE);
- }
-
- /**
- * This method initializes a new <code>BufferedInputStream</code> that will
- * read from the specified subordinate stream with a buffer size that
- * is specified by the caller.
- *
- * @param in The subordinate stream to read from
- * @param size The buffer size to use
- *
- * @exception IllegalArgumentException when size is smaller then 1
- */
- public BufferedInputStream(InputStream in, int size)
- {
- 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;
- }
-
- /**
- * This method returns the number of bytes that can be read from this
- * stream before a read can block. A return of 0 indicates that blocking
- * might (or might not) occur on the very next read attempt.
- * <p>
- * The number of available bytes will be the number of read ahead bytes
- * stored in the internal buffer plus the number of available bytes in
- * the underlying stream.
- *
- * @return The number of bytes that can be read before blocking could occur
- *
- * @exception IOException If an error occurs
- */
- public synchronized int available() throws IOException
- {
- return count - pos + super.available();
- }
-
- /**
- * This method closes the underlying input stream and frees any
- * resources associated with it. Sets <code>buf</code> to <code>null</code>.
- *
- * @exception IOException If an error occurs.
- */
- public void close() throws IOException
- {
- // Free up the array memory.
- buf = null;
- pos = count = 0;
- markpos = -1;
- super.close();
- }
-
- /**
- * This method marks a position in the input to which the stream can be
- * "reset" by calling the <code>reset()</code> method. The parameter
- * <code>readlimit</code> is the number of bytes that can be read from the
- * stream after setting the mark before the mark becomes invalid. For
- * example, if <code>mark()</code> is called with a read limit of 10, then
- * when 11 bytes of data are read from the stream before the
- * <code>reset()</code> method is called, then the mark is invalid and the
- * stream object instance is not required to remember the mark.
- * <p>
- * Note that the number of bytes that can be remembered by this method
- * can be greater than the size of the internal read buffer. It is also
- * not dependent on the subordinate stream supporting mark/reset
- * functionality.
- *
- * @param readlimit The number of bytes that can be read before the mark
- * becomes invalid
- */
- public synchronized void mark(int readlimit)
- {
- marklimit = readlimit;
- markpos = pos;
- }
-
- /**
- * This method returns <code>true</code> to indicate that this class
- * supports mark/reset functionality.
- *
- * @return <code>true</code> to indicate that mark/reset functionality is
- * supported
- *
- */
- public boolean markSupported()
- {
- return true;
- }
-
- /**
- * This method reads an unsigned byte from the input stream and returns it
- * as an int in the range of 0-255. This method also will return -1 if
- * the end of the stream has been reached.
- * <p>
- * This method will block until the byte can be read.
- *
- * @return The byte read or -1 if end of stream
- *
- * @exception IOException If an error occurs
- */
- public synchronized int read() throws IOException
- {
- if (pos >= count && !refill())
- return -1; // EOF
-
- return buf[pos++] & 0xFF;
- }
-
- /**
- * This method reads bytes from a stream and stores them into a caller
- * supplied buffer. It starts storing the data at index <code>off</code>
- * into the buffer and attempts to read <code>len</code> bytes. This method
- * can return before reading the number of bytes requested, but it will try
- * to read the requested number of bytes by repeatedly calling the underlying
- * stream as long as available() for this stream continues to return a
- * non-zero value (or until the requested number of bytes have been read).
- * The actual number of bytes read is returned as an int. A -1 is returned
- * to indicate the end of the stream.
- * <p>
- * This method will block until some data can be read.
- *
- * @param b The array into which the bytes read should be stored
- * @param off The offset into the array to start storing bytes
- * @param len The requested number of bytes to read
- *
- * @return The actual number of bytes read, or -1 if end of stream.
- *
- * @exception IOException If an error occurs.
- * @exception IndexOutOfBoundsException when <code>off</code> or
- * <code>len</code> are negative, or when <code>off + len</code>
- * is larger then the size of <code>b</code>,
- */
- public synchronized int read(byte[] b, int off, int len) throws IOException
- {
- if (off < 0 || len < 0 || b.length - off < len)
- throw new IndexOutOfBoundsException();
-
- if (len == 0)
- return 0;
-
- if (pos >= count && !refill())
- return -1; // No bytes were read before EOF.
-
- int totalBytesRead = Math.min(count - pos, len);
- System.arraycopy(buf, pos, b, off, totalBytesRead);
- pos += totalBytesRead;
- off += totalBytesRead;
- len -= totalBytesRead;
-
- while (len > 0 && super.available() > 0 && refill())
- {
- int remain = Math.min(count - pos, len);
- System.arraycopy(buf, pos, b, off, remain);
- pos += remain;
- off += remain;
- len -= remain;
- totalBytesRead += remain;
- }
-
- return totalBytesRead;
- }
-
- /**
- * This method resets a stream to the point where the <code>mark()</code>
- * method was called. Any bytes that were read after the mark point was
- * set will be re-read during subsequent reads.
- * <p>
- * This method will throw an IOException if the number of bytes read from
- * the stream since the call to <code>mark()</code> exceeds the mark limit
- * passed when establishing the mark.
- *
- * @exception IOException If <code>mark()</code> was never called or more
- * then <code>marklimit</code> bytes were read since the last
- * call to <code>mark()</code>
- */
- public synchronized void reset() throws IOException
- {
- if (markpos == -1)
- throw new IOException(buf == null ? "Stream closed." : "Invalid mark.");
-
- pos = markpos;
- }
-
- /**
- * This method skips the specified number of bytes in the stream. It
- * returns the actual number of bytes skipped, which may be less than the
- * requested amount.
- *
- * @param n The requested number of bytes to skip
- *
- * @return The actual number of bytes skipped.
- *
- * @exception IOException If an error occurs
- */
- public synchronized long skip(long n) throws IOException
- {
- if (buf == null)
- throw new IOException("Stream closed.");
-
- final long origN = n;
-
- while (n > 0L)
- {
- if (pos >= count && !refill())
- break;
-
- int numread = (int) Math.min((long) (count - pos), n);
- pos += numread;
- n -= numread;
- }
-
- return origN - n;
- }
-
- /**
- * Called to refill the buffer (when count is equal to pos).
- *
- * @return <code>true</code> when at least one additional byte was read
- * into <code>buf</code>, <code>false</code> otherwise (at EOF).
- */
- private boolean refill() throws IOException
- {
- if (buf == null)
- throw new IOException("Stream closed.");
-
- if (markpos == -1 || count - markpos >= marklimit)
- {
- markpos = -1;
- pos = count = 0;
- }
- else
- {
- byte[] newbuf = buf;
- if (markpos < bufferSize)
- {
- newbuf = new byte[count - markpos + bufferSize];
- }
- System.arraycopy(buf, markpos, newbuf, 0, count - markpos);
- buf = newbuf;
- count -= markpos;
- pos -= markpos;
- markpos = 0;
- }
-
- int numread = super.read(buf, count, bufferSize);
-
- if (numread <= 0) // EOF
- return false;
-
- count += numread;
- return true;
- }
-}
Deleted: trunk/core/src/classpath/java/java/io/BufferedOutputStream.java
===================================================================
--- trunk/core/src/classpath/java/java/io/BufferedOutputStream.java 2007-11-03 18:08:09 UTC (rev 3578)
+++ trunk/core/src/classpath/java/java/io/BufferedOutputStream.java 2007-11-03 18:16:58 UTC (rev 3579)
@@ -1,192 +0,0 @@
-/* BufferedOutputStream.java -- Buffer output into large blocks before writing
- Copyright (C) 1998, 2000, 2003 Free Software Foundation, Inc.
-
-This file is part of GNU Classpath.
-
-GNU Classpath is free software; you can redistribute it and/or modify
-it under the terms of the GNU General Public License as published by
-the Free Software Foundation; either version 2, or (at your option)
-any later version.
-
-GNU Classpath is distributed in the hope that it will be useful, but
-WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-General Public License for more details.
-
-You should have received a copy of the GNU General Public License
-along with GNU Classpath; see the file COPYING. If not, write to the
-Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
-02110-1301 USA.
-
-Linking this library statically or dynamically with other modules is
-making a combined work based on this library. Thus, the terms and
-conditions of the GNU General Public License cover the whole
-combination.
-
-As a special exception, the copyright holders of this library give you
-permission to link this library with independent modules to produce an
-executable, regardless of the license terms of these independent
-modules, and to copy and distribute the resulting executable under
-terms of your choice, provided that you also meet, for each linked
-independent module, the terms and conditions of the license of that
-module. An independent module is a module which is not derived from
-or based on this library. If you modify this library, you may extend
-this exception to your version of the library, but you are not
-obligated to do so. If you do not wish to do so, delete this
-exception statement from your version. */
-
-
-package java.io;
-
-/**
- * This class accumulates bytes written in a buffer instead of immediately
- * writing the data to the underlying output sink. The bytes are instead
- * as one large block when the buffer is filled, or when the stream is
- * closed or explicitly flushed. This mode operation can provide a more
- * efficient mechanism for writing versus doing numerous small unbuffered
- * writes.
- *
- * @author Aaron M. Renn (ar...@ur...)
- */
-public class BufferedOutputStream extends FilterOutputStream
-{
- /**
- * This is the default buffer size
- */
- private static final int DEFAULT_BUFFER_SIZE = 512;
-
- /**
- * This is the internal byte array used for buffering output before
- * writing it.
- */
- protected byte[] buf;
-
- /**
- * This is the number of bytes 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 byte of data will be stored
- */
- protected int count;
-
- /**
- * This method initializes a new <code>BufferedOutputStream</code> instance
- * that will write to the specified subordinate <code>OutputStream</code>
- * and which will use a default buffer size of 512 bytes.
- *
- * @param out The underlying <code>OutputStream</code> to write data to
- */
- public BufferedOutputStream(OutputStream out)
- {
- this(out, DEFAULT_BUFFER_SIZE);
- }
-
- /**
- * This method initializes a new <code>BufferedOutputStream</code> instance
- * that will write to the specified subordinate <code>OutputStream</code>
- * and which will use the specified buffer size
- *
- * @param out The underlying <code>OutputStream</code> to write data to
- * @param size The size of the internal buffer
- */
- public BufferedOutputStream(OutputStream out, int size)
- {
- super(out);
-
- buf = new byte[size];
- }
-
- /**
- * This method causes any currently buffered bytes to be immediately
- * written to the underlying output stream.
- *
- * @exception IOException If an error occurs
- */
- public synchronized void flush() throws IOException
- {
- if (count == 0)
- return;
-
- out.write(buf, 0, count);
- count = 0;
- out.flush();
- }
-
- /**
- * This method flushes any remaining buffered bytes then closes the
- * underlying output stream. Any further attempts to write to this stream
- * may throw an exception
- *
- public synchronized void close() throws IOException
- {
- flush();
- out.close();
- }
- */
-
- /**
- * This method runs when the object is garbage collected. It is
- * responsible for ensuring that all buffered bytes are written and
- * for closing the underlying stream.
- *
- * @exception IOException If an error occurs (ignored by the Java runtime)
- *
- protected void finalize() throws IOException
- {
- close();
- }
- */
-
- /**
- * This method writes a single byte of data. This will be written to the
- * buffer instead of the underlying data source. However, if the buffer
- * is filled as a result of this write request, it will be flushed to the
- * underlying output stream.
- *
- * @param b The byte of data to be written, passed as an int
- *
- * @exception IOException If an error occurs
- */
- public synchronized void write(int b) throws IOException
- {
- if (count == buf.length)
- flush();
-
- buf[count] = (byte)(b & 0xFF);
- ++count;
- }
-
- /**
- * This method writes <code>len</code> bytes from the byte array
- * <code>buf</code> starting at position <code>offset</code> in the buffer.
- * These bytes will be written to the internal buffer. However, if this
- * write operation fills the buffer, the buffer will be flushed to the
- * underlying output stream.
- *
- * @param buf The array of bytes to write.
- * @param offset The index into the byte array to start writing from.
- * @param len The number of bytes to write.
- *
- * @exception IOException If an error occurs
- */
- 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))
- {
- System.arraycopy(buf, offset, this.buf, count, len);
- count += len;
- }
- else
- {
- // 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);
- }
- }
-
-} // class BufferedOutputStream
-
Deleted: trunk/core/src/classpath/java/java/io/BufferedReader.java
===================================================================
--- trunk/core/src/classpath/java/java/io/BufferedReader.java 2007-11-03 18:08:09 UTC (rev 3578)
+++ trunk/core/src/classpath/java/java/io/BufferedReader.java 2007-11-03 18:16:58 UTC (rev 3579)
@@ -1,581 +0,0 @@
-/* BufferedReader.java
- Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005
- Free Software Foundation, Inc.
-
-This file is part of GNU Classpath.
-
-GNU Classpath is free software; you can redistribute it and/or modify
-it under the terms of the GNU General Public License as published by
-the Free Software Foundation; either version 2, or (at your option)
-any later version.
-
-GNU Classpath is distributed in the hope that it will be useful, but
-WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-General Public License for more details.
-
-You should have received a copy of the GNU General Public License
-along with GNU Classpath; see the file COPYING. If not, write to the
-Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
-02110-1301 USA.
-
-Linking this library statically or dynamically with other modules is
-making a combined work based on this library. Thus, the terms and
-conditions of the GNU General Public License cover the whole
-combination.
-
-As a special exception, the copyright holders of this library give you
-permission to link this library with independent modules to produce an
-executable, regardless of the license terms of these independent
-modules, and to copy and distribute the resulting executable under
-terms of your choice, provided that you also meet, for each linked
-independent module, the terms and conditions of the license of that
-module. An independent module is a module which is not derived from
-or based on this library. If you modify this library, you may extend
-this exception to your version of the library, but you are not
-obligated to do so. If you do not wish to do so, delete this
-exception statement from your version. */
-
-
-package java.io;
-
-/* Written using "Java Class Libraries", 2nd edition, plus online
- * API docs for JDK 1.2 beta from http://www.javasoft.com.
- * Status: Believed complete and correct.
- */
-
-/**
- * This subclass of <code>FilterReader</code> buffers input from an
- * underlying implementation to provide a possibly more efficient read
- * mechanism. It maintains the buffer and buffer state in instance
- * variables that are available to subclasses. The default buffer size
- * of 8192 chars can be overridden by the creator of the stream.
- * <p>
- * This class also implements mark/reset functionality. It is capable
- * of remembering any number of input chars, to the limits of
- * system memory or the size of <code>Integer.MAX_VALUE</code>
- *
- * @author Per Bothner (bo...@cy...)
- * @author Aaron M. Renn (ar...@ur...)
- */
-public class BufferedReader extends Reader
-{
- Reader in;
- char[] buffer;
- /* Index of current read position. Must be >= 0 and <= limit. */
- /* There is a special case where pos may be equal to limit+1; this
- * is used as an indicator that a readLine was done with a '\r' was
- * the very last char in the buffer. Since we don't want to read-ahead
- * and potentially block, we set pos this way to indicate the situation
- * and deal with it later. Doing it this way rather than having a
- * separate boolean field to indicate the condition has the advantage
- * that it is self-clearing on things like mark/reset.
- */
- int pos;
- /* Limit of valid data in buffer. Must be >= pos and <= buffer.length. */
- /* This can be < pos in the one special case described above. */
- int limit;
-
- /* The value -1 means there is no mark, or the mark has been invalidated.
- Otherwise, markPos is the index in the buffer of the marked position.
- Must be >= 0 and <= pos.
- Note we do not explicitly store the read-limit.
- The implicit read-limit is (buffer.length - markPos), which is
- guaranteed to be >= the read-limit requested in the call to mark. */
- int markPos = -1;
-
- // The JCL book specifies the default buffer size as 8K characters.
- // This is package-private because it is used by LineNumberReader.
- static final int DEFAULT_BUFFER_SIZE = 8192;
-
- /**
- * The line buffer for <code>readLine</code>.
- */
- private StringBuffer sbuf = null;
-
- /**
- * Create a new <code>BufferedReader</code> that will read from the
- * specified subordinate stream with a default buffer size of 8192 chars.
- *
- * @param in The subordinate stream to read from
- */
- public BufferedReader(Reader in)
- {
- this(in, DEFAULT_BUFFER_SIZE);
- }
-
- /**
- * Create a new <code>BufferedReader</code> that will read from the
- * specified subordinate stream with a buffer size that is specified by the
- * caller.
- *
- * @param in The subordinate stream to read from
- * @param size The buffer size to use
- *
- * @exception IllegalArgumentException if size <= 0
- */
- public BufferedReader(Reader in, int size)
- {
- super(in.lock);
- if (size <= 0)
- throw new IllegalArgumentException("Illegal buffer size: " + size);
- this.in = in;
- buffer = new char[size];
- }
-
- /**
- * This method closes the underlying stream and frees any associated
- * resources.
- *
- * @exception IOException If an error occurs
- */
- public void close() throws IOException
- {
- synchronized (lock)
- {
- if (in != null)
- in.close();
- in = null;
- buffer = null;
- }
- }
-
- /**
- * Returns <code>true</code> to indicate that this class supports mark/reset
- * functionality.
- *
- * @return <code>true</code>
- */
- public boolean markSupported()
- {
- return true;
- }
-
- /**
- * Mark a position in the input to which the stream can be
- * "reset" by calling the <code>reset()</code> method. The parameter
- * <code>readLimit</code> is the number of chars that can be read from the
- * stream after setting the mark before the mark becomes invalid. For
- * example, if <code>mark()</code> is called with a read limit of 10, then
- * when 11 chars of data are read from the stream before the
- * <code>reset()</code> method is called, then the mark is invalid and the
- * stream object instance is not required to remember the mark.
- * <p>
- * Note that the number of chars that can be remembered by this method
- * can be greater than the size of the internal read buffer. It is also
- * not dependent on the subordinate stream supporting mark/reset
- * functionality.
- *
- * @param readLimit The number of chars that can be read before the mark
- * becomes invalid
- *
- * @exception IOException If an error occurs
- * @exception IllegalArgumentException if readLimit is negative.
- */
- public void mark(int readLimit) throws IOException
- {
- if (readLimit < 0)
- throw new IllegalArgumentException("Read-ahead limit is negative");
-
- synchronized (lock)
- {
- checkStatus();
- // In this method we need to be aware of the special case where
- // pos + 1 == limit. This indicates that a '\r' was the last char
- // in the buffer during a readLine. We'll want to maintain that
- // condition after we shift things around and if a larger buffer is
- // needed to track readLimit, we'll have to make it one element
- // larger to ensure we don't invalidate the mark too early, if the
- // char following the '\r' is NOT a '\n'. This is ok because, per
- // the spec, we are not required to invalidate when passing readLimit.
- //
- // Note that if 'pos > limit', then doing 'limit -= pos' will cause
- // limit to be negative. This is the only way limit will be < 0.
-
- if (pos + readLimit > limit)
- {
- char[] old_buffer = buffer;
- int extraBuffSpace = 0;
- if (pos > limit)
- extraBuffSpace = 1;
- if (readLimit + extraBuffSpace > limit)
- buffer = new char[readLimit + extraBuffSpace];
- limit -= pos;
- if (limit >= 0)
- {
- System.arraycopy(old_buffer, pos, buffer, 0, limit);
- pos = 0;
- }
- }
-
- if (limit < 0)
- {
- // Maintain the relationship of 'pos > limit'.
- pos = 1;
- limit = markPos = 0;
- }
- else
- markPos = pos;
- // Now pos + readLimit <= buffer.length. thus if we need to read
- // beyond buffer.length, then we are allowed to invalidate markPos.
- }
- }
-
- /**
- * Reset the stream to the point where the <code>mark()</code> method
- * was called. Any chars that were read after the mark point was set will
- * be re-read during subsequent reads.
- * <p>
- * This method will throw an IOException if the number of chars read from
- * the stream since the call to <code>mark()</code> exceeds the mark limit
- * passed when establishing the mark.
- *
- * @exception IOException If an error occurs;
- */
- public void reset() throws IOException
- {
- synchronized (lock)
- {
- checkStatus();
- if (markPos < 0)
- throw new IOException("mark never set or invalidated");
-
- // Need to handle the extremely unlikely case where a readLine was
- // done with a '\r' as the last char in the buffer; which was then
- // immediately followed by a mark and a reset with NO intervening
- // read of any sort. In that case, setting pos to markPos would
- // lose that info and a subsequent read would thus not skip a '\n'
- // (if one exists). The value of limit in this rare case is zero.
- // We can assume that if limit is zero for other reasons, then
- // pos is already set to zero and doesn't need to be readjusted.
- if (limit > 0)
- pos = markPos;
- }
- }
-
- /**
- * This method determines whether or not a stream is ready to be read. If
- * this method returns <code>false</code> then this stream could (but is
- * not guaranteed to) block on the next read attempt.
- *
- * @return <code>true</code> if this stream is ready to be read,
- * <code>false</code> otherwise
- *
- * @exception IOException If an error occurs
- */
- public boolean ready() throws IOException
- {
- synchronized (lock)
- {
- checkStatus();
- return pos < limit || in.ready();
- }
- }
-
- /**
- * This method read chars from a stream and stores them into a caller
- * supplied buffer. It starts storing the data at index
- * <code>offset</code> into
- * the buffer and attempts to read <code>len</code> chars. This method can
- * return before reading the number of chars requested. The actual number
- * of chars read is returned as an int. A -1 is returned to indicate the
- * end of the stream.
- * <p>
- * This method will block until some data can be read.
- *
- * @param buf The array into which the chars read should be stored
- * @param offset The offset into the array to start storing chars
- * @param count The requested number of chars to read
- *
- * @return The actual number of chars read, or -1 if end of stream.
- *
- * @exception IOException If an error occurs.
- * @exception IndexOutOfBoundsException If offset and count are not
- * valid regarding buf.
- */
- public int read(char[] buf, int offset, int count) throws IOException
- {
- if (offset < 0 || offset + count > buf.length || count < 0)
- throw new IndexOutOfBoundsException();
-
- synchronized (lock)
- {
- checkStatus();
- // Once again, we need to handle the special case of a readLine
- // that has a '\r' at the end of the buffer. In this case, we'll
- // need to skip a '\n' if it is the next char to be read.
- // This special case is indicated by 'pos > limit'.
- boolean retAtEndOfBuffer = false;
-
- int avail = limit - pos;
- if (count > avail)
- {
- if (avail > 0)
- count = avail;
- else // pos >= limit
- {
- if (limit == buffer.length)
- markPos = -1; // read too far - invalidate the mark.
- if (pos > limit)
- {
- // Set a boolean and make pos == limit to simplify things.
- retAtEndOfBuffer = true;
- --pos;
- }
- if (markPos < 0)
- {
- // Optimization: can read directly into buf.
- if (count >= buffer.length && !retAtEndOfBuffer)
- return in.read(buf, offset, count);
- pos = limit = 0;
- }
- avail = in.read(buffer, limit, buffer.length - limit);
- if (retAtEndOfBuffer && avail > 0 && buffer[limit] == '\n')
- {
- --avail;
- limit++;
- }
- if (avail < count)
- {
- if (avail <= 0)
- return avail;
- count = avail;
- }
- limit += avail;
- }
- }
- System.arraycopy(buffer, pos, buf, offset, count);
- pos += count;
- return count;
- }
- }
-
- /* Read more data into the buffer. Update pos and limit appropriately.
- Assumes pos==limit initially. May invalidate the mark if read too much.
- Return number of chars read (never 0), or -1 on eof. */
- private int fill() throws IOException
- {
- checkStatus();
- // Handle the special case of a readLine that has a '\r' at the end of
- // the buffer. In this case, we'll need to skip a '\n' if it is the
- // next char to be read. This special case is indicated by 'pos > limit'.
- boolean retAtEndOfBuffer = false;
- if (pos > limit)
- {
- retAtEndOfBuffer = true;
- --pos;
- }
-
- if (markPos >= 0 && limit == buffer.length)
- markPos = -1;
- if (markPos < 0)
- pos = limit = 0;
- int count = in.read(buffer, limit, buffer.length - limit);
- if (count > 0)
- limit += count;
-
- if (retAtEndOfBuffer && buffer[pos] == '\n')
- {
- --count;
- // If the mark was set to the location of the \n, then we
- // must change it to fully pretend that the \n does not
- // exist.
- if (markPos == pos)
- ++markPos;
- ++pos;
- }
-
- return count;
- }
-
- public int read() throws IOException
- {
- synchronized (lock)
- {
- checkStatus();
- if (pos >= limit && fill () <= 0)
- return -1;
- return buffer[pos++];
- }
- }
-
- /* Return the end of the line starting at this.pos and ending at limit.
- * The index returns is *before* any line terminators, or limit
- * if no line terminators were found.
- */
- private int lineEnd(int limit)
- {
- int i = pos;
- for (; i < limit; i++)
- {
- char ch = buffer[i];
- if (ch == '\n' || ch == '\r')
- break;
- }
- return i;
- }
-
- /**
- * This method reads a single line of text from the input stream, returning
- * it as a <code>String</code>. A line is terminated by "\n", a "\r", or
- * an "\r\n" sequence. The system dependent line separator is not used.
- * The line termination characters are not returned in the resulting
- * <code>String</code>.
- *
- * @return The line of text read, or <code>null</code> if end of stream.
- *
- * @exception IOException If an error occurs
- */
- public String readLine() throws IOException
- {
- checkStatus();
- // Handle the special case where a previous readLine (with no intervening
- // reads/skips) had a '\r' at the end of the buffer.
- // In this case, we'll need to skip a '\n' if it's the next char to be read.
- // This special case is indicated by 'pos > limit'.
- if (pos > limit)
- {
- int ch = read();
- if (ch < 0)
- return null;
- if (ch != '\n')
- --pos;
- }
- int i = lineEnd(limit);
- if (i < limit)
- {
- String str = String.valueOf(buffer, pos, i - pos);
- pos = i + 1;
- // If the last char in the buffer is a '\r', we must remember
- // to check if the next char to be read after the buffer is refilled
- // is a '\n'. If so, skip it. To indicate this condition, we set pos
- // to be limit + 1, which normally is never possible.
- if (buffer[i] == '\r')
- if (pos == limit || buffer[pos] == '\n')
- pos++;
- return str;
- }
- if (sbuf == null)
- sbuf = new StringBuffer(200);
- else
- sbuf.setLength(0);
- sbuf.append(buffer, pos, i - pos);
- pos = i;
- // We only want to return null when no characters were read before
- // EOF. So we must keep track of this separately. Otherwise we
- // would treat an empty `sbuf' as an EOF condition, which is wrong
- // when there is just a newline.
- boolean eof = false;
- for (;;)
- {
- // readLine should block. So we must not return until a -1 is reached.
- if (pos >= limit)
- {
- // here count == 0 isn't sufficient to give a failure.
- int count = fill();
- if (count < 0)
- {
- eof = true;
- break;
- }
- continue;
- }
- int ch = buffer[pos++];
- if (ch == '\n' || ch == '\r')
- {
- // Check here if a '\r' was the last char in the buffer; if so,
- // mark it as in the comment above to indicate future reads
- // should skip a newline that is the next char read after
- // refilling the buffer.
- if (ch == '\r')
- if (pos == limit || buffer[pos] == '\n')
- pos++;
- break;
- }
- i = lineEnd(limit);
- sbuf.append(buffer, pos - 1, i - (pos - 1));
- pos = i;
- }
- return (sbuf.length() == 0 && eof) ? null : sbuf.toString();
- }
-
- /**
- * This method skips the specified number of chars in the stream. It
- * returns the actual number of chars skipped, which may be less than the
- * requested amount.
- * <p>
- * This method first discards chars in the buffer, then calls the
- * <code>skip</code> method on the underlying stream to skip the
- * remaining chars.
- *
- * @param count The requested number of chars to skip
- *
- * @return The actual number of chars skipped.
- *
- * @exception IOException If an error occurs.
- * @exception IllegalArgumentException If count is negative.
- */
- public long skip(long count) throws IOException
- {
- synchronized (lock)
- {
- checkStatus();
- if (count < 0)
- throw new IllegalArgumentException("skip value is negative");
- if (count == 0)
- return 0;
- // Yet again, we need to handle the special case of a readLine
- // that has a '\r' at the end of the buffer. In this case, we need
- // to ignore a '\n' if it is the next char to be read.
- // This special case is indicated by 'pos > limit' (i.e. avail < 0).
- // To simplify things, if we're dealing with the special case for
- // readLine, just read the next char (since the fill method will
- // skip the '\n' for us). By doing this, we'll have to back up pos.
- // That's easier than trying to keep track of whether we've skipped
- // one element or not.
- if (pos > limit)
- {
- if (read() < 0)
- return 0;
- else
- --pos;
- }
-
- int avail = limit - pos;
-
- if (count < avail)
- {
- pos += count;
- return count;
- }
-
- pos = limit;
- long todo = count - avail;
- if (todo > buffer.length)
- {
- markPos = -1;
- todo -= in.skip(todo);
- }
- else
- {
- while (todo > 0)
- {
- avail = fill();
- if (avail <= 0)
- break;
- if (avail > todo)
- avail = (int) todo;
- pos += avail;
- todo -= avail;
- }
- }
- return count - todo;
- }
- }
-
- private void checkStatus() throws IOException
- {
- if (in == null)
- throw new IOException("Stream closed");
- }
-}
Deleted: trunk/core/src/classpath/java/java/io/BufferedWriter.java
===================================================================
--- trunk/core/src/classpath/java/java/io/BufferedWriter.java 2007-11-03 18:08:09 UTC (rev 3578)
+++ trunk/core/src/classpath/java/java/io/BufferedWriter.java 2007-11-03 18:16:58 UTC (rev 3579)
@@ -1,262 +0,0 @@
-/* BufferedWriter.java -- Buffer output into large blocks before writing
- Copyright (C) 1998, 1999, 2000, 2001 Free Software Foundation, Inc.
-
-This file is part of GNU Classpath.
-
-GNU Classpath is free software; you can redistribute it and/or modify
-it under the terms of the GNU General Public License as published by
-the Free Software Foundation; either version 2, or (at your option)
-any later version.
-
-GNU Classpath is distributed in the hope that it will be useful, but
-WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-General Public License for more details.
-
-You should have received a copy of the GNU General Public License
-along with GNU Classpath; see the file COPYING. If not, write to the
-Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
-02110-1301 USA.
-
-Linking this library statically or dynamically with other modules is
-making a combined work based on this library. Thus, the terms and
-conditions of the GNU General Public License cover the whole
-combination.
-
-As a special exception, the copyright holders of this library give you
-permission to link this library with independent modules to produce an
-executable, regardless of the license terms of these independent
-modules, and to copy and distribute the resulting executable under
-terms of your choice, provided that you also meet, for each linked
-independent module, the terms and conditions of the license of that
-module. An independent module is a module which is not derived from
-or based on this library. If you modify this library, you may extend
-this exception to your version of the library, but you are not
-obligated to do so. If you do not wish to do so, delete this
-exception statement from your version. */
-
-
-package java.io;
-
-/* Written using "Java Class Libraries", 2nd edition, ISBN 0-201-31002-3
- * "The Java Language Specification", ISBN 0-201-63451-1
- * Status: Complete to version 1.1.
- */
-
-/**
- * This class accumulates chars written in a buffer instead of immediately
- * writing the data to the underlying output sink. The chars are instead
- * as one large block when the buffer is filled, or when the stream is
- * closed or explicitly flushed. This mode operation can provide a more
- * efficient mechanism for writing versus doing numerous small unbuffered
- * writes.
- *
- * @author Aaron M. Renn (ar...@ur...)
- * @author Tom Tromey (tr...@cy...)
- * @date September 25, 1998
- */
-public class BufferedWriter extends Writer
-{
- /**
- * This is the default buffer size
- */
- private static final int DEFAULT_BUFFER_SIZE = 8192;
-
- /**
- * This is the underlying <code>Writer</code> to which this object
- * sends its output.
- */
- private Writer out;
-
- /**
- * This is the internal char array used for buffering output before
- * writing it.
- */
- 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;
-
- /**
- * This method initializes a new <code>BufferedWriter</code> instance
- * that will write to the specified subordinate <code>Writer</code>
- * and which will use a default buffer size of 8192 chars.
- *
- * @param out The underlying <code>Writer</code> to write data to
- */
- public BufferedWriter (Writer out)
- {
- this (out, DEFAULT_BUFFER_SIZE);
- }
-
- /**
- * This method initializes a new <code>BufferedWriter</code> instance
- * that will write to the specified subordinate <code>Writer</code>
- * and which will use the specified buffer size
- *
- * @param out The underlying <code>Writer</code> to write data to
- * @param size The size of the internal buffer
- */
- public BufferedWriter (Writer out, int size)
- {
- super(out.lock);
- this.out = out;
- this.buffer = new char[size];
- this.count = 0;
- }
-
- /**
- * This method flushes any remaining buffered chars then closes the
- * underlying output stream. Any further attempts to write to this stream
- * may throw an exception
- *
- * @exception IOException If an error occurs.
- */
- public void close () throws IOException
- {
- synchronized (lock)
- {
- // It is safe to call localFlush even if the stream is already
- // closed.
- localFlush ();
- out.close();
- buffer = null;
- }
- }
-
- /**
- * This method causes any currently buffered chars to be immediately
- * written to the underlying output stream.
- *
- * @exception IOException If an error occurs
- */
- public void flush () throws IOException
- {
- synchronized (lock)
- {
- if (buffer == null)
- throw new IOException ("Stream closed");
- localFlush ();
- out.flush();
- }
- }
-
- /**
- * This method writes out a system depedent line separator sequence. The
- * actual value written is detemined from the <xmp>line.separator</xmp>
- * system property.
- *
- * @exception IOException If an error occurs
- */
- public void newLine () throws IOException
- {
- write (System.getProperty("line.separator"));
- }
-
- /**
- * This method writes a single char of data. This will be written to the
- * buffer instead of the underlying data source. However, if the buffer
- * is filled as a result of this write request, it will be flushed to the
- * underlying output stream.
- *
- * @param oneChar The char of data to be written, passed as an int
- *
- * @exception IOException If an error occurs
- */
- public void write (int oneChar) throws IOException
- {
- synchronized (lock)
- {
- if (buffer == null)
- throw new IOException ("Stream closed");
- buffer[count++] = (char) oneChar;
- if (count == buffer.length)
- localFlush ();
- }
- }
-
- /**
- * This method writes <code>len</code> chars from the char array
- * <code>buf</code> starting at position <code>offset</code> in the buffer.
- * These chars will be written to the internal buffer. However, if this
- * write operation fills the buffer, the buffer will be flushed to the
- * underlying output stream.
- *
- * @param buf The array of chars to write.
- * @param offset The index into the char array to start writing from.
- * @param len The number of chars to write.
- *
- * @exception IOException If an error occurs
- */
- public void write (char[] buf, int offset, int len) throws IOException
- {
- synchronized (lock)
- {
- if (buffer == null)
- throw new IOException ("Stream closed");
-
- // Bypass buffering if there is too much incoming data.
- if (count + len > buffer.length)
- {
- localFlush ();
- out.write(buf, offset, len);
- }
- else
- {
- System.arraycopy(buf, offset, buffer, count, len);
- count += len;
- if (count == buffer.length)
- localFlush ();
- }
- }
- }
-
- /**
- * This method writes <code>len</code> chars from the <code>String</code>
- * <code>str</code> starting at position <code>offset</code> in the string.
- * These chars will be written to the internal buffer. However, if this
- * write operation fills the buffer, the buffer will be flushed to the
- * underlying output stream.
- *
- * @param str The <code>String</code> to write.
- * @param offset The index into the string to start writing from.
- * @param len The number of chars to write.
- *
- * @exception IOException If an error occurs
- */
- public void write (String str, int offset, int len) throws IOException
- {
- synchronized (lock)
- {
- if (buffer == null)
- throw new IOException ("Stream closed");
-
- if (count + len > buffer.length)
- {
- localFlush ();
- out.write(str, offset, len);
- }
- else
- {
- str.getChars(offset, offset + len, buffer, count);
- count += len;
- if (count == buffer.length)
- localFlush ();
- }
- }
- }
-
- // This should only be called with the lock held.
- private void localFlush () throws IOException
- {
- if (count > 0)
- {
- out.write(buffer, 0, count);
- count = 0;
- }
- }
-}
Deleted: trunk/core/src/classpath/java/java/io/ByteArrayInputStream.java
===================================================================
--- trunk/core/src/classpath/java/java/io/ByteArrayInputStream.java 2007-11-03 18:08:09 UTC (rev 3578)
+++ trunk/core/src/classpath/java/java/io/ByteArrayInputStream.java 2007-11-03 18:16:58 UTC (rev 3579)
@@ -1,251 +0,0 @@
-/* ByteArrayInputStream.java -- Read an array as a stream
- Copyright (C) 1998, 1999, 2001, 2005 Free Software Foundation, Inc.
-
-This file is part of GNU Classpath.
-
-GNU Classpath is free software; you can redistribute it and/or modify
-it under the terms of the GNU General Public License as published by
-the Free Software Foundation; either version 2, or (at your option)
-any later version.
-
-GNU Classpath is distributed in the hope that it will be useful, but
-WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-General Public License for more details.
-
-You should have received a copy of the GNU General Public License
-along with GNU Classpath; see the file COPYING. If not, write to the
-Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
-02110-1301 USA.
-
-Linking this library statically or dynamically with other modules is
-making a combined work based on this library. Thus, the terms and
-conditions of the GNU General Public License cover the whole
-combination.
-
-As a special exception, the copyright holders of this library give you
-permission to link this library with independent modules to produce an
-executable, regardless of the license terms of these independent
-modules, and to copy and distribute the resulting executable under
-terms of your choice, provided that you also meet, for each linked
-independent module, the terms and conditions of the license of that
-module. An independent module is a module which is not derived from
-or based on this library. If you modify this library, you may extend
-this exception to your version of the library, but you are not
-obligated to do so. If you do not wish to do so, delete this
-exception statement from your version. */
-
-
-package java.io;
-
-/**
- * This class permits an array of bytes to be read as an input stream.
- *
- * @author Warren Levy (wa...@cy...)
- * @author Aaron M. Renn (ar...@ur...)
- */
-public class ByteArrayInputStream extends InputStream
-{
- /**
- * The array that contains the data supplied during read operations
- */
- protected byte[] buf;
-
- /**
- * The array index of the next byte to be read from the buffer
- * <code>buf</code>
- */
- protected int pos;
-
- /**
- * The currently marked position in the stream. This defaults to 0, so a
- * reset operation on the stream resets it to read from array index 0 in
- * the buffer - even if the stream was initially created with an offset
- * greater than 0
- */
- protected int mark;
-
- /**
- * This indicates the maximum number of bytes that can be read from this
- * stream. It is the array index of the position after the last valid
- * byte in the buffer <code>buf</code>
- */
- protected int count;
-
- /**
- * Create a new ByteArrayInputStream that will read bytes from the passed
- * in byte array. This stream will read from the beginning to the end
- * of the array. It is identical to calling an overloaded constructor
- * as <code>ByteArrayInputStream(buf, 0, buf.length)</code>.
- * <p>
- * Note that this array is not copied. If its contents are changed
- * while this stream is being read, those changes will be reflected in the
- * bytes supplied to the reader. Please use caution in changing the
- * contents of the buffer while this stream is open.
- *
- * @param buffer The byte array buffer this stream will read from.
- */
- public ByteArrayInputStream(byte[] buffer)
- {
- this(buffer, 0, buffer.length);
- }
-
- /**
- * Create a new ByteArrayInputStream that will read bytes from the
- * passed in byte array. This stream will read from position
- * <code>offset</code> in the array for a length of
- * <code>length</code> bytes past <code>offset</code>. If the
- * stream is reset to a position before <code>offset</code> then
- * more than <code>length</code> bytes can be read from the stream.
- * The <code>length</code> value should be viewed as the array index
- * one greater than the last position in the buffer to read.
- * <p>
- * Note that this array is not copied. If its contents are changed
- * while this stream is being read, those changes will be reflected in the
- * bytes supplied to the reader. Please use caution in changing the
- * contents of the buffer while this stream is open.
- *
- * @param buffer The byte array buffer this stream will read from.
- * @param offset The index into the buffer to start reading bytes from
- * @param length The number of bytes to read from the buffer
- */
- public ByteArrayInputStream(byte[] buffer, int offset, int length)
- {
- if (offset < 0 || length < 0 || offset > buffer.length)
- throw new IllegalArgumentException();
-
- buf = buffer;
-
- count = offset + length;
- if (count > buf.length)
- count = buf.length;
-
- pos = offset;
- mark = pos;
- }
-
- /**
- * This method returns the number of bytes available to be read from this
- * stream. The value returned will be equal to <code>count - pos</code>.
- *
- * @return The number of bytes that can be read from this stream
- * before blocking, which is all of them
- */
- public synchronized int available()
- {
- return count - pos;
- }
-
- /**
- * This method sets the mark position in this stream to the current
- * position. Note that the <code>readlimit</code> parameter in this
- * method does nothing as this stream is always capable of
- * remembering all the bytes int it.
- * <p>
- * Note that in this class the mark position is set by default to
- * position 0 in the stream. This is in constrast to some other
- * stream types where there is no default mark position.
- *
- * @param readLimit The number of bytes this stream must remember.
- * This parameter is ignored.
- */
- public synchronized void mark(int readLimit)
- {
- // readLimit is ignored per Java Class Lib. book, p.220.
- mark = pos;
- }
-
- /**
- * This method overrides the <code>markSupported</code> method in
- * <code>InputStream</code> in order to return <code>true</code> -
- * indicating that this stream class supports mark/reset
- * functionality.
- *
- * @return <code>true</code> to indicate that this class supports
- * mark/reset.
- */
- public boolean markSupported()
- {
- return true;
- }
-
- /**
- * This method reads one byte from the stream. The <code>pos</code>
- * counter is advanced to the next byte to be read. The byte read is
- * returned as an int in the range of 0-255. If the stream position
- * is already at the end of the buffer, no byte is read and a -1 is
- * returned in order to indicate the end of the stream.
- *
- * @return The byte read, or -1 if end of stream
- */
- public synchronized int read()
- {
- if (pos < count)
- return ((int) buf[pos++]) & 0xFF;
- return -1;
- }
-
- /**
- * This method reads bytes from the stream and stores them into a
- * caller supplied buffer. It starts storing the data at index
- * <code>offset</code> into the buffer and attempts to read
- * <code>len</code> bytes. This method can return before reading
- * the number of bytes re...
[truncated message content] |