|
Message
From: cvs at opencores.org<cvs@o...>
Date: Thu Oct 26 02:48:24 CEST 2006
Subject: [cvs-checkins] MODIFIED: jop ...
Date: 00/06/10 26:02:48 Added: jop/java/target/src/jdk11/java/io ByteArrayInputStream.java ByteArrayOutputStream.java DataInput.java DataInputStream.java DataOutput.java DataOutputStream.java EOFException.java InputStreamReader.java InterruptedIOException.java OutputStreamWriter.java Reader.java Serializable.java UTFDataFormatException.java Writer.java Log: merge with Nelsons JDK and split into three source directories Revision Changes Path 1.1 jop/java/target/src/jdk11/java/io/ByteArrayInputStream.java http://www.opencores.org/cvsweb.shtml/jop/java/target/src/jdk11/java/io/ByteArrayInputStream.java?rev=1.1&content-type=text/x-cvsweb-markup Index: ByteArrayInputStream.java =================================================================== /* 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 (warrenl@c...) * @author Aaron M. Renn (arenn@u...) */ 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 requested if the end of the stream is
* encountered first. The actual number of bytes read is returned.
* If no bytes can be read because the stream is already at the end
* of stream position, a -1 is returned.
* <p>
* This method does not block.
*
* @param buffer The array into which the bytes read should be stored.
* @param offset The offset into the array to start storing bytes
* @param length The requested number of bytes to read
*
* @return The actual number of bytes read, or -1 if end of stream.
*/
public synchronized int read(byte[] buffer, int offset, int length)
{
if (pos >= count)
return -1;
int numBytes = Math.min(count - pos, length);
System.arraycopy(buf, pos, buffer, offset, numBytes);
pos += numBytes;
return numBytes;
}
/**
* This method sets the read position in the stream to the mark
* point by setting the <code>pos</code> variable equal to the
* <code>mark</code> variable. Since a mark can be set anywhere in
* the array, the mark/reset methods int this class can be used to
* provide random search capabilities for this type of stream.
*/
public synchronized void reset()
{
pos = mark;
}
/**
* This method attempts to skip the requested number of bytes in the
* input stream. It does this by advancing the <code>pos</code>
* value by the specified number of bytes. It this would exceed the
* length of the buffer, then only enough bytes are skipped to
* position the stream at the end of the buffer. The actual number
* of bytes skipped is returned.
*
* @param num The requested number of bytes to skip
*
* @return The actual number of bytes skipped.
*/
public synchronized long skip(long num)
{
// Even though the var numBytes is a long, in reality it can never
// be larger than an int since the result of subtracting 2 positive
// ints will always fit in an int. Since we have to return a long
// anyway, numBytes might as well just be a long.
long numBytes = Math.min((long) (count - pos), num < 0 ? 0L : num);
pos += numBytes;
return numBytes;
}
}
1.1 jop/java/target/src/jdk11/java/io/ByteArrayOutputStream.java
http://www.opencores.org/cvsweb.shtml/jop/java/target/src/jdk11/java/io/ByteArrayOutputStream.java?rev=1.1&content-type=text/x-cvsweb-markup
Index: ByteArrayOutputStream.java
===================================================================
/* BufferedReader.java
Copyright (C) 1998, 1999, 2000, 2001, 2003, 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
* Status: Complete to version 1.1.
*/
/**
* This class allows data to be written to a byte array buffer and
* and then retrieved by an application. The internal byte array
* buffer is dynamically resized to hold all the data written. Please
* be aware that writing large amounts to data to this stream will
* cause large amounts of memory to be allocated.
* <p>
* The size of the internal buffer defaults to 32 and it is resized
* by doubling the size of the buffer. This default size can be
* overridden by using the
* <code>gnu.java.io.ByteArrayOutputStream.initialBufferSize</code>
* property.
* <p>
* There is a constructor that specified the initial buffer size and
* that is the preferred way to set that value because it it portable
* across all Java class library implementations.
* <p>
* Note that this class also has methods that convert the byte array
* buffer to a <code>String</code> using either the system default or an
* application specified character encoding. Thus it can handle
* multibyte character encodings.
*
* @author Aaron M. Renn (arenn@u...)
* @author Tom Tromey (tromey@c...)
* @date September 24, 1998
*/
public class ByteArrayOutputStream extends OutputStream
{
/**
* This method initializes a new <code>ByteArrayOutputStream</code>
* with the default buffer size of 32 bytes. If a different initial
* buffer size is desired, see the constructor
* <code>ByteArrayOutputStream(int size)</code>. For applications
* where the source code is not available, the default buffer size
* can be set using the system property
* <code>gnu.java.io.ByteArrayOutputStream.initialBufferSize</code>
*/
public ByteArrayOutputStream ()
{
this (initial_buffer_size);
}
/**
* This method initializes a new <code>ByteArrayOutputStream</code> with
* a specified initial buffer size.
*
* @param size The initial buffer size in bytes
*/
public ByteArrayOutputStream (int size)
{
buf = new byte[size];
count = 0;
}
/**
* This method discards all of the bytes that have been written to
* the internal buffer so far by setting the <code>count</code>
* variable to 0. The internal buffer remains at its currently
* allocated size.
*/
public synchronized void reset ()
{
count = 0;
}
/**
* This method returns the number of bytes that have been written to
* the buffer so far. This is the same as the value of the protected
* <code>count</code> variable. If the <code>reset</code> method is
* called, then this value is reset as well. Note that this method does
* not return the length of the internal buffer, but only the number
* of bytes that have been written to it.
*
* @return The number of bytes in the internal buffer
*
* @see #reset()
*/
public int size ()
{
return count;
}
/**
* This method returns a byte array containing the bytes that have been
* written to this stream so far. This array is a copy of the valid
* bytes in the internal buffer and its length is equal to the number of
* valid bytes, not necessarily to the the length of the current
* internal buffer. Note that since this method allocates a new array,
* it should be used with caution when the internal buffer is very large.
*/
public synchronized byte[] toByteArray ()
{
byte[] ret = new byte[count];
System.arraycopy(buf, 0, ret, 0, count);
return ret;
}
/**
* Returns the bytes in the internal array as a <code>String</code>. The
* bytes in the buffer are converted to characters using the system default
* encoding. There is an overloaded <code>toString()</code> method that
* allows an application specified character encoding to be used.
*
* @return A <code>String</code> containing the data written to this
* stream so far
*/
public String toString ()
{
String tmp = "";
try {
tmp = new String (buf, 0, count);
} catch (UnsupportedEncodingException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return tmp;
}
// Resize buffer to accommodate new bytes.
private void resize (int add)
{
if (count + add > buf.length)
{
int newlen = buf.length * 2;
if (count + add > newlen)
newlen = count + add;
byte[] newbuf = new byte[newlen];
System.arraycopy(buf, 0, newbuf, 0, count);
buf = newbuf;
}
}
/**
* This method writes the writes the specified byte into the internal
* buffer.
*
* @param oneByte The byte to be read passed as an int
*/
public synchronized void write (int oneByte)
{
resize (1);
buf[count++] = (byte) oneByte;
}
/**
* This method writes <code>len</code> bytes from the passed in array
* <code>buf</code> starting at index <code>offset</code> into the
* internal buffer.
*
* @param buffer The byte array to write data from
* @param offset The index into the buffer to start writing data from
* @param add The number of bytes to write
*/
public synchronized void write (byte[] buffer, int offset, int add)
{
// If ADD < 0 then arraycopy will throw the appropriate error for
// us.
if (add >= 0)
resize (add);
System.arraycopy(buffer, offset, buf, count, add);
count += add;
}
/**
* The internal buffer where the data written is stored
*/
protected byte[] buf;
/**
* The number of bytes that have been written to the buffer
*/
protected int count;
/**
* The default initial buffer size. Specified by the JCL.
*/
private static final int DEFAULT_INITIAL_BUFFER_SIZE = 32;
// The default buffer size which can be overridden by the user.
private static final int initial_buffer_size = 32;
}
1.1 jop/java/target/src/jdk11/java/io/DataInput.java
http://www.opencores.org/cvsweb.shtml/jop/java/target/src/jdk11/java/io/DataInput.java?rev=1.1&content-type=text/x-cvsweb-markup
Index: DataInput.java
===================================================================
/* DataInput.java -- Interface for reading data from a stream
Copyright (C) 1998, 1999, 2001, 2003, 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 interface is implemented by classes that can data from streams
* into Java primitive types.
*
* @author Aaron M. Renn (arenn@u...)
* @author Warren Levy (warrenl@c...)
*/
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 <code>false</code>. If the byte is non-zero, then
* the value returned is <code>true</code>.
* <p>
* This method can read a <code>boolean</code> written by an object
* implementing the <code>writeBoolean()</code> method in the
* <code>DataOutput</code> interface.
*
* @return The <code>boolean</code> value read
*
* @exception EOFException If end of file is reached before
* reading the boolean
* @exception IOException If any other error occurs
*
* @see DataOutput#writeBoolean
*/
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.
* <p>
* This method can read a <code>byte</code> written by an object
* implementing the
* <code>writeByte()</code> method in the <code>DataOutput</code> interface.
* <p>
* @return The <code>byte</code> value read
*
* @exception EOFException If end of file is reached before reading the byte
* @exception IOException If any other error occurs
*
* @see DataOutput#writeByte
*/
byte readByte() throws EOFException, IOException;
/**
* This method reads 8 unsigned bits into a Java <code>int</code> value from
* the stream. The value returned is in the range of 0 to 255.
* <p>
* This method can read an unsigned byte written by an object
* implementing the
* <code>writeByte()</code> method in the <code>DataOutput</code>
* interface.
*
* @return The unsigned bytes value read as a Java <code>int</code>.
*
* @exception EOFException If end of file is reached before reading the value
* @exception IOException If any other error occurs
*
* @see DataOutput#writeByte
*/
int readUnsignedByte() throws EOFException, IOException;
/**
* This method reads a Java <code>char</code> value from an input stream.
* It operates by reading two bytes from the stream and converting them to
* a single 16-bit Java <code>char</code>. The two bytes are stored most
* significant byte first (i.e., "big endian") regardless of the native
* host byte ordering.
* <p>
* As an example, if <code>byte1</code> and <code>byte2</code> represent the
* first and second byte read from the stream respectively, they will be
* transformed to a <code>char</code> in the following manner:
* <p>
* <code>(char)((byte1 << 8) + byte2)</code>
* <p>
* This method can read a <code>char</code> written by an object implementing
* the
* <code>writeChar()</code> method in the <code>DataOutput</code> interface.
*
* @return The <code>char</code> value read
*
* @exception EOFException If end of file is reached before reading the char
* @exception IOException If any other error occurs
*
* @see DataOutput#writeChar
*/
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 <code>short</code>. The two bytes are stored most
* significant byte first (i.e., "big endian") regardless of the native
* host byte ordering.
* <p>
* As an example, if <code>byte1</code> and <code>byte2</code> represent the
* first and second byte read from the stream respectively, they will be
* transformed to a <code>short</code> in the following manner:
* <p>
* <code>(short)(((byte1 & 0xFF) << 8) + (byte2 & 0xFF))</code>
* <p>
* The value returned is in the range of -32768 to 32767.
* <p>
* This method can read a <code>short</code> written by an object
* implementing
* the <code>writeShort()</code> method in the <code>DataOutput</code>
* interface.
*
* @return The <code>short</code> value read
*
* @exception EOFException If end of file is reached before reading the value
* @exception IOException If any other error occurs
*
* @see DataOutput#writeShort
*/
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 <code>int</code>. The two bytes are stored most
* significant byte first (i.e., "big endian") regardless of the native
* host byte ordering.
* <p>
* As an example, if <code>byte1</code> and <code>byte2</code> represent the
* first and second byte read from the stream respectively, they will be
* transformed to an <code>int</code> in the following manner:
* <p>
* <code>(int)(((byte1 0xFF) << 8) + (byte2 & 0xFF))</code>
* <p>
* The value returned is in the range of 0 to 65535.
* <p>
* This method can read an unsigned short written by an object implementing
* the <code>writeShort()</code> method in the
* <code>DataOutput</code>
* interface.
*
* @return The unsigned short value read as a Java <code>int</code>.
*
* @exception EOFException If end of file is reached before reading
* the value
* @exception IOException If any other error occurs
*
* @see DataOutput#writeShort
*/
int readUnsignedShort() throws EOFException, IOException;
/**
* This method reads a Java <code>int</code> value from an input stream
* It operates by reading four bytes from the stream and converting them to
* a single Java <code>int</code>. The bytes are stored most
* significant byte first (i.e., "big endian") regardless of the native
* host byte ordering.
* <p>
* As an example, if <code>byte1</code> through <code>byte4</code> represent
* the first four bytes read from the stream, they will be
* transformed to an <code>int</code> in the following manner:
* <p>
* <code>(int)(((byte1 & 0xFF) << 24) + ((byte2 & 0xFF) << 16) +
* ((byte3 & 0xFF)<< 8) + (byte4 & 0xFF)))</code>
* <p>
* The value returned is in the range of -2147483648 to 2147483647.
* <p>
* This method can read an <code>int</code> written by an object
* implementing the <code>writeInt()</code> method in the
* <code>DataOutput</code> interface.
*
* @return The <code>int</code> value read
*
* @exception EOFException If end of file is reached before reading the int
* @exception IOException If any other error occurs
*
* @see DataOutput#writeInt
*/
int readInt() throws EOFException, IOException;
/**
* This method reads a Java <code>long</code> value from an input stream
* It operates by reading eight bytes from the stream and converting them to
* a single Java <code>long</code>. The bytes are stored most
* significant byte first (i.e., "big endian") regardless of the native
* host byte ordering.
* <p>
* As an example, if <code>byte1</code> through <code>byte8</code> represent
* the first eight bytes read from the stream, they will be
* transformed to an <code>long</code> in the following manner:
* <p>
* <code>(long)(((byte1 & 0xFF) << 56) + ((byte2 & 0xFF) << 48) +
* ((byte3 & 0xFF) << 40) + ((byte4 & 0xFF) << 32) +
* ((byte5 & 0xFF) << 24) + ((byte6 & 0xFF) << 16) +
* ((byte7 & 0xFF) << 8) + (byte8 & 0xFF)))
* </code>
* <p>
* The value returned is in the range of -9223372036854775808 to
* 9223372036854775807.
* <p>
* This method can read an <code>long</code> written by an object
* implementing the <code>writeLong()</code> method in the
* <code>DataOutput</code> interface.
*
* @return The <code>long</code> value read
*
* @exception EOFException If end of file is reached before reading the long
* @exception IOException If any other error occurs
*
* @see DataOutput#writeLong
*/
long readLong() throws EOFException, IOException;
/**
* This method reads a <code>String</code> 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 <code>readUnsignedShort()</code> method of this
* interface.
*
* After the number of remaining bytes have been determined, these bytes
* are read an transformed into <code>char</code> values. These
* <code>char</code> 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.
* <p>
* 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 <code>byte1</code> is the byte read from the stream, it would
* be converted to a <code>char</code> like so:
* <p>
* <code>(char)byte1</code>
* <p>
* 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.
* <p>
* As an example, if <code>byte1</code> and <code>byte2</code> 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 <code>char</code> like so:
* <p>
* <code>(char)(((byte1 & 0x1F) << 6) + (byte2 & 0x3F))</code>
* <p>
* 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.
* <p>
* As an example, if <code>byte1</code>, <code>byte2</code>, and
* <code>byte3</code> 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 <code>char</code> like so:
*
* <code>
* (char)(((byte1 & 0x0F) << 12) + ((byte2 & 0x3F) + (byte3 & 0x3F))
* </code>
*
* 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 <code>\<llll>u0000</code> which is encoded as two bytes.
* This is a modification of the UTF standard used to prevent C language
* style <code>NUL</code> values from appearing in the byte stream.
* <p>
* This method can read data that was written by an object implementing the
* <code>writeUTF()</code> method in <code>DataOutput</code>.
*
* @return The <code>String</code> 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#writeUTF
*/
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. Note also that zero length buffers are permitted.
* In this case, the method will return immediately without reading any
* bytes from the stream.
*
* @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 <code>buf</code>
* starting
* <code>offset</code> bytes into the buffer. The number of bytes read
* will be
* exactly <code>len</code>. 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 <code>len</code> bytes. Note also that zero length
* buffers are permitted. In this case, the method will return immediately
* without reading any bytes from the stream.
*
* @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. Note that this method may skip less than the requested
* number of bytes. The actual number of bytes skipped is returned.
* No bytes are skipped if a negative number is passed to this method.
*
* @param numBytes The number of bytes to skip
*
* @return The number of bytes actually skipped, which will always be
* <code>numBytes</code>
*
* @exception EOFException If end of file is reached before all bytes can be
* skipped
* @exception IOException If any other error occurs
*/
int skipBytes(int numBytes) throws EOFException, IOException;
} // interface DataInput
1.1 jop/java/target/src/jdk11/java/io/DataInputStream.java
http://www.opencores.org/cvsweb.shtml/jop/java/target/src/jdk11/java/io/DataInputStream.java?rev=1.1&content-type=text/x-cvsweb-markup
Index: DataInputStream.java
===================================================================
/* DataInputStream.java -- FilteredInputStream that implements DataInput
Copyright (C) 1998, 1999, 2000, 2001, 2003, 2005 Free Software Foundation
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>FilteredInputStream</code> implements the
* <code>DataInput</code> interface that provides method for reading primitive
* Java data types from a stream.
*
* @see DataInput
*
* @author Warren Levy (warrenl@c...)
* @author Aaron M. Renn (arenn@u...)
* @date October 20, 1998.
*/
public class DataInputStream extends InputStream implements DataInput
{
// Byte buffer, used to make primitive read calls more efficient.
byte[] buf = new byte [8];
InputStream in;
/**
* This constructor initializes a new <code>DataInputStream</code>
* to read from the specified subordinate stream.
*
* @param in The subordinate <code>InputStream</code> to read from
*/
public DataInputStream (InputStream in)
{
this.in = in;
}
/**
* This method reads bytes from the underlying stream into the specified
* byte array buffer. It will attempt to fill the buffer completely, but
* may return a short count if there is insufficient data remaining to be
* read to fill the buffer.
*
* @param b The buffer into which bytes will be read.
*
* @return The actual number of bytes read, or -1 if end of stream reached
* before reading any bytes.
*
* @exception IOException If an error occurs.
*/
public final int read (byte[] b) throws IOException
{
return in.read (b, 0, b.length);
}
/**
* This method reads one byte from the underlying stream.
*
* @return The byte read , or -1 if end of stream reached
* before reading any bytes.
*
* @exception IOException If an error occurs.
*/
public int read() throws IOException
{
byte[] b = new byte[1];
read(b);
return (int)b[0];
}
/**
* This method reads bytes from the underlying stream into the specified
* byte array buffer. It will attempt to read <code>len</code> bytes and
* will start storing them at position <code>off</code> into the buffer.
* This method can return a short count if there is insufficient data
* remaining to be read to complete the desired read length.
*
* @param b The buffer into which bytes will be read.
* @param off The offset into the buffer 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 reached
* before reading any bytes.
*
* @exception IOException If an error occurs.
*/
public final int read (byte[] b, int off, int len) throws IOException
{
return in.read (b, off, len);
}
/**
* 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 <code>false</code>. If the byte is non-zero, then
* the value returned is <code>true</code>.
* <p>
* This method can read a <code>boolean</code> written by an object
* implementing the <code>writeBoolean()</code> method in the
* <code>DataOutput</code> interface.
*
* @return The <code>boolean</code> value read
*
* @exception EOFException If end of file is reached before reading
* the boolean
* @exception IOException If any other error occurs
*
* @see DataOutput#writeBoolean
*/
public final boolean readBoolean () throws IOException
{
return convertToBoolean (in.read ());
}
/**
* This method reads a Java byte value from an input stream. The value
* is in the range of -128 to 127.
* <p>
* This method can read a <code>byte</code> written by an object
* implementing the <code>writeByte()</code> method in the
* <code>DataOutput</code> interface.
*
* @return The <code>byte</code> value read
*
* @exception EOFException If end of file is reached before reading the byte
* @exception IOException If any other error occurs
*
* @see DataOutput#writeByte
*/
public final byte readByte () throws IOException
{
return convertToByte (in.read ());
}
/**
* This method reads a Java <code>char</code> value from an input stream.
* It operates by reading two bytes from the stream and converting them to
* a single 16-bit Java <code>char</code>. The two bytes are stored most
* significant byte first (i.e., "big endian") regardless of the native
* host byte ordering.
* <p>
* As an example, if <code>byte1</code> and <code>byte2</code>
* represent the first and second byte read from the stream
* respectively, they will be transformed to a <code>char</code> in
* the following manner:
* <p>
* <code>(char)(((byte1 & 0xFF) << 8) | (byte2 & 0xFF)</code>
* <p>
* This method can read a <code>char</code> written by an object
* implementing the <code>writeChar()</code> method in the
* <code>DataOutput</code> interface.
*
* @return The <code>char</code> value read
*
* @exception EOFException If end of file is reached before reading the char
* @exception IOException If any other error occurs
*
* @see DataOutput#writeChar
*/
public final char readChar () throws IOException
{
readFully (buf, 0, 2);
return convertToChar (buf);
}
/**
* 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. Note also that zero length buffers are permitted.
* In this case, the method will return immediately without reading any
* bytes from the stream.
*
* @param b 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
*/
public final void readFully (byte[] b) throws IOException
{
readFully (b, 0, b.length);
}
/**
* This method reads raw bytes into the passed array <code>buf</code>
* starting
* <code>offset</code> bytes into the buffer. The number of bytes read
* will be
* exactly <code>len</code>. 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 <code>len</code> bytes. Note also that zero length
* buffers are permitted. In this case, the method will return immediately
* without reading any bytes from the stream.
*
* @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
*/
public final void readFully (byte[] buf, int offset, int len) throws IOException
{
if (len < 0)
throw new IndexOutOfBoundsException("Negative length: " + len);
while (len > 0)
{
// in.read will block until some data is available.
int numread = in.read (buf, offset, len);
if (numread < 0)
throw new EOFException ();
len -= numread;
offset += numread;
}
}
/**
* This method reads a Java <code>int</code> value from an input stream
* It operates by reading four bytes from the stream and converting them to
* a single Java <code>int</code>. The bytes are stored most
* significant byte first (i.e., "big endian") regardless of the native
* host byte ordering.
* <p>
* As an example, if <code>byte1</code> through <code>byte4</code> represent
* the first four bytes read from the stream, they will be
* transformed to an <code>int</code> in the following manner:
* <p>
* <code>(int)(((byte1 & 0xFF) << 24) + ((byte2 & 0xFF) << 16) +
* ((byte3 & 0xFF)<< 8) + (byte4 & 0xFF)))</code>
* <p>
* The value returned is in the range of -2147483648 to 2147483647.
* <p>
* This method can read an <code>int</code> written by an object
* implementing the <code>writeInt()</code> method in the
* <code>DataOutput</code> interface.
*
* @return The <code>int</code> value read
*
* @exception EOFException If end of file is reached before reading the int
* @exception IOException If any other error occurs
*
* @see DataOutput#writeInt
*/
public final int readInt () throws IOException
{
readFully (buf, 0, 4);
return convertToInt (buf);
}
/**
* This method reads a Java <code>long</code> value from an input stream
* It operates by reading eight bytes from the stream and converting them to
* a single Java <code>long</code>. The bytes are stored most
* significant byte first (i.e., "big endian") regardless of the native
* host byte ordering.
* <p>
* As an example, if <code>byte1</code> through <code>byte8</code> represent
* the first eight bytes read from the stream, they will be
* transformed to an <code>long</code> in the following manner:
* <p>
* <code>(long)(((byte1 & 0xFF) << 56) + ((byte2 & 0xFF) << 48) +
* ((byte3 & 0xFF) << 40) + ((byte4 & 0xFF) << 32) +
* ((byte5 & 0xFF) << 24) + ((byte6 & 0xFF) << 16) +
* ((byte7 & 0xFF) << 8) + (byte8 & 0xFF)))
* </code>
* <p>
* The value returned is in the range of -9223372036854775808 to
* 9223372036854775807.
* <p>
* This method can read an <code>long</code> written by an object
* implementing the <code>writeLong()</code> method in the
* <code>DataOutput</code> interface.
*
* @return The <code>long</code> value read
*
* @exception EOFException If end of file is reached before reading the long
* @exception IOException If any other error occurs
*
* @see DataOutput#writeLong
*/
public final long readLong () throws IOException
{
readFully (buf, 0, 8);
return convertToLong (buf);
}
/**
* 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 <code>short</code>. The
* two bytes are stored most significant byte first (i.e., "big
* endian") regardless of the native host byte ordering.
* <p>
* As an example, if <code>byte1</code> and <code>byte2</code>
* represent the first and second byte read from the stream
* respectively, they will be transformed to a <code>short</code>. in
* the following manner:
* <p>
* <code>(short)(((byte1 & 0xFF) << 8) | (byte2 & 0xFF))</code>
* <p>
* The value returned is in the range of -32768 to 32767.
* <p>
* This method can read a <code>short</code> written by an object
* implementing the <code>writeShort()</code> method in the
* <code>DataOutput</code> interface.
*
* @return The <code>short</code> value read
*
* @exception EOFException If end of file is reached before reading the value
* @exception IOException If any other error occurs
*
* @see DataOutput#writeShort
*/
public final short readShort () throws IOException
{
readFully (buf, 0, 2);
return convertToShort (buf);
}
/**
* This method reads 8 unsigned bits into a Java <code>int</code>
* value from the stream. The value returned is in the range of 0 to
* 255.
* <p>
* This method can read an unsigned byte written by an object
* implementing the <code>writeUnsignedByte()</code> method in the
* <code>DataOutput</code> interface.
*
* @return The unsigned bytes value read as a Java <code>int</code>.
*
* @exception EOFException If end of file is reached before reading the value
* @exception IOException If any other error occurs
*
* @see DataOutput#writeByte
*/
public final int readUnsignedByte () throws IOException
{
return convertToUnsignedByte (in.read ());
}
/**
* 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 <code>int</code> The two bytes are stored most
* significant byte first (i.e., "big endian") regardless of the native
* host byte ordering.
* <p>
* As an example, if <code>byte1</code> and <code>byte2</code>
* represent the first and second byte read from the stream
* respectively, they will be transformed to an <code>int</code> in
* the following manner:
* <p>
* <code>(int)(((byte1 & 0xFF) << 8) + (byte2 & 0xFF))</code>
* <p>
* The value returned is in the range of 0 to 65535.
* <p>
* This method can read an unsigned short written by an object
* implementing the <code>writeUnsignedShort()</code> method in the
* <code>DataOutput</code> interface.
*
* @return The unsigned short value read as a Java <code>int</code>
*
* @exception EOFException If end of file is reached before reading the value
* @exception IOException If any other error occurs
*
* @see DataOutput#writeShort
*/
public final int readUnsignedShort () throws IOException
{
readFully (buf, 0, 2);
return convertToUnsignedShort (buf);
}
/**
* This method reads a <code>String</code> 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
* <code>readUnsignedShort()</code> method of this interface.
* <p>
* After the number of remaining bytes have been determined, these
* bytes are read an transformed into <code>char</code> values.
* These <code>char</code> 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.
* <p>
* 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 <code>byte1</code> is the byte read from the stream,
* it would be converted to a <code>char</code> like so:
* <p>
* <code>(char)byte1</code>
* <p>
* 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.
* <p>
* As an example, if <code>byte1</code> and <code>byte2</code> 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
* <code>char</code> like so:
* <p>
* <code>(char)(((byte1 & 0x1F) << 6) | (byte2 & 0x3F))</code>
* <p>
* 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.
* <p>
* As an example, if <code>byte1</code> <code>byte2</code> and
* <code>byte3</code> 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
* <code>char</code> like so:
* <p>
* <code>(char)(((byte1 & 0x0F) << 12) | ((byte2 & 0x3F) << 6) |
* (byte3 & 0x3F))</code>
* <p>
* 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 <code>\u0000</code> which is encoded as two
* bytes. This is a modification of the UTF standard used to
* prevent C language style <code>NUL</code> values from appearing
* in the byte stream.
* <p>
* This method can read data that was written by an object implementing the
* <code>writeUTF()</code> method in <code>DataOutput</code>
*
* @return The <code>String</code> 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#writeUTF
*/
public final String readUTF () throws IOException
{
return readUTF (this);
}
/**
* This method reads a String encoded in UTF-8 format from the
* specified <code>DataInput</code> source.
*
* @param in The <code>DataInput</code> source to read from
*
* @return The String read from the source
*
* @exception IOException If an error occurs
*
* @see DataInput#readUTF
*/
public static final String readUTF(DataInput in) throws IOException
{
final int UTFlen = in.readUnsignedShort ();
byte[] buf = new byte [UTFlen];
// This blocks until the entire string is available rather than
// doing partial processing on the bytes that are available and then
// blocking. An advantage of the latter is that Exceptions
// could be thrown earlier. The former is a bit cleaner.
in.readFully (buf, 0, UTFlen);
return convertFromUTF (buf);
}
/**
* This method attempts to skip and discard the specified number of bytes
* in the input stream. It may actually skip fewer bytes than requested.
* This method will not skip any bytes if passed a negative number of bytes
* to skip.
*
* @param n The requested number of bytes to skip.
*
* @return The requested number of bytes to skip.
*
* @exception IOException If an error occurs.
* @specnote The JDK docs claim that this returns the number of bytes
* actually skipped. The JCL claims that this method can throw an
* EOFException. Neither of these appear to be true in the JDK 1.3's
* implementation. This tries to implement the actual JDK behaviour.
*/
public final int skipBytes (int n) throws IOException
{
if (n <= 0)
return 0;
try
{
return (int) in.skip (n);
}
catch (EOFException x)
{
// do nothing.
}
return n;
}
static boolean convertToBoolean (int b) throws EOFException
{
if (b < 0)
throw new EOFException ();
return (b != 0);
}
static byte convertToByte (int i) throws EOFException
{
if (i < 0)
throw new EOFException ();
return (byte) i;
}
static int convertToUnsignedByte (int i) throws EOFException
{
if (i < 0)
throw new EOFException ();
return (i & 0xFF);
}
static char convertToChar (byte[] buf)
{
return (char) ((buf [0] << 8)
| (buf [1] & 0xff));
}
static short convertToShort (byte[] buf)
{
return (short) ((buf [0] << 8)
| (buf [1] & 0xff));
}
static int convertToUnsignedShort (byte[] buf)
{
return (((buf [0] & 0xff) << 8)
| (buf [1] & 0xff));
}
static int convertToInt (byte[] buf)
{
return (((buf [0] & 0xff) << 24)
| ((buf [1] & 0xff) << 16)
| ((buf [2] & 0xff) << 8)
| (buf [3] & 0xff));
}
static long convertToLong (byte[] buf)
{
return (((long)(buf [0] & 0xff) << 56) |
((long)(buf [1] & 0xff) << 48) |
((long)(buf [2] & 0xff) << 40) |
((long)(buf [3] & 0xff) << 32) |
((long)(buf [4] & 0xff) << 24) |
((long)(buf [5] & 0xff) << 16) |
((long)(buf [6] & 0xff) << 8) |
((long)(buf [7] & 0xff)));
}
// FIXME: This method should be re-thought. I suspect we have multiple
// UTF-8 decoders floating around. We should use the standard charset
// converters, maybe and adding a direct call into one of the new
// NIO converters for a super-fast UTF8 decode.
static String convertFromUTF (byte[] buf)
throws EOFException, UTFDataFormatException
{
// Give StringBuffer an initial estimated size to avoid
// enlarge buffer frequently
StringBuffer strbuf = new StringBuffer (buf.length / 2 + 2);
for (int i = 0; i < buf.length; )
{
if ((buf [i] & 0x80) == 0) // bit pattern 0xxxxxxx
strbuf.append ((char) (buf [i++] & 0xFF));
else if ((buf [i] & 0xE0) == 0xC0) // bit pattern 110xxxxx
{
if (i + 1 >= buf.length
|| (buf [i + 1] & 0xC0) != 0x80)
throw new UTFDataFormatException ();
strbuf.append((char) (((buf [i++] & 0x1F) << 6)
| (buf [i++] & 0x3F)));
}
else if ((buf [i] & 0xF0) == 0xE0) // bit pattern 1110xxxx
{
if (i + 2 >= buf.length
|| (buf [i + 1] & 0xC0) != 0x80
|| (buf [i + 2] & 0xC0) != 0x80)
throw new UTFDataFormatException ();
strbuf.append ((char) (((buf [i++] & 0x0F) << 12)
| ((buf [i++] & 0x3F) << 6)
| (buf [i++] & 0x3F)));
}
else // must be ((buf [i] & 0xF0) == 0xF0 || (buf [i] & 0xC0) == 0x80)
throw new UTFDataFormatException (); // bit patterns 1111xxxx or
// 10xxxxxx
}
return strbuf.toString ();
}
}
1.1 jop/java/target/src/jdk11/java/io/DataOutput.java
http://www.opencores.org/cvsweb.shtml/jop/java/target/src/jdk11/java/io/DataOutput.java?rev=1.1&content-type=text/x-cvsweb-markup
Index: DataOutput.java
===================================================================
/* DataOutput.java -- Interface for writing data from a stream
Copyright (C) 1998, 1999, 2001, 2003, 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
* Status: Complete to version 1.1.
*/
/**
* This interface is implemented by classes that can wrte data to streams
* from Java primitive types. This data can subsequently be read back
* by classes implementing the <code>DataInput</code> interface.
*
* @author Aaron M. Renn (arenn@u...)
* @author Tom Tromey (tromey@c...)
*
* @see DataInput
*/
public interface DataOutput
{
/**
* This method writes a Java boolean value to an output stream. If
* <code>value</code> is <code>true</code>, a byte with the value of
* 1 will be written, otherwise a byte with the value of 0 will be
* written.
*
* The value written can be read using the <code>readBoolean</code>
* method in <code>DataInput</code>.
*
* @param value The boolean value to write
*
* @exception IOException If an error occurs
*
* @see DataInput#readBoolean
*/
void writeBoolean(boolean value) throws IOException;
/**
* This method writes a Java byte value to an output stream. The
* byte to be written will be in the lowest 8 bits of the
* <code>int</code> value passed.
*
* The value written can be read using the <code>readByte</code> or
* <code>readUnsignedByte</code> methods in <code>DataInput</code>.
*
* @param value The int value to write
*
* @exception IOException If an error occurs
*
* @see DataInput#readByte
* @see DataInput#readUnsignedByte
*/
void writeByte(int value) throws IOException;
/**
* This method writes a Java char value to an output stream. The
* char to be written will be in the lowest 16 bits of the <code>int</code>
* value passed. These bytes will be written "big endian". That is,
* with the high byte written first in the following manner:
* <p>
* <code>byte0 = (byte)((value & 0xFF00) >> 8);<br>
* byte1 = (byte)(value & 0x00FF);</code>
* <p>
*
* The value written can be read using the <code>readChar</code>
* method in <code>DataInput</code>.
*
* @param value The char value to write
*
* @exception IOException If an error occurs
*
* @see DataInput#readChar
*/
void writeChar(int value) throws IOException;
/**
* This method writes a Java short value to an output stream. The
* char to be written will be in the lowest 16 bits of the <code>int</code>
* value passed. These bytes will be written "big endian". That is,
* with the high byte written first in the following manner:
* <p>
* <code>byte0 = (byte)((value & 0xFF00) >> 8);<br>
* byte1 = (byte)(value & 0x00FF);</code>
* <p>
*
* The value written can be read using the <code>readShort</code> and
* <code>readUnsignedShort</code> methods in <code>DataInput</code>.
*
* @param value The int value to write as a 16-bit value
*
* @exception IOException If an error occurs
*
* @see DataInput#readShort
* @see DataInput#readUnsignedShort
*/
void writeShort(int value) throws IOException;
/**
* This method writes a Java int value to an output stream. The 4 bytes
* of the passed value will be written "big endian". That is, with
* the high byte written first in the following manner:
* <p>
* <code>byte0 = (byte)((value & 0xFF000000) >> 24);<br>
* byte1 = (byte)((value & 0x00FF0000) >> 16);<br>
* byte2 = (byte)((value & 0x0000FF00) >> 8);<br>
* byte3 = (byte)(value & 0x000000FF);</code>
* <p>
*
* The value written can be read using the <code>readInt</code>
* method in <code>DataInput</code>.
*
* @param value The int value to write
*
* @exception IOException If an error occurs
*
* @see DataInput#readInt
*/
void writeInt(int value) throws IOException;
/**
* This method writes a Java long value to an output stream. The 8 bytes
* of the passed value will be written "big endian". That is, with
* the high byte written first in the following manner:
* <p>
* <code>byte0 = (byte)((value & 0xFF00000000000000L) >> 56);<br>
* byte1 = (byte)((value & 0x00FF000000000000L) >> 48);<br>
* byte2 = (byte)((value & 0x0000FF0000000000L) >> 40);<br>
* byte3 = (byte)((value & 0x000000FF00000000L) >> 32);<br>
* byte4 = (byte)((value & 0x00000000FF000000L) >> 24);<br>
* byte5 = (byte)((value & 0x0000000000FF0000L) >> 16);<br>
* byte6 = (byte)((value & 0x000000000000FF00L) >> 8);<br>
* byte7 = (byte)(value & 0x00000000000000FFL);</code>
* <p>
*
* The value written can be read using the <code>readLong</code>
* method in <code>DataInput</code>.
*
* @param value The long value to write
*
* @exception IOException If an error occurs
*
* @see DataInput#readLong
*/
void writeLong(long value) throws IOException;
/**
* This method writes all the characters of a <code>String</code> to an
* output stream as an array of <code>char</code>'s. Each character
* is written using the method specified in the <code>writeChar</code>
* method.
*
* @param value The String to write
*
* @exception IOException If an error occurs
*
* @see #writeChar(int)
*/
void writeChars(String value) throws IOException;
/**
* This method writes a Java <code>String</code> to the stream in a modified
* UTF-8 format. First, two bytes are written to the stream indicating the
* number of bytes to follow. This is written in the form of a Java
* <code>short</code> value in the same manner used by the
* <code>writeShort</code> method. Note that this is the number of
* bytes in the
* encoded <code>String</code> not the <code>String</code> length. Next
* come the encoded characters. Each character in the <code>String</code>
* is encoded as either one, two or three bytes. For characters in the
* range of <code>\u0001</code> to <code>\u007F</code>, one byte is used.
* The character
* value goes into bits 0-7 and bit eight is 0. For characters in the range
* of <code>\u0080</code> to <code>\u007FF</code>, two bytes are used. Bits
* 6-10 of the character value are encoded bits 0-4 of the first byte, with
* the high bytes having a value of "110". Bits 0-5 of the character value
* are stored in bits 0-5 of the second byte, with the high bits set to
* "10". This type of encoding is also done for the null character
* <code>\u0000</code>. This eliminates any C style NUL character values
* in the output. All remaining characters are stored as three bytes.
* Bits 12-15 of the character value are stored in bits 0-3 of the first
* byte. The high bits of the first bytes are set to "1110". Bits 6-11
* of the character value are stored in bits 0-5 of the second byte. The
* high bits of the second byte are set to "10". And bits 0-5 of the
* character value are stored in bits 0-5 of byte three, with the high bits
* of that byte set to "10".
*
* The value written can be read using the <code>readUTF</code>
* method in <code>DataInput</code>.
*
* @param value The <code>String</code> to write
*
* @exception IOException If an error occurs
*
* @see DataInput#readUTF
*/
void writeUTF(String value) throws IOException;
/**
* This method writes an 8-bit value (passed into the method as a Java
* <code>int</code>) to an output stream. The low 8 bits of the
* passed value are written.
*
* @param value The <code>byte</code> 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 <code>buf</code>
* starting
* <code>offset</code> bytes into the buffer. The number of bytes
* written will be exactly <code>len</code>.
*
* @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
1.1 jop/java/target/src/jdk11/java/io/DataOutputStream.java
http://www.opencores.org/cvsweb.shtml/jop/java/target/src/jdk11/java/io/DataOutputStream.java?rev=1.1&content-type=text/x-cvsweb-markup
Index: DataOutputStream.java
===================================================================
/* DataOutputStream.java -- Writes primitive Java datatypes to streams
Copyright (C) 1998, 2001, 2003, 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
* Status: Complete to version 1.1.
*/
/**
* This class provides a mechanism for writing primitive Java datatypes
* to an <code>OutputStream</code> in a portable way. Data written to
* a stream using this class can be read back in using the
* <code>DataInputStream</code> class on any platform.
*
* @see DataInputStream
*
* @author Aaron M. Renn (arenn@u...)
* @author Tom Tromey (tromey@c...)
*/
public class DataOutputStream extends OutputStream implements DataOutput
{
OutputStream out;
/**
* This is the total number of bytes that have been written to the
* stream by this object instance.
*/
protected int written;
/**
* Utf8 byte buffer, used by writeUTF()
*/
private byte[] buf;
/**
* This method initializes an instance of <code>DataOutputStream</code> to
* write its data to the specified underlying <code>OutputStream</code>
*
* @param out The subordinate <code>OutputStream</code> to which this
* object will write
*/
public DataOutputStream (OutputStream out)
{
this.out = out;
written = 0;
}
/**
* This method flushes any unwritten bytes to the underlying stream.
*
* @exception IOException If an error occurs.
*/
public void flush () throws IOException
{
out.flush();
}
/**
* This method writes the specified byte (passed as an <code>int</code>)
* to the underlying output stream.
*
* @param value The <code>byte</code> to write, passed as an <code>int</code>.
*
* @exception IOException If an error occurs.
*/
public synchronized void write (int value) throws IOException
{
out.write (value);
++written;
}
/**
* This method writes <code>len</code> bytes from the specified byte array
* <code>buf</code> starting at position <code>offset</code> into the
* buffer to the underlying output stream.
*
* @param buf The byte array to write from.
* @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
{
out.write(buf, offset, len);
written += len;
}
/**
* This method writes a Java boolean value to an output stream. If
* <code>value</code> is <code>true</code>, a byte with the value of
* 1 will be written, otherwise a byte with the value of 0 will be
* written.
*
* The value written can be read using the <code>readBoolean</code>
* method in <code>DataInput</code>.
*
* @param value The <code>boolean</code> value to write to the stream
*
* @exception IOException If an error occurs
*
* @see DataInput#readBoolean
*/
public final void writeBoolean (boolean value) throws IOException
{
write (value ? 1 : 0);
}
/**
* This method writes a Java byte value to an output stream. The
* byte to be written will be in the lowest 8 bits of the
* <code>int</code> value passed.
*
* The value written can be read using the <code>readByte</code> or
* <code>readUnsignedByte</code> methods in <code>DataInput</code>.
*
* @param value The <code>byte</code> to write to the stream, passed as
* the low eight bits of an <code>int</code>.
*
* @exception IOException If an error occurs
*
* @see DataInput#readByte
* @see DataInput#readUnsignedByte
*/
public final void writeByte (int value) throws IOException
{
write (value & 0xff);
}
/**
* This method writes a Java short value to an output stream. The
* char to be written will be in the lowest 16 bits of the <code>int</code>
* value passed. These bytes will be written "big endian". That is,
* with the high byte written first in the following manner:
* <p>
* <code>byte0 = (byte)((value & 0xFF00) >> 8);<br>
* byte1 = (byte)(value & 0x00FF);</code>
* <p>
*
* The value written can be read using the <code>readShort</code> and
* <code>readUnsignedShort</code> methods in <code>DataInput</code>.
*
* @param value The <code>short</code> value to write to the stream,
* passed as an <code>int</code>.
*
* @exception IOException If an error occurs
*
* @see DataInput#readShort
* @see DataInput#readUnsignedShort
*/
public final synchronized void writeShort (int value) throws IOException
{
write ((byte) (0xff & (value >> 8)));
write ((byte) (0xff & value));
}
/**
* This method writes a Java char value to an output stream. The
* char to be written will be in the lowest 16 bits of the <code>int</code>
* value passed. These bytes will be written "big endian". That is,
* with the high byte written first in the following manner:
* <p>
* <code>byte0 = (byte)((value & 0xFF00) >> 8);<br>
* byte1 = (byte)(value & 0x00FF);</code>
* <p>
*
* The value written can be read using the <code>readChar</code>
* method in <code>DataInput</code>.
*
* @param value The <code>char</code> value to write,
* passed as an <code>int</code>.
*
* @exception IOException If an error occurs
*
* @see DataInput#readChar
*/
public final synchronized void writeChar (int value) throws IOException
{
write ((byte) (0xff & (value >> 8)));
write ((byte) (0xff & value));
}
/**
* This method writes a Java int value to an output stream. The 4 bytes
* of the passed value will be written "big endian". That is, with
* the high byte written first in the following manner:
* <p>
* <code>byte0 = (byte)((value & 0xFF000000) >> 24);<br>
* byte1 = (byte)((value & 0x00FF0000) >> 16);<br>
* byte2 = (byte)((value & 0x0000FF00) >> 8);<br>
* byte3 = (byte)(value & 0x000000FF);</code>
* <p>
*
* The value written can be read using the <code>readInt</code>
* method in <code>DataInput</code>.
*
* @param value The <code>int</code> value to write to the stream
*
* @exception IOException If an error occurs
*
* @see DataInput#readInt
*/
public final synchronized void writeInt (int value) throws IOException
{
write ((byte) (0xff & (value >> 24)));
write ((byte) (0xff & (value >> 16)));
write ((byte) (0xff & (value >> 8)));
write ((byte) (0xff & value));
}
/**
* This method writes a Java long value to an output stream. The 8 bytes
* of the passed value will be written "big endian". That is, with
* the high byte written first in the following manner:
* <p>
* <code>byte0 = (byte)((value & 0xFF00000000000000L) >> 56);<br>
* byte1 = (byte)((value & 0x00FF000000000000L) >> 48);<br>
* byte2 = (byte)((value & 0x0000FF0000000000L) >> 40);<br>
* byte3 = (byte)((value & 0x000000FF00000000L) >> 32);<br>
* byte4 = (byte)((value & 0x00000000FF000000L) >> 24);<br>
* byte5 = (byte)((value & 0x0000000000FF0000L) >> 16);<br>
* byte6 = (byte)((value & 0x000000000000FF00L) >> 8);<br>
* byte7 = (byte)(value & 0x00000000000000FFL);</code>
* <p>
*
* The value written can be read using the <code>readLong</code>
* method in <code>DataInput</code>.
*
* @param value The <code>long</code> value to write to the stream
*
* @exception IOException If an error occurs
*
* @see DataInput#readLong
*/
public final synchronized void writeLong (long value) throws IOException
{
write ((byte) (0xff & (value >> 56)));
write ((byte) (0xff & (value>> 48)));
write ((byte) (0xff & (value>> 40)));
write ((byte) (0xff & (value>> 32)));
write ((byte) (0xff & (value>> 24)));
write ((byte) (0xff & (value>> 16)));
write ((byte) (0xff & (value>> 8)));
write ((byte) (0xff & value));
}
/**
* This method writes all the bytes in a <code>String</code> out to the
* stream. One byte is written for each character in the
* <code>String</code>.
* The high eight bits of each character are discarded, thus this
* method is inappropriate for completely representing Unicode characters.
*
* @param value The <code>String</code> to write to the stream
*
* @exception IOException If an error occurs
*/
public final void writeBytes (String value) throws IOException
{
int len = value.length();
for (int i = 0; i < len; ++i)
writeByte (value.charAt(i));
}
/**
* This method writes all the characters of a <code>String</code> to an
* output stream as an array of <code>char</code>'s. Each character
* is written using the method specified in the <code>writeChar</code>
* method.
*
* @param value The <code>String</code> to write to the stream
*
* @exception IOException If an error occurs
*
* @see #writeChar(char)
*/
public final void writeChars (String value) throws IOException
{
int len = value.length();
for (int i = 0; i < len; ++i)
writeChar (value.charAt(i));
}
/**
* This method writes a Java <code>String</code> to the stream in a modified
* UTF-8 format. First, two bytes are written to the stream indicating the
* number of bytes to follow. Note that this is the number of bytes in the
* encoded <code>String</code> not the <code>String</code> length. Next
* come the encoded characters. Each character in the <code>String</code>
* is encoded as either one, two or three bytes. For characters in the
* range of <code>\u0001</code> to <\u007F>, one byte is used. The character
* value goes into bits 0-7 and bit eight is 0. For characters in the range
* of <code>\u0080</code> to <code>\u007FF</code>, two bytes are used. Bits
* 6-10 of the character value are encoded bits 0-4 of the first byte, with
* the high bytes having a value of "110". Bits 0-5 of the character value
* are stored in bits 0-5 of the second byte, with the high bits set to
* "10". This type of encoding is also done for the null character
* <code>\u0000</code>. This eliminates any C style NUL character values
* in the output. All remaining characters are stored as three bytes.
* Bits 12-15 of the character value are stored in bits 0-3 of the first
* byte. The high bits of the first bytes are set to "1110". Bits 6-11
* of the character value are stored in bits 0-5 of the second byte. The
* high bits of the second byte are set to "10". And bits 0-5 of the
* character value are stored in bits 0-5 of byte three, with the high bits
* of that byte set to "10".
*
* The value written can be read using the <code>readUTF</code>
* method in <code>DataInput</code>.
*
* @param value The <code>String</code> to write to the output in UTF format
*
* @exception IOException If an error occurs
*
* @see DataInput#readUTF
*/
public final synchronized void writeUTF(String value) throws IOException
{
int len = value.length();
int i = 0;
int pos = 0;
boolean lengthWritten = false;
if (buf == null)
buf = new byte[512];
do
{
while (i < len && pos < buf.length - 3)
{
char c = value.charAt(i++);
if (c >= '\u0001' && c <= '\u007f')
buf[pos++] = (byte) c;
else if (c == '\u0000' || (c >= '\u0080' && c <= '\u07ff'))
{
buf[pos++] = (byte) (0xc0 | (0x1f & (c >> 6)));
buf[pos++] = (byte) (0x80 | (0x3f & c));
}
else
{
// JSL says the first byte should be or'd with 0xc0, but
// that is a typo. Unicode says 0xe0, and that is what is
// consistent with DataInputStream.
buf[pos++] = (byte) (0xe0 | (0x0f & (c >> 12)));
buf[pos++] = (byte) (0x80 | (0x3f & (c >> 6)));
buf[pos++] = (byte) (0x80 | (0x3f & c));
}
}
if (! lengthWritten)
{
if (i == len)
writeShort(pos);
else
writeShort(getUTFlength(value, i, pos));
lengthWritten = true;
}
write(buf, 0, pos);
pos = 0;
}
while (i < len);
}
/**
* Calculate the length, in bytes, of a <code>String</code> in Utf8 format.
*
* @param value The <code>String</code> to measure
* @param start String index at which to begin count
* @param sum Starting Utf8 byte count
*
* @throws UTFDataFormatException if result would exceed 65535
*/
private int getUTFlength(String value, int start, int sum)
throws IOException
{
int len = value.length();
for (int i = start; i < len && sum <= 65535; ++i)
{
char c = value.charAt(i);
if (c >= '\u0001' && c <= '\u007f')
sum += 1;
else if (c == '\u0000' || (c >= '\u0080' && c <= '\u07ff'))
sum += 2;
else
sum += 3;
}
if (sum > 65535)
throw new UTFDataFormatException ();
return sum;
}
} // class DataOutputStream
1.1 jop/java/target/src/jdk11/java/io/EOFException.java
http://www.opencores.org/cvsweb.shtml/jop/java/target/src/jdk11/java/io/EOFException.java?rev=1.1&content-type=text/x-cvsweb-markup
Index: EOFException.java
===================================================================
/* EOFException.java -- unexpected end of file exception
Copyright (C) 1998, 1999, 2001, 2002, 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 exception is thrown when the end of the file or stream was
* encountered unexpectedly. This is not the normal way that an EOF
* condition is reported; such as a special value like -1 being returned.
* However, certain types of streams expecting certain data in a certain
* format might reach EOF before reading their expected data pattern and
* thus throw this exception.
*
* @author Aaron M. Renn (arenn@u...)
* @author Tom Tromey (tromey@c...)
* @status updated to 1.4
*/
public class EOFException extends IOException
{
/**
* Compatible with JDK 1.0+.
*/
private static final long serialVersionUID = 6433858223774886977L;
/**
* Create an exception without a descriptive error message.
*/
public EOFException()
{
}
/**
* Create an exception with a descriptive error message.
*
* @param message the descriptive error message
*/
public EOFException(String message)
{
super(message);
}
} // class EOFException
1.1 jop/java/target/src/jdk11/java/io/InputStreamReader.java
http://www.opencores.org/cvsweb.shtml/jop/java/target/src/jdk11/java/io/InputStreamReader.java?rev=1.1&content-type=text/x-cvsweb-markup
Index: InputStreamReader.java
===================================================================
/* InputStreamReader.java -- Reader than transforms bytes to chars
Copyright (C) 1998, 1999, 2001, 2003, 2004, 2005, 2006
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;
public class InputStreamReader extends Reader {
/**
* The input stream.
*/
private InputStream in;
/**
* java.io canonical name of the encoding.
*/
private String encoding;
/**
* This method initializes a new instance of <code>InputStreamReader</code>
* to read from the specified stream using the default encoding.
*
* @param in
* The <code>InputStream</code> to read from
*/
public InputStreamReader(InputStream in) {
this.in = in;
}
/**
* This method initializes a new instance of <code>InputStreamReader</code>
* to read from the specified stream using a caller supplied character
* encoding scheme. Note that due to a deficiency in the Java language
* design, there is no way to determine which encodings are supported.
*
* @param in
* The <code>InputStream</code> to read from
* @param encoding_name
* The name of the encoding scheme to use
*
* @exception UnsupportedEncodingException
* If the encoding scheme requested is not available.
*/
public InputStreamReader(InputStream in, String encoding_name)
throws UnsupportedEncodingException {
if (!(encoding_name.equals("ASCII") || encoding_name.equals("ascii") || encoding_name
.equals("Ascii"))) {
throw new UnsupportedEncodingException(
"io.InputStreamReader: only ASCII encoding supported");
}
this.in = in;
}
/**
* This method closes this stream, as well as the underlying
* <code>InputStream</code>.
*
* @exception IOException
* If an error occurs
*/
public void close() throws IOException {
synchronized (lock) {
// Makes sure all intermediate data is released by the decoder.
if (in != null)
in.close();
in = null;
}
}
/**
* This method returns the name of the encoding that is currently in use by
* this object. If the stream has been closed, this method is allowed to
* return <code>null</code>.
*
* @return The current encoding name
*/
public String getEncoding() {
return "ASCII";
}
/**
* This method checks to see if the stream is ready to be read. It will
* return <code>true</code> if is, or <code>false</code> if it is not.
* If the stream is not ready to be read, it could (although is not required
* to) block on the next read attempt.
*
* @return <code>true</code> if the stream is ready to be read,
* <code>false</code> otherwise
*
* @exception IOException
* If an error occurs
*/
public boolean ready() throws IOException {
if (in == null)
throw new IOException("Reader has been closed");
return in.available() != 0;
}
/**
* This method reads up to <code>length</code> characters from the stream
* into the specified array starting at index <code>offset</code> into the
* array.
*
* @param buf
* The character array to recieve the data read
* @param offset
* The offset into the array to start storing characters
* @param length
* The requested number of characters to read.
*
* @return The actual number of characters read, or -1 if end of stream.
*
* @exception IOException
* If an error occurs
*/
public int read(char[] buf, int offset, int length) throws IOException {
byte[] bytes = new byte[length];
int read = in.read(bytes);
for (int i = 0; i < read; i++)
buf[offset + i] = (char) (bytes[i] & 0xFF);
return read;
}
/**
* Reads an char from the input stream and returns it as an int in the range
* of 0-65535. This method also will return -1 if the end of the stream has
* been reached.
* <p>
* This method will block until the char can be read.
*
* @return The char read or -1 if end of stream
*
* @exception IOException
* If an error occurs
*/
public int read() throws IOException {
char[] buf = new char[1];
int count = read(buf, 0, 1);
return count > 0 ? buf[0] : -1;
}
/**
* 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.
*
* @param count
* The requested number of chars to skip
*
* @return The actual number of chars skipped.
*
* @exception IOException
* If an error occurs
*/
public long skip(long count) throws IOException {
if (in == null)
throw new IOException("Reader has been closed");
return super.skip(count);
}
}
1.1 jop/java/target/src/jdk11/java/io/InterruptedIOException.java
http://www.opencores.org/cvsweb.shtml/jop/java/target/src/jdk11/java/io/InterruptedIOException.java?rev=1.1&content-type=text/x-cvsweb-markup
Index: InterruptedIOException.ja |