Commit fddab7dc by Michael Koch Committed by Michael Koch

BufferedOutputStream.java, [...]: More merges from classpath.

2003-03-18  Michael Koch  <konqueror@gmx.de>

	* 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
parent 71a15b15
2003-03-18 Michael Koch <konqueror@gmx.de> 2003-03-18 Michael Koch <konqueror@gmx.de>
* 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 <konqueror@gmx.de>
* configure.in: Fixed links to platform dependant java.net files. * configure.in: Fixed links to platform dependant java.net files.
* configure: Regenerated. * configure: Regenerated.
* java/net/natInetAddress.cc, * java/net/natInetAddress.cc,
......
...@@ -46,189 +46,179 @@ package java.io; ...@@ -46,189 +46,179 @@ package java.io;
* efficient mechanism for writing versus doing numerous small unbuffered * efficient mechanism for writing versus doing numerous small unbuffered
* writes. * writes.
* *
* @version 0.0
*
* @author Aaron M. Renn (arenn@urbanophile.com) * @author Aaron M. Renn (arenn@urbanophile.com)
*/ */
public class BufferedOutputStream extends FilterOutputStream public class BufferedOutputStream extends FilterOutputStream
{ {
/*
/*************************************************************************/ * Class Variables
*/
/*
* Class Variables /**
*/ * This is the default buffer size
*/
/** private static final int DEFAULT_BUFFER_SIZE = 512;
* This is the default buffer size
*/ /*************************************************************************/
private static final int DEFAULT_BUFFER_SIZE = 512;
/*
/*************************************************************************/ * Instance Variables
*/
/*
* Instance Variables /**
*/ * This is the internal byte array used for buffering output before
* writing it.
/** */
* This is the internal byte array used for buffering output before protected byte[] buf;
* 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
* 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 protected int count;
* the index into the buffer where the next byte of data will be stored
*/ /*************************************************************************/
protected int count;
/*
/*************************************************************************/ * Constructors
*/
/*
* Constructors /**
*/ * This method initializes a new <code>BufferedOutputStream</code> instance
* that will write to the specified subordinate <code>OutputStream</code>
/** * and which will use a default buffer size of 512 bytes.
* This method initializes a new <code>BufferedOutputStream</code> instance *
* that will write to the specified subordinate <code>OutputStream</code> * @param out The underlying <code>OutputStream</code> to write data to
* and which will use a default buffer size of 512 bytes. */
* public BufferedOutputStream(OutputStream out)
* @param out The underlying <code>OutputStream</code> to write data to {
*/ this(out, DEFAULT_BUFFER_SIZE);
public }
BufferedOutputStream(OutputStream out)
{ /*************************************************************************/
this(out, DEFAULT_BUFFER_SIZE);
} /**
* This method initializes a new <code>BufferedOutputStream</code> instance
/*************************************************************************/ * that will write to the specified subordinate <code>OutputStream</code>
* and which will use the specified buffer size
/** *
* This method initializes a new <code>BufferedOutputStream</code> instance * @param out The underlying <code>OutputStream</code> to write data to
* that will write to the specified subordinate <code>OutputStream</code> * @param size The size of the internal buffer
* and which will use the specified buffer size */
* public BufferedOutputStream(OutputStream out, int size)
* @param out The underlying <code>OutputStream</code> to write data to {
* @param size The size of the internal buffer super(out);
*/
public buf = new byte[size];
BufferedOutputStream(OutputStream out, int size) }
{
super(out); /*************************************************************************/
buf = new byte[size]; /*
} * Instance Methods
*/
/*************************************************************************/
/**
/* * This method causes any currently buffered bytes to be immediately
* Instance Methods * written to the underlying output stream.
*/ *
* @exception IOException If an error occurs
/** */
* This method causes any currently buffered bytes to be immediately public synchronized void flush() throws IOException
* written to the underlying output stream. {
* if (count == 0)
* @exception IOException If an error occurs 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 * This method runs when the object is garbage collected. It is
* buffer instead of the underlying data source. However, if the buffer * responsible for ensuring that all buffered bytes are written and
* is filled as a result of this write request, it will be flushed to the * for closing the underlying stream.
* underlying output stream. *
* * @exception IOException If an error occurs (ignored by the Java runtime)
* @param b The byte of data to be written, passed as an int *
* protected void finalize() throws IOException
* @exception IOException If an error occurs {
close();
}
*/ */
public synchronized void
write(int b) throws IOException
{
if (count == buf.length)
flush();
buf[count] = (byte)(b & 0xFF);
++count;
}
/*************************************************************************/
/** /*************************************************************************/
* This method writes <code>len</code> bytes from the byte array
* <code>buf</code> starting at position <code>offset</code> in the buffer. /**
* These bytes will be written to the internal buffer. However, if this * This method writes a single byte of data. This will be written to the
* write operation fills the buffer, the buffer will be flushed to the * buffer instead of the underlying data source. However, if the buffer
* underlying output stream. * is filled as a result of this write request, it 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 b The byte of data to be written, passed as an int
* @param len The number of bytes to write. *
* * @exception IOException If an error occurs
* @exception IOException If an error occurs */
*/ public synchronized void write(int b) throws IOException
public synchronized void {
write(byte[] buf, int offset, int len) throws IOException if (count == buf.length)
{
// 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(); flush();
out.write (buf, offset, len);
} buf[count] = (byte)(b & 0xFF);
} ++count;
}
/*************************************************************************/
/**
* This method writes <code>len</code> bytes from the byte array
* <code>buf</code> starting at position <code>offset</code> in the buffer.
* These bytes will be written to the internal buffer. However, if this
* write operation fills the buffer, the buffer will be flushed to the
* underlying output stream.
*
* @param buf The array of bytes to write.
* @param offset The index into the byte array to start writing from.
* @param len The number of bytes to write.
*
* @exception IOException If an error occurs
*/
public synchronized void write(byte[] buf, int offset, int len)
throws IOException
{
// Buffer can hold everything. Note that the case where LEN < 0
// is automatically handled by the downstream write.
if (len < (this.buf.length - count))
{
System.arraycopy(buf, offset, this.buf, count, len);
count += len;
}
else
{
// The write was too big. So flush the buffer and write the new
// bytes directly to the underlying stream, per the JDK 1.2
// docs.
flush();
out.write (buf, offset, len);
}
}
} // class BufferedOutputStream } // class BufferedOutputStream
/* DataInputStream.java -- FilteredInputStream that implements DataInput /* 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. This file is part of GNU Classpath.
...@@ -50,8 +50,6 @@ package java.io; ...@@ -50,8 +50,6 @@ package java.io;
* *
* @see DataInput * @see DataInput
* *
* @version 0.0
*
* @author Warren Levy <warrenl@cygnus.com> * @author Warren Levy <warrenl@cygnus.com>
* @author Aaron M. Renn (arenn@urbanophile.com) * @author Aaron M. Renn (arenn@urbanophile.com)
* @date October 20, 1998. * @date October 20, 1998.
......
...@@ -53,176 +53,165 @@ package java.io; ...@@ -53,176 +53,165 @@ package java.io;
public interface DataOutput public interface DataOutput
{ {
/** /**
* This method writes a Java boolean value to an output stream * This method writes a Java boolean value to an output stream
* *
* @param value The boolean value to write * @param value The boolean value to write
* *
* @exception IOException If an error occurs * @exception IOException If an error occurs
*/ */
void void writeBoolean(boolean value) throws IOException;
writeBoolean(boolean value) throws IOException;
/*************************************************************************/
/*************************************************************************/
/**
/** * This method writes a Java byte value to an output stream
* This method writes a Java byte value to an output stream *
* * @param value The int value to write
* @param value The int value to write *
* * @exception IOException If an error occurs
* @exception IOException If an error occurs */
*/ void writeByte(int value) throws IOException;
void
writeByte(int value) throws IOException; /*************************************************************************/
/*************************************************************************/ /**
* This method writes a Java char value to an output stream
/** *
* This method writes a Java char value to an output stream * @param value The char value to write
* *
* @param value The char value to write * @exception IOException If an error occurs
* */
* @exception IOException If an error occurs void writeChar(int value) throws IOException;
*/
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
* This method writes a Java int value to an output stream as a 16 bit value *
* * @exception IOException If an error occurs
* @param value The int value to write as a 16-bit value */
* void writeShort(int value) throws IOException;
* @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
/** *
* This method writes a Java int value to an output stream * @exception IOException If an error occurs
* */
* @param value The int value to write void writeInt(int value) throws IOException;
*
* @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
* This method writes a Java long value to an output stream */
* void writeLong(long value) throws IOException;
* @param value The long value to write
* /*************************************************************************/
* @exception IOException If an error occurs
*/ /**
void * This method writes a Java float value to an output stream
writeLong(long value) throws IOException; *
* @param value The float value to write
/*************************************************************************/ *
* @exception IOException If an error occurs
/** */
* This method writes a Java float value to an output stream void writeFloat(float value) throws IOException;
*
* @param value The float value to write /*************************************************************************/
*
* @exception IOException If an error occurs /**
*/ * This method writes a Java double value to an output stream
void *
writeFloat(float value) throws IOException; * @param value The double value to write
*
/*************************************************************************/ * @exception IOException If any other error occurs
*/
/** void writeDouble(double 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 * This method writes a String to an output stream as an array of bytes
*/ *
void * @param value The String to write
writeDouble(double value) throws IOException; *
* @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 bytes /*************************************************************************/
*
* @param value The String to write /**
* * This method writes a String to an output stream as an array of char's
* @exception IOException If an error occurs *
*/ * @param value The String to write
void *
writeBytes(String value) throws IOException; * @exception IOException If an error occurs
*/
/*************************************************************************/ void writeChars(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 * This method writes a String to an output stream encoded in
* * UTF-8 format.
* @exception IOException If an error occurs *
*/ * @param value The String to write
void *
writeChars(String value) throws IOException; * @exception IOException If an error occurs
*/
/*************************************************************************/ void writeUTF(String value) throws IOException;
/** /*************************************************************************/
* This method writes a String to an output stream encoded in
* UTF-8 format. /**
* * This method writes an 8-bit value (passed into the method as a Java
* @param value The String to write * int) to an output stream.
* *
* @exception IOException If an error occurs * @param value The byte to write to the output stream
*/ *
void * @exception IOException If an error occurs
writeUTF(String value) throws IOException; */
void write(int value) throws IOException;
/*************************************************************************/
/*************************************************************************/
/**
* This method writes an 8-bit value (passed into the method as a Java /**
* int) to an output stream. * This method writes the raw byte array passed in to the output stream.
* *
* @param value The byte to write to the output stream * @param buf The byte array to write
* *
* @exception IOException If an error occurs * @exception IOException If an error occurs
*/ */
void void write(byte[] buf) throws IOException;
write(int value) throws IOException;
/*************************************************************************/
/*************************************************************************/
/**
/** * This method writes raw bytes from the passed array <code>buf</code>
* This method writes the raw byte array passed in to the output stream. * starting
* * <code>offset</code> bytes into the buffer. The number of bytes
* @param buf The byte array to write * written will be * exactly <code>len</code>.
* *
* @exception IOException If an error occurs * @param buf The buffer from which to write the data
*/ * @param offset The offset into the buffer to start writing data from
void * @param len The number of bytes to write from the buffer to the output
write(byte[] buf) throws IOException; * stream
*
/*************************************************************************/ * @exception IOException If any other error occurs
*/
/** void write(byte[] buf, int offset, int len) 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 } // interface DataOutput
...@@ -56,55 +56,58 @@ package java.io; ...@@ -56,55 +56,58 @@ package java.io;
* created using the default no-argument constructor and the * created using the default no-argument constructor and the
* <code>readExternal</code> method is used to restore the state. * <code>readExternal</code> method is used to restore the state.
* *
* @version 0.0
*
* @author Aaron M. Renn (arenn@urbanophile.com) * @author Aaron M. Renn (arenn@urbanophile.com)
*/ */
public interface Externalizable extends Serializable public interface Externalizable extends Serializable
{ {
static final long serialVersionUID = -282491828744381764L; static final long serialVersionUID = -282491828744381764L;
/** /**
* This method restores an object's state by reading in the instance data * 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 * for the object from the passed in stream. Note that this stream is not
* a subclass of <code>InputStream</code>, but rather is a class that implements * a subclass of <code>InputStream</code>, but rather is a class that
* the <code>ObjectInput</code> interface. That interface provides a mechanism for * implements
* reading in Java data types from a stream. * the <code>ObjectInput</code> interface. That interface provides a
* <p> * mechanism for
* Note that this method must be compatible with <code>writeExternal</code>. * reading in Java data types from a stream.
* It must read back the exact same types that were written by that * <p>
* method in the exact order they were written. * Note that this method must be compatible with <code>writeExternal</code>.
* <p> * It must read back the exact same types that were written by that
* If this method needs to read back an object instance, then the class * method in the exact order they were written.
* for that object must be found and loaded. If that operation fails, * <p>
* then this method throws a <code>ClassNotFoundException</code> * 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,
* @param in An <code>ObjectInput</code> instance for reading in the object state * then this method throws a <code>ClassNotFoundException</code>
* *
* @exception ClassNotFoundException If the class of an object being restored cannot be found * @param in An <code>ObjectInput</code> instance for reading in the object
* @exception IOException If any other error occurs * state
*/ *
public abstract void * @exception ClassNotFoundException If the class of an object being
readExternal(ObjectInput in) throws ClassNotFoundException, IOException; * 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 * 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 * to the passed in stream. Note that this stream is not a subclass of
* <code>OutputStream</code>, but rather is a class that implements the * <code>OutputStream</code>, but rather is a class that implements the
* <code>ObjectOutput</code> interface. That interface provides a number of methods * <code>ObjectOutput</code> interface. That interface provides a
* for writing Java data values to a stream. * number of methods
* <p> * for writing Java data values to a stream.
* Not that the implementation of this method must be coordinated with * <p>
* the implementation of <code>readExternal</code>. * Not that the implementation of this method must be coordinated with
* * the implementation of <code>readExternal</code>.
* @param out An <code>ObjectOutput</code> instance for writing the object state *
* * @param out An <code>ObjectOutput</code> instance for writing the
* @exception IOException If an error occurs * object state
*/ *
public abstract void * @exception IOException If an error occurs
writeExternal(ObjectOutput out) throws IOException; */
public abstract void writeExternal(ObjectOutput out) throws IOException;
} // interface Externalizable } // interface Externalizable
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment