From fddab7dc9b09a03abf7e066fdf88fbf00b2bab89 Mon Sep 17 00:00:00 2001 From: Michael Koch Date: Tue, 18 Mar 2003 07:50:19 +0000 Subject: [PATCH] BufferedOutputStream.java, [...]: More merges from classpath. 2003-03-18 Michael Koch * java/io/BufferedOutputStream.java, java/io/DataInput.java, java/io/DataInputStream.java, java/io/DataOutput.java, java/io/Externalizable.java: More merges from classpath. From-SVN: r64528 --- libjava/ChangeLog | 9 + libjava/java/io/BufferedOutputStream.java | 340 +++++---- libjava/java/io/DataInput.java | 838 +++++++++++----------- libjava/java/io/DataInputStream.java | 4 +- libjava/java/io/DataOutput.java | 331 +++++---- libjava/java/io/Externalizable.java | 85 +-- 6 files changed, 799 insertions(+), 808 deletions(-) diff --git a/libjava/ChangeLog b/libjava/ChangeLog index 64f4388c5a9..d63331d1124 100644 --- a/libjava/ChangeLog +++ b/libjava/ChangeLog @@ -1,3 +1,12 @@ +2003-03-18 Michael Koch + + * java/io/BufferedOutputStream.java, + java/io/DataInput.java, + java/io/DataInputStream.java, + java/io/DataOutput.java, + java/io/Externalizable.java: + More merges from classpath. + 2003-03-18 Michael Koch * configure.in: Fixed links to platform dependant java.net files. diff --git a/libjava/java/io/BufferedOutputStream.java b/libjava/java/io/BufferedOutputStream.java index e324cbcf938..c2f9f6ba955 100644 --- a/libjava/java/io/BufferedOutputStream.java +++ b/libjava/java/io/BufferedOutputStream.java @@ -46,189 +46,179 @@ package java.io; * efficient mechanism for writing versus doing numerous small unbuffered * writes. * - * @version 0.0 - * * @author Aaron M. Renn (arenn@urbanophile.com) */ public class BufferedOutputStream extends FilterOutputStream { - -/*************************************************************************/ - -/* - * Class Variables - */ - -/** - * This is the default buffer size - */ -private static final int DEFAULT_BUFFER_SIZE = 512; - -/*************************************************************************/ - -/* - * Instance Variables - */ - -/** - * 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; - -/*************************************************************************/ - -/* - * Constructors - */ - -/** - * This method initializes a new BufferedOutputStream instance - * that will write to the specified subordinate OutputStream - * and which will use a default buffer size of 512 bytes. - * - * @param out The underlying OutputStream to write data to - */ -public -BufferedOutputStream(OutputStream out) -{ - this(out, DEFAULT_BUFFER_SIZE); -} - -/*************************************************************************/ - -/** - * This method initializes a new BufferedOutputStream instance - * that will write to the specified subordinate OutputStream - * and which will use the specified buffer size - * - * @param out The underlying OutputStream to write data to - * @param size The size of the internal buffer - */ -public -BufferedOutputStream(OutputStream out, int size) -{ - super(out); - - buf = new byte[size]; -} - -/*************************************************************************/ - -/* - * Instance Methods - */ - -/** - * This method causes any currently buffered bytes to be immediately - * written to the underlying output stream. - * - * @exception IOException If an error occurs + /* + * Class Variables + */ + + /** + * This is the default buffer size + */ + private static final int DEFAULT_BUFFER_SIZE = 512; + + /*************************************************************************/ + + /* + * Instance Variables + */ + + /** + * 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; + + /*************************************************************************/ + + /* + * Constructors + */ + + /** + * This method initializes a new BufferedOutputStream instance + * that will write to the specified subordinate OutputStream + * and which will use a default buffer size of 512 bytes. + * + * @param out The underlying OutputStream to write data to + */ + public BufferedOutputStream(OutputStream out) + { + this(out, DEFAULT_BUFFER_SIZE); + } + + /*************************************************************************/ + + /** + * This method initializes a new BufferedOutputStream instance + * that will write to the specified subordinate OutputStream + * and which will use the specified buffer size + * + * @param out The underlying OutputStream to write data to + * @param size The size of the internal buffer + */ + public BufferedOutputStream(OutputStream out, int size) + { + super(out); + + buf = new byte[size]; + } + + /*************************************************************************/ + + /* + * Instance Methods + */ + + /** + * 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(); + } */ -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 + /*************************************************************************/ + + /* + * 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(); + } */ -public synchronized void -write(int b) throws IOException -{ - if (count == buf.length) - flush(); - - buf[count] = (byte)(b & 0xFF); - ++count; -} - -/*************************************************************************/ -/** - * This method writes len bytes from the byte array - * buf starting at position offset 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. + /*************************************************************************/ + + /** + * 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(); - out.write (buf, offset, len); - } -} + + buf[count] = (byte)(b & 0xFF); + ++count; + } + + /*************************************************************************/ + + /** + * This method writes len bytes from the byte array + * buf starting at position offset 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 + diff --git a/libjava/java/io/DataInput.java b/libjava/java/io/DataInput.java index 7de140f4827..d9763e29d2c 100644 --- a/libjava/java/io/DataInput.java +++ b/libjava/java/io/DataInput.java @@ -1,5 +1,5 @@ /* DataInput.java -- Interface for reading data from a stream - Copyright (C) 1998, 1999, 2001 Free Software Foundation, Inc. + Copyright (C) 1998, 1999, 2001, 2003 Free Software Foundation, Inc. This file is part of GNU Classpath. @@ -40,9 +40,8 @@ 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. - */ + * plus online API docs for JDK 1.2 beta from http://www.javasoft.com. + * Status: Believed complete and correct. */ /** * This interface is implemented by classes that can data from streams @@ -54,419 +53,422 @@ package java.io; public interface DataInput { -/** - * This method reads a Java boolean value from an input stream. It does - * so by reading a single byte of data. If that byte is zero, then the - * value returned is false. If the byte is non-zero, then - * the value returned is true. - *

- * This method can read a boolean written by an object - * implementing the writeBoolean() method in the - * DataOutput interface. - * - * @return The boolean value read - * - * @exception EOFException If end of file is reached before reading the boolean - * @exception IOException If any other error occurs - */ -boolean -readBoolean() throws EOFException, IOException; - -/*************************************************************************/ - -/** - * This method reads a Java byte value from an input stream. The value - * is in the range of -128 to 127. - *

- * This method can read a byte written by an object - * implementing the - * writeByte() method in the DataOutput interface. - *

- * @return The byte value read - * - * @exception EOFException If end of file is reached before reading the byte - * @exception IOException If any other error occurs - * - * @see DataOutput - */ -byte -readByte() throws EOFException, IOException; - -/*************************************************************************/ - -/** - * This method reads 8 unsigned bits into a Java int value from - * the stream. The value returned is in the range of 0 to 255. - *

- * This method can read an unsigned byte written by an object implementing the - * writeUnsignedByte() method in the DataOutput - * interface. - * - * @return The unsigned bytes value read as a Java int. - * - * @exception EOFException If end of file is reached before reading the value - * @exception IOException If any other error occurs - * - * @see DataOutput - */ -int -readUnsignedByte() throws EOFException, IOException; - -/*************************************************************************/ - -/** - * This method reads a Java char value from an input stream. - * It operates by reading two bytes from the stream and converting them to - * a single 16-bit Java char. The two bytes are stored most - * significant byte first (i.e., "big endian") regardless of the native - * host byte ordering. - *

- * As an example, if byte1 and byte2 represent the - * first and second byte read from the stream respectively, they will be - * transformed to a char in the following manner: - *

- * (char)((byte1 << 8) + byte2) - *

- * This method can read a char written by an object implementing - * the - * writeChar() method in the DataOutput interface. - * - * @return The char value read - * - * @exception EOFException If end of file is reached before reading the char - * @exception IOException If any other error occurs - * - * @see DataOutput - */ -char -readChar() throws EOFException, IOException; - -/*************************************************************************/ - -/** - * This method reads a signed 16-bit value into a Java in from the stream. - * It operates by reading two bytes from the stream and converting them to - * a single 16-bit Java short. The two bytes are stored most - * significant byte first (i.e., "big endian") regardless of the native - * host byte ordering. - *

- * As an example, if byte1 and byte2 represent the - * first and second byte read from the stream respectively, they will be - * transformed to a short in the following manner: - *

- * (short)((byte1 << 8) + byte2) - *

- * The value returned is in the range of -32768 to 32767. - *

- * This method can read a short written by an object implementing - * the writeShort() method in the DataOutput - * interface. - * - * @return The short value read - * - * @exception EOFException If end of file is reached before reading the value - * @exception IOException If any other error occurs - * - * @see DataOutput - */ -short -readShort() throws EOFException, IOException; - -/*************************************************************************/ - -/** - * This method reads 16 unsigned bits into a Java int value from the stream. - * It operates by reading two bytes from the stream and converting them to - * a single Java int. The two bytes are stored most - * significant byte first (i.e., "big endian") regardless of the native - * host byte ordering. - *

- * As an example, if byte1 and byte2 represent the - * first and second byte read from the stream respectively, they will be - * transformed to an int in the following manner: - *

- * (int)((byte1 << 8) + byte2) - *

- * The value returned is in the range of 0 to 65535. - *

- * This method can read an unsigned short written by an object implementing - * the writeUnsignedShort() method in the DataOutput - * interface. - * - * @return The unsigned short value read as a Java int. - * - * @exception EOFException If end of file is reached before reading the value - * @exception IOException If any other error occurs - */ -int -readUnsignedShort() throws EOFException, IOException; - -/*************************************************************************/ - -/** - * This method reads a Java int value from an input stream - * It operates by reading four bytes from the stream and converting them to - * a single Java int. The bytes are stored most - * significant byte first (i.e., "big endian") regardless of the native - * host byte ordering. - *

- * As an example, if byte1 through byte4 represent - * the first four bytes read from the stream, they will be - * transformed to an int in the following manner: - *

- * (int)((byte1 << 24) + (byte2 << 16) + (byte3 << 8) + byte4)) - *

- The value returned is in the range of -2147483648 to 2147483647. - *

- * This method can read an int written by an object implementing - * the writeInt() method in the DataOutput interface. - * - * @return The int value read - * - * @exception EOFException If end of file is reached before reading the int - * @exception IOException If any other error occurs - * - * @see DataOutput - */ -int -readInt() throws EOFException, IOException; - -/*************************************************************************/ - -/** - * This method reads a Java long value from an input stream - * It operates by reading eight bytes from the stream and converting them to - * a single Java long. The bytes are stored most - * significant byte first (i.e., "big endian") regardless of the native - * host byte ordering. - *

- * As an example, if byte1 through byte8 represent - * the first eight bytes read from the stream, they will be - * transformed to an long in the following manner: - *

- * (long)((byte1 << 56) + (byte2 << 48) + (byte3 << 40) + - * (byte4 << 32) + (byte5 << 24) + (byte6 << 16) + (byte7 << 8) + byte9)) - * - *

- * The value returned is in the range of -9223372036854775808 to - * 9223372036854775807. - *

- * This method can read an long written by an object implementing - * the writeLong() method in the DataOutput - * interface. - * - * @return The long value read - * - * @exception EOFException If end of file is reached before reading the long - * @exception IOException If any other error occurs - * - * @see DataOutput - */ -long -readLong() throws EOFException, IOException; - -/*************************************************************************/ - -/** - * This method reads a Java float value from an input stream. It operates - * by first reading an int value from the stream by calling the - * readInt() method in this interface, then converts that - * int to a float using the - * intBitsToFloat method in the class - * java.lang.Float. - *

- * This method can read a float written by an object implementing - * the writeFloat() method in the DataOutput - * interface. - * - * @return The float value read - * - * @exception EOFException If end of file is reached before reading the float - * @exception IOException If any other error occurs - * - * @see java.lang.Float - * @see DataOutput - */ -float -readFloat() throws EOFException, IOException; - -/*************************************************************************/ - -/** - * This method reads a Java double value from an input stream. It operates - * by first reading a long value from the stream by calling the - * readLong() method in this interface, then converts that - * long to a double using the - * longBitsToDouble method in the class - * java.lang.Double. - *

- * This method can read a double written by an object - * implementing the writeDouble() method in the - * DataOutput interface. - * - * @return The double value read - * - * @exception EOFException If end of file is reached before reading the double - * @exception IOException If any other error occurs - * - * @see java.lang.Double - * @see DataOutput - */ -double -readDouble() throws EOFException, IOException; - -/*************************************************************************/ - -/** - * This method reads the next line of text data from an input stream. - * It operates by reading bytes and converting those bytes to char - * values by treating the byte read as the low eight bits of the - * char and using 0 as the high eight bits. Because of this, - * it does not support the full 16-bit Unicode character set. - *

- * The reading of bytes ends when either the end of file or a line terminator - * is encountered. The bytes read are then returned as a String. - * A line terminator is a byte sequence consisting of either - * \r, \n or \r\n. These termination - * charaters are discarded and are not returned as part of the string. - *

- * This method can read data that was written by an object implementing the - * writeLine() method in DataOutput. - * - * @return The line read as a String - * - * @exception IOException If an error occurs - * - * @see DataOutput - */ -String -readLine() throws IOException; - -/*************************************************************************/ - -/** - * This method reads a String from an input stream that is - * encoded in a modified UTF-8 format. This format has a leading two byte - * sequence that contains the remaining number of bytes to read. This two byte - * sequence is read using the readUnsignedShort() method of this - * interface. - * - * After the number of remaining bytes have been determined, these bytes - * are read an transformed into char values. These - * char values are encoded in the stream using either a one, two, - * or three byte format. - * The particular format in use can be determined by examining the first - * byte read. - *

- * If the first byte has a high order bit of 0, then - * that character consists on only one byte. This character value consists - * of seven bits that are at positions 0 through 6 of the byte. As an - * example, if byte1 is the byte read from the stream, it would - * be converted to a char like so: - *

- * (char)byte1 - *

- * If the first byte has 110 as its high order bits, then the - * character consists of two bytes. The bits that make up the character - * value are in positions 0 through 4 of the first byte and bit positions - * 0 through 5 of the second byte. (The second byte should have - * 10 as its high order bits). These values are in most significant - * byte first (i.e., "big endian") order. - *

- * As an example, if byte1 and byte2 are the first - * two bytes read respectively, and the high order bits of them match the - * patterns which indicate a two byte character encoding, then they would be - * converted to a Java char like so: - *

- * (char)(((byte1 & 0x1F) << 6) + (byte2 & 0x3F)) - *

- * If the first byte has a 1110 as its high order bits, then the - * character consists of three bytes. The bits that make up the character - * value are in positions 0 through 3 of the first byte and bit positions - * 0 through 5 of the other two bytes. (The second and third bytes should - * have 10 as their high order bits). These values are in most - * significant byte first (i.e., "big endian") order. - *

- * As an example, if byte1, byte2, and - * byte3 are the three bytes read, and the high order bits of - * them match the patterns which indicate a three byte character encoding, - * then they would be converted to a Java char like so: - * - * - * (char)(((byte1 & 0x0F) << 12) + ((byte2 & 0x3F) + (byte3 & 0x3F)) - * - * - * Note that all characters are encoded in the method that requires the - * fewest number of bytes with the exception of the character with the - * value of \u0000 which is encoded as two bytes. This is - * a modification of the UTF standard used to prevent C language style - * NUL values from appearing in the byte stream. - *

- * This method can read data that was written by an object implementing the - * writeUTF() method in DataOutput. - * - * @returns The String read - * - * @exception EOFException If end of file is reached before reading the String - * @exception UTFDataFormatException If the data is not in UTF-8 format - * @exception IOException If any other error occurs - * - * @see DataOutput - */ -String -readUTF() throws EOFException, UTFDataFormatException, IOException; - -/*************************************************************************/ - -/** - * This method reads raw bytes into the passed array until the array is - * full. Note that this method blocks until the data is available and - * throws an exception if there is not enough data left in the stream to - * fill the buffer - * - * @param buf The buffer into which to read the data - * - * @exception EOFException If end of file is reached before filling the buffer - * @exception IOException If any other error occurs - */ -void -readFully(byte[] buf) throws EOFException, IOException; - -/*************************************************************************/ - -/** - * This method reads raw bytes into the passed array buf starting - * offset bytes into the buffer. The number of bytes read will be - * exactly len. Note that this method blocks until the data is - * available and * throws an exception if there is not enough data left in - * the stream to read len bytes. - * - * @param buf The buffer into which to read the data - * @param offset The offset into the buffer to start storing data - * @param len The number of bytes to read into the buffer - * - * @exception EOFException If end of file is reached before filling the buffer - * @exception IOException If any other error occurs - */ -void -readFully(byte[] buf, int offset, int len) throws EOFException, IOException; - -/*************************************************************************/ - -/** - * This method skips and discards the specified number of bytes in an - * input stream - * - * @param num_bytes The number of bytes to skip - * - * @return The number of bytes actually skipped, which will always be - * num_bytes - * - * @exception EOFException If end of file is reached before all bytes can be - * skipped - * @exception IOException If any other error occurs - */ -int -skipBytes(int n) throws EOFException, IOException; + /** + * This method reads a Java boolean value from an input stream. It does + * so by reading a single byte of data. If that byte is zero, then the + * value returned is false. If the byte is non-zero, then + * the value returned is true. + *

+ * This method can read a boolean written by an object + * implementing the writeBoolean() method in the + * DataOutput interface. + * + * @return The boolean value read + * + * @exception EOFException If end of file is reached before + * reading the boolean + * @exception IOException If any other error occurs + */ + boolean readBoolean() throws EOFException, IOException; + + /*************************************************************************/ + + /** + * This method reads a Java byte value from an input stream. The value + * is in the range of -128 to 127. + *

+ * This method can read a byte written by an object + * implementing the + * writeByte() method in the DataOutput interface. + *

+ * @return The byte value read + * + * @exception EOFException If end of file is reached before reading the byte + * @exception IOException If any other error occurs + * + * @see DataOutput + */ + byte readByte() throws EOFException, IOException; + + /*************************************************************************/ + + /** + * This method reads 8 unsigned bits into a Java int value from + * the stream. The value returned is in the range of 0 to 255. + *

+ * This method can read an unsigned byte written by an object + * implementing the + * writeUnsignedByte() method in the DataOutput + * interface. + * + * @return The unsigned bytes value read as a Java int. + * + * @exception EOFException If end of file is reached before reading the value + * @exception IOException If any other error occurs + * + * @see DataOutput + */ + int readUnsignedByte() throws EOFException, IOException; + + /*************************************************************************/ + + /** + * This method reads a Java char value from an input stream. + * It operates by reading two bytes from the stream and converting them to + * a single 16-bit Java char. The two bytes are stored most + * significant byte first (i.e., "big endian") regardless of the native + * host byte ordering. + *

+ * As an example, if byte1 and byte2 represent the + * first and second byte read from the stream respectively, they will be + * transformed to a char in the following manner: + *

+ * (char)((byte1 << 8) + byte2) + *

+ * This method can read a char written by an object implementing + * the + * writeChar() method in the DataOutput interface. + * + * @return The char value read + * + * @exception EOFException If end of file is reached before reading the char + * @exception IOException If any other error occurs + * + * @see DataOutput + */ + char readChar() throws EOFException, IOException; + + /*************************************************************************/ + + /** + * This method reads a signed 16-bit value into a Java in from the stream. + * It operates by reading two bytes from the stream and converting them to + * a single 16-bit Java short. The two bytes are stored most + * significant byte first (i.e., "big endian") regardless of the native + * host byte ordering. + *

+ * As an example, if byte1 and byte2 represent the + * first and second byte read from the stream respectively, they will be + * transformed to a short in the following manner: + *

+ * (short)((byte1 << 8) + byte2) + *

+ * The value returned is in the range of -32768 to 32767. + *

+ * This method can read a short written by an object + * implementing + * the writeShort() method in the DataOutput + * interface. + * + * @return The short value read + * + * @exception EOFException If end of file is reached before reading the value + * @exception IOException If any other error occurs + * + * @see DataOutput + */ + short readShort() throws EOFException, IOException; + + /*************************************************************************/ + + /** + * This method reads 16 unsigned bits into a Java int value from the stream. + * It operates by reading two bytes from the stream and converting them to + * a single Java int. The two bytes are stored most + * significant byte first (i.e., "big endian") regardless of the native + * host byte ordering. + *

+ * As an example, if byte1 and byte2 represent the + * first and second byte read from the stream respectively, they will be + * transformed to an int in the following manner: + *

+ * (int)((byte1 << 8) + byte2) + *

+ * The value returned is in the range of 0 to 65535. + *

+ * This method can read an unsigned short written by an object implementing + * the writeUnsignedShort() method in the + * DataOutput + * interface. + * + * @return The unsigned short value read as a Java int. + * + * @exception EOFException If end of file is reached before reading + * the value + * @exception IOException If any other error occurs + */ + int readUnsignedShort() throws EOFException, IOException; + + /*************************************************************************/ + + /** + * This method reads a Java int value from an input stream + * It operates by reading four bytes from the stream and converting them to + * a single Java int. The bytes are stored most + * significant byte first (i.e., "big endian") regardless of the native + * host byte ordering. + *

+ * As an example, if byte1 through byte4 represent + * the first four bytes read from the stream, they will be + * transformed to an int in the following manner: + *

+ * (int)((byte1 << 24) + (byte2 << 16) + (byte3 << 8) + byte4)) + *

+ * The value returned is in the range of -2147483648 to 2147483647. + *

+ * This method can read an int written by an object + * implementing the writeInt() method in the + * DataOutput interface. + * + * @return The int value read + * + * @exception EOFException If end of file is reached before reading the int + * @exception IOException If any other error occurs + * + * @see DataOutput + */ + int readInt() throws EOFException, IOException; + + /*************************************************************************/ + + /** + * This method reads a Java long value from an input stream + * It operates by reading eight bytes from the stream and converting them to + * a single Java long. The bytes are stored most + * significant byte first (i.e., "big endian") regardless of the native + * host byte ordering. + *

+ * As an example, if byte1 through byte8 represent + * the first eight bytes read from the stream, they will be + * transformed to an long in the following manner: + *

+ * (long)((byte1 << 56) + (byte2 << 48) + (byte3 << 40) + + * (byte4 << 32) + (byte5 << 24) + (byte6 << 16) + (byte7 << 8) + byte9)) + * + *

+ * The value returned is in the range of -9223372036854775808 to + * 9223372036854775807. + *

+ * This method can read an long written by an object + * implementing the writeLong() method in the + * DataOutput interface. + * + * @return The long value read + * + * @exception EOFException If end of file is reached before reading the long + * @exception IOException If any other error occurs + * + * @see DataOutput + */ + long readLong() throws EOFException, IOException; + + /*************************************************************************/ + + /** + * This method reads a Java float value from an input stream. It operates + * by first reading an int value from the stream by calling the + * readInt() method in this interface, then converts that + * int to a float using the + * intBitsToFloat method in the class + * java.lang.Float. + *

+ * This method can read a float written by an object + * implementing + * the writeFloat() method in the DataOutput + * interface. + * + * @return The float value read + * + * @exception EOFException If end of file is reached before reading the + * float + * @exception IOException If any other error occurs + * + * @see java.lang.Float + * @see DataOutput + */ + float readFloat() throws EOFException, IOException; + + /*************************************************************************/ + + /** + * This method reads a Java double value from an input stream. It operates + * by first reading a long value from the stream by calling the + * readLong() method in this interface, then converts that + * long to a double using the + * longBitsToDouble method in the class + * java.lang.Double. + *

+ * This method can read a double written by an object + * implementing the writeDouble() method in the + * DataOutput interface. + * + * @return The double value read + * + * @exception EOFException If end of file is reached before reading the + * double + * @exception IOException If any other error occurs + * + * @see java.lang.Double + * @see DataOutput + */ + double readDouble() throws EOFException, IOException; + + /*************************************************************************/ + + /** + * This method reads the next line of text data from an input stream. + * It operates by reading bytes and converting those bytes to + * char + * values by treating the byte read as the low eight bits of the + * char and using 0 as the high eight bits. Because of this, + * it does not support the full 16-bit Unicode character set. + *

+ * The reading of bytes ends when either the end of file or a line terminator + * is encountered. The bytes read are then returned as a + * String. + * A line terminator is a byte sequence consisting of either + * \r, \n or \r\n. These termination + * charaters are discarded and are not returned as part of the string. + *

+ * This method can read data that was written by an object implementing the + * writeLine() method in DataOutput. + * + * @return The line read as a String + * + * @exception IOException If an error occurs + * + * @see DataOutput + */ + String readLine() throws IOException; + + /*************************************************************************/ + + /** + * This method reads a String from an input stream that is + * encoded in a modified UTF-8 format. This format has a leading two byte + * sequence that contains the remaining number of bytes to read. + * This two byte + * sequence is read using the readUnsignedShort() method of this + * interface. + * + * After the number of remaining bytes have been determined, these bytes + * are read an transformed into char values. These + * char values are encoded in the stream using either a one, + * two, or three byte format. + * The particular format in use can be determined by examining the first + * byte read. + *

+ * If the first byte has a high order bit of 0, then + * that character consists on only one byte. This character value consists + * of seven bits that are at positions 0 through 6 of the byte. As an + * example, if byte1 is the byte read from the stream, it would + * be converted to a char like so: + *

+ * (char)byte1 + *

+ * If the first byte has 110 as its high order bits, then the + * character consists of two bytes. The bits that make up the character + * value are in positions 0 through 4 of the first byte and bit positions + * 0 through 5 of the second byte. (The second byte should have + * 10 as its high order bits). These values are in most significant + * byte first (i.e., "big endian") order. + *

+ * As an example, if byte1 and byte2 are the first + * two bytes read respectively, and the high order bits of them match the + * patterns which indicate a two byte character encoding, then they would be + * converted to a Java char like so: + *

+ * (char)(((byte1 & 0x1F) << 6) + (byte2 & 0x3F)) + *

+ * If the first byte has a 1110 as its high order bits, then the + * character consists of three bytes. The bits that make up the character + * value are in positions 0 through 3 of the first byte and bit positions + * 0 through 5 of the other two bytes. (The second and third bytes should + * have 10 as their high order bits). These values are in most + * significant byte first (i.e., "big endian") order. + *

+ * As an example, if byte1, byte2, and + * byte3 are the three bytes read, and the high order bits of + * them match the patterns which indicate a three byte character encoding, + * then they would be converted to a Java char like so: + * + * + * (char)(((byte1 & 0x0F) << 12) + ((byte2 & 0x3F) + (byte3 & 0x3F)) + * + * + * Note that all characters are encoded in the method that requires the + * fewest number of bytes with the exception of the character with the + * value of \u0000 which is encoded as two bytes. + * This is a modification of the UTF standard used to prevent C language + * style NUL values from appearing in the byte stream. + *

+ * This method can read data that was written by an object implementing the + * writeUTF() method in DataOutput. + * + * @returns The String read + * + * @exception EOFException If end of file is reached before reading the + * String + * @exception UTFDataFormatException If the data is not in UTF-8 format + * @exception IOException If any other error occurs + * + * @see DataOutput + */ + String readUTF() throws EOFException, UTFDataFormatException, IOException; + + /*************************************************************************/ + + /** + * This method reads raw bytes into the passed array until the array is + * full. Note that this method blocks until the data is available and + * throws an exception if there is not enough data left in the stream to + * fill the buffer + * + * @param buf The buffer into which to read the data + * + * @exception EOFException If end of file is reached before filling the + * buffer + * @exception IOException If any other error occurs + */ + void readFully(byte[] buf) throws EOFException, IOException; + + /*************************************************************************/ + + /** + * This method reads raw bytes into the passed array buf + * starting + * offset bytes into the buffer. The number of bytes read + * will be + * exactly len. Note that this method blocks until the data is + * available and * throws an exception if there is not enough data left in + * the stream to read len bytes. + * + * @param buf The buffer into which to read the data + * @param offset The offset into the buffer to start storing data + * @param len The number of bytes to read into the buffer + * + * @exception EOFException If end of file is reached before filling the + * buffer + * @exception IOException If any other error occurs + */ + void readFully(byte[] buf, int offset, int len) + throws EOFException, IOException; + + /*************************************************************************/ + + /** + * This method skips and discards the specified number of bytes in an + * input stream + * + * @param num_bytes The number of bytes to skip + * + * @return The number of bytes actually skipped, which will always be + * num_bytes + * + * @exception EOFException If end of file is reached before all bytes can be + * skipped + * @exception IOException If any other error occurs + */ + int skipBytes(int n) throws EOFException, IOException; } // interface DataInput diff --git a/libjava/java/io/DataInputStream.java b/libjava/java/io/DataInputStream.java index 52c0c7a7b82..626da900b59 100644 --- a/libjava/java/io/DataInputStream.java +++ b/libjava/java/io/DataInputStream.java @@ -1,5 +1,5 @@ /* DataInputStream.java -- FilteredInputStream that implements DataInput - Copyright (C) 1998, 1999, 2000, 2001 Free Software Foundation + Copyright (C) 1998, 1999, 2000, 2001, 2003 Free Software Foundation This file is part of GNU Classpath. @@ -50,8 +50,6 @@ package java.io; * * @see DataInput * - * @version 0.0 - * * @author Warren Levy * @author Aaron M. Renn (arenn@urbanophile.com) * @date October 20, 1998. diff --git a/libjava/java/io/DataOutput.java b/libjava/java/io/DataOutput.java index 2538c32efc1..4721f526ac7 100644 --- a/libjava/java/io/DataOutput.java +++ b/libjava/java/io/DataOutput.java @@ -53,176 +53,165 @@ package java.io; public interface DataOutput { -/** - * This method writes a Java boolean value to an output stream - * - * @param value The boolean value to write - * - * @exception IOException If an error occurs - */ -void -writeBoolean(boolean value) throws IOException; - -/*************************************************************************/ - -/** - * This method writes a Java byte value to an output stream - * - * @param value The int value to write - * - * @exception IOException If an error occurs - */ -void -writeByte(int value) throws IOException; - -/*************************************************************************/ - -/** - * This method writes a Java char value to an output stream - * - * @param value The char value to write - * - * @exception IOException If an error occurs - */ -void -writeChar(int value) throws IOException; - -/*************************************************************************/ - -/** - * This method writes a Java int value to an output stream as a 16 bit value - * - * @param value The int value to write as a 16-bit value - * - * @exception IOException If an error occurs - */ -void -writeShort(int value) throws IOException; - -/*************************************************************************/ - -/** - * This method writes a Java int value to an output stream - * - * @param value The int value to write - * - * @exception IOException If an error occurs - */ -void -writeInt(int value) throws IOException; - -/*************************************************************************/ - -/** - * This method writes a Java long value to an output stream - * - * @param value The long value to write - * - * @exception IOException If an error occurs - */ -void -writeLong(long value) throws IOException; - -/*************************************************************************/ - -/** - * This method writes a Java float value to an output stream - * - * @param value The float value to write - * - * @exception IOException If an error occurs - */ -void -writeFloat(float value) throws IOException; - -/*************************************************************************/ - -/** - * This method writes a Java double value to an output stream - * - * @param value The double value to write - * - * @exception IOException If any other error occurs - */ -void -writeDouble(double value) throws IOException; - -/*************************************************************************/ - -/** - * This method writes a String to an output stream as an array of bytes - * - * @param value The String to write - * - * @exception IOException If an error occurs - */ -void -writeBytes(String value) throws IOException; - -/*************************************************************************/ - -/** - * This method writes a String to an output stream as an array of char's - * - * @param value The String to write - * - * @exception IOException If an error occurs - */ -void -writeChars(String value) throws IOException; - -/*************************************************************************/ - -/** - * This method writes a String to an output stream encoded in - * UTF-8 format. - * - * @param value The String to write - * - * @exception IOException If an error occurs - */ -void -writeUTF(String value) throws IOException; - -/*************************************************************************/ - -/** - * This method writes an 8-bit value (passed into the method as a Java - * int) to an output stream. - * - * @param value The byte to write to the output stream - * - * @exception IOException If an error occurs - */ -void -write(int value) throws IOException; - -/*************************************************************************/ - -/** - * This method writes the raw byte array passed in to the output stream. - * - * @param buf The byte array to write - * - * @exception IOException If an error occurs - */ -void -write(byte[] buf) throws IOException; - -/*************************************************************************/ - -/** - * This method writes raw bytes from the passed array buf starting - * offset bytes into the buffer. The number of bytes written will be - * exactly len. - * - * @param buf The buffer from which to write the data - * @param offset The offset into the buffer to start writing data from - * @param len The number of bytes to write from the buffer to the output stream - * - * @exception IOException If any other error occurs - */ -void -write(byte[] buf, int offset, int len) throws IOException; + /** + * This method writes a Java boolean value to an output stream + * + * @param value The boolean value to write + * + * @exception IOException If an error occurs + */ + void writeBoolean(boolean value) throws IOException; + + /*************************************************************************/ + + /** + * This method writes a Java byte value to an output stream + * + * @param value The int value to write + * + * @exception IOException If an error occurs + */ + void writeByte(int value) throws IOException; + + /*************************************************************************/ + + /** + * This method writes a Java char value to an output stream + * + * @param value The char value to write + * + * @exception IOException If an error occurs + */ + void writeChar(int value) throws IOException; + + /*************************************************************************/ + + /** + * This method writes a Java int value to an output stream as a 16 bit value + * + * @param value The int value to write as a 16-bit value + * + * @exception IOException If an error occurs + */ + void writeShort(int value) throws IOException; + + /*************************************************************************/ + + /** + * This method writes a Java int value to an output stream + * + * @param value The int value to write + * + * @exception IOException If an error occurs + */ + void writeInt(int value) throws IOException; + + /*************************************************************************/ + + /** + * This method writes a Java long value to an output stream + * + * @param value The long value to write + * + * @exception IOException If an error occurs + */ + void writeLong(long value) throws IOException; + + /*************************************************************************/ + + /** + * This method writes a Java float value to an output stream + * + * @param value The float value to write + * + * @exception IOException If an error occurs + */ + void writeFloat(float value) throws IOException; + + /*************************************************************************/ + + /** + * This method writes a Java double value to an output stream + * + * @param value The double value to write + * + * @exception IOException If any other error occurs + */ + void writeDouble(double value) throws IOException; + + /*************************************************************************/ + + /** + * This method writes a String to an output stream as an array of bytes + * + * @param value The String to write + * + * @exception IOException If an error occurs + */ + void writeBytes(String value) throws IOException; + + /*************************************************************************/ + + /** + * This method writes a String to an output stream as an array of char's + * + * @param value The String to write + * + * @exception IOException If an error occurs + */ + void writeChars(String value) throws IOException; + + /*************************************************************************/ + + /** + * This method writes a String to an output stream encoded in + * UTF-8 format. + * + * @param value The String to write + * + * @exception IOException If an error occurs + */ + void writeUTF(String value) throws IOException; + + /*************************************************************************/ + + /** + * This method writes an 8-bit value (passed into the method as a Java + * int) to an output stream. + * + * @param value The byte to write to the output stream + * + * @exception IOException If an error occurs + */ + void write(int value) throws IOException; + + /*************************************************************************/ + + /** + * This method writes the raw byte array passed in to the output stream. + * + * @param buf The byte array to write + * + * @exception IOException If an error occurs + */ + void write(byte[] buf) throws IOException; + + /*************************************************************************/ + + /** + * This method writes raw bytes from the passed array buf + * starting + * offset bytes into the buffer. The number of bytes + * written will be * exactly len. + * + * @param buf The buffer from which to write the data + * @param offset The offset into the buffer to start writing data from + * @param len The number of bytes to write from the buffer to the output + * stream + * + * @exception IOException If any other error occurs + */ + void write(byte[] buf, int offset, int len) throws IOException; } // interface DataOutput + diff --git a/libjava/java/io/Externalizable.java b/libjava/java/io/Externalizable.java index 83f1b653ec5..f6406b0335a 100644 --- a/libjava/java/io/Externalizable.java +++ b/libjava/java/io/Externalizable.java @@ -56,55 +56,58 @@ package java.io; * created using the default no-argument constructor and the * readExternal method is used to restore the state. * - * @version 0.0 - * * @author Aaron M. Renn (arenn@urbanophile.com) */ public interface Externalizable extends Serializable { static final long serialVersionUID = -282491828744381764L; -/** - * This method restores an object's state by reading in the instance data - * for the object from the passed in stream. Note that this stream is not - * a subclass of InputStream, but rather is a class that implements - * the ObjectInput interface. That interface provides a mechanism for - * reading in Java data types from a stream. - *

- * Note that this method must be compatible with writeExternal. - * It must read back the exact same types that were written by that - * method in the exact order they were written. - *

- * If this method needs to read back an object instance, then the class - * for that object must be found and loaded. If that operation fails, - * then this method throws a ClassNotFoundException - * - * @param in An ObjectInput instance for reading in the object state - * - * @exception ClassNotFoundException If the class of an object being restored cannot be found - * @exception IOException If any other error occurs - */ -public abstract void -readExternal(ObjectInput in) throws ClassNotFoundException, IOException; + /** + * This method restores an object's state by reading in the instance data + * for the object from the passed in stream. Note that this stream is not + * a subclass of InputStream, but rather is a class that + * implements + * the ObjectInput interface. That interface provides a + * mechanism for + * reading in Java data types from a stream. + *

+ * Note that this method must be compatible with writeExternal. + * It must read back the exact same types that were written by that + * method in the exact order they were written. + *

+ * If this method needs to read back an object instance, then the class + * for that object must be found and loaded. If that operation fails, + * then this method throws a ClassNotFoundException + * + * @param in An ObjectInput instance for reading in the object + * state + * + * @exception ClassNotFoundException If the class of an object being + * restored cannot be found + * @exception IOException If any other error occurs + */ + public abstract void readExternal(ObjectInput in) + throws ClassNotFoundException, IOException; -/*************************************************************************/ + /*************************************************************************/ -/** - * This method is responsible for writing the instance data of an object - * to the passed in stream. Note that this stream is not a subclass of - * OutputStream, but rather is a class that implements the - * ObjectOutput interface. That interface provides a number of methods - * for writing Java data values to a stream. - *

- * Not that the implementation of this method must be coordinated with - * the implementation of readExternal. - * - * @param out An ObjectOutput instance for writing the object state - * - * @exception IOException If an error occurs - */ -public abstract void -writeExternal(ObjectOutput out) throws IOException; + /** + * This method is responsible for writing the instance data of an object + * to the passed in stream. Note that this stream is not a subclass of + * OutputStream, but rather is a class that implements the + * ObjectOutput interface. That interface provides a + * number of methods + * for writing Java data values to a stream. + *

+ * Not that the implementation of this method must be coordinated with + * the implementation of readExternal. + * + * @param out An ObjectOutput instance for writing the + * object state + * + * @exception IOException If an error occurs + */ + public abstract void writeExternal(ObjectOutput out) throws IOException; } // interface Externalizable -- 2.30.2