diff --git a/libjava/ChangeLog b/libjava/ChangeLog index 0d230374359..39a86976748 100644 --- a/libjava/ChangeLog +++ b/libjava/ChangeLog @@ -1,3 +1,30 @@ +2003-03-24 Michael Koch + + * java/io/DataOutputStream.java + (write): Merged from classpath. + * java/io/File.java: + Merged copyrigth with classpath. + * java/io/FileInputStream.java + (getChannel): Made it synchronized instead of using a synchronized + block. + * java/io/FileOutputStream.java: Reformatted. + * java/io/InputStreamReader.java + (InputStreamReader): Renamed enc to encoding_name. + (close): Merged documentation from classpath. + (getEncoding): Merged documentation from classpath. + (ready): Merged documentation from classpath. + (read): Merged documentation from classpath. + * java/io/LineNumberReader.java + (lineNumber): Made it private. + (LineNumberReader): Use Constant instead of a direct value. + * java/io/OutputStreamWriter.java + (OutputStreamWriter): Renamed enc to encoding_scheme, merged + documentation from classpath. + (close): Merged documentation from classpath. + (flush): Merged documentation from classpath. + (write): Merged documentation from classpath. + * java/io/PrintStream.java: Reformatted. + 2003-03-24 Michael Koch * javax/swing/text/ComponentView.java diff --git a/libjava/java/io/DataOutputStream.java b/libjava/java/io/DataOutputStream.java index 8fe9bbef962..644b5901c33 100644 --- a/libjava/java/io/DataOutputStream.java +++ b/libjava/java/io/DataOutputStream.java @@ -122,10 +122,10 @@ public class DataOutputStream extends FilterOutputStream implements DataOutput * * @exception IOException If an error occurs. */ - public synchronized void write (byte[] b, int off, int len) - throws IOException, NullPointerException, IndexOutOfBoundsException + public synchronized void write (byte[] buf, int offset, int len) + throws IOException { - out.write(b, off, len); + out.write(buf, offset, len); written += len; } diff --git a/libjava/java/io/File.java b/libjava/java/io/File.java index e0aaaf9063c..eb457b37000 100644 --- a/libjava/java/io/File.java +++ b/libjava/java/io/File.java @@ -1,5 +1,5 @@ /* File.java -- Class representing a file on disk - Copyright (C) 1998, 1999, 2001, 2003 Free Software Foundation, Inc. + Copyright (C) 1998, 1999, 2000, 2001, 2003 Free Software Foundation, Inc. This file is part of GNU Classpath. diff --git a/libjava/java/io/FileInputStream.java b/libjava/java/io/FileInputStream.java index 63390ec0901..533dd080461 100644 --- a/libjava/java/io/FileInputStream.java +++ b/libjava/java/io/FileInputStream.java @@ -280,15 +280,12 @@ public class FileInputStream extends InputStream * A file channel must be created by first creating an instance of * Input/Output/RandomAccessFile and invoking the getChannel() method on it. */ - public FileChannel getChannel () + public synchronized FileChannel getChannel () { - synchronized (this) - { - if (ch == null) - ch = new FileChannelImpl (fd, false, this); + if (ch == null) + ch = new FileChannelImpl (fd, false, this); - return ch; - } + return ch; } } // class FileInputStream diff --git a/libjava/java/io/FileOutputStream.java b/libjava/java/io/FileOutputStream.java index e8a4f08e1ff..ac823616c16 100644 --- a/libjava/java/io/FileOutputStream.java +++ b/libjava/java/io/FileOutputStream.java @@ -41,18 +41,21 @@ package java.io; import java.nio.channels.FileChannel; import gnu.java.nio.FileChannelImpl; -/** - * @author Tom Tromey - * @date September 24, 1998 - */ - /* 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. */ +/** + * @author Tom Tromey + * @date September 24, 1998 + */ public class FileOutputStream extends OutputStream { + // Instance variables. + private FileDescriptor fd; + private FileChannel ch; + public FileOutputStream (String path, boolean append) throws SecurityException, FileNotFoundException { @@ -159,7 +162,4 @@ public class FileOutputStream extends OutputStream } } - // Instance variables. - private FileDescriptor fd; - private FileChannel ch; } diff --git a/libjava/java/io/InputStreamReader.java b/libjava/java/io/InputStreamReader.java index 51ddf76f68c..70213b5f843 100644 --- a/libjava/java/io/InputStreamReader.java +++ b/libjava/java/io/InputStreamReader.java @@ -66,10 +66,10 @@ public class InputStreamReader extends Reader this(in, BytesToUnicode.getDefaultDecoder()); } - public InputStreamReader(InputStream in, String enc) + public InputStreamReader(InputStream in, String encoding_name) throws UnsupportedEncodingException { - this(in, BytesToUnicode.getDecoder(enc)); + this(in, BytesToUnicode.getDecoder(encoding_name)); } private InputStreamReader(InputStream in, BytesToUnicode decoder) @@ -88,6 +88,12 @@ public class InputStreamReader extends Reader converter.setInput(this.in.buf, 0, 0); } + /** + * This method closes this stream, as well as the underlying + * InputStream. + * + * @exception IOException If an error occurs + */ public void close() throws IOException { synchronized (lock) @@ -100,11 +106,29 @@ public class InputStreamReader extends Reader } } + /** + * 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 null. + * + * @param The current encoding name + */ public String getEncoding() { return in != null ? converter.getName() : null; } + /** + * This method checks to see if the stream is read to be read. It + * will return true if is, or false 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 true if the stream is ready to be read, + * false otherwise + * + * @exception IOException If an error occurs + */ public boolean ready() throws IOException { synchronized (lock) @@ -149,6 +173,13 @@ public class InputStreamReader extends Reader } } + /** + * This method reads a single character of data from the stream. + * + * @return The char read, as an int, or -1 if end of stream. + * + * @exception IOException If an error occurs + */ public int read() throws IOException { synchronized (lock) @@ -198,4 +229,6 @@ public class InputStreamReader extends Reader } } } -} + +} // class InputStreamReader + diff --git a/libjava/java/io/LineNumberReader.java b/libjava/java/io/LineNumberReader.java index 73b3b90c11b..9d80745d2fa 100644 --- a/libjava/java/io/LineNumberReader.java +++ b/libjava/java/io/LineNumberReader.java @@ -70,7 +70,7 @@ package java.io; public class LineNumberReader extends BufferedReader { /** The current line number. */ - int lineNumber; + private int lineNumber; /** * Create a new LineNumberReader that reads from the @@ -81,7 +81,7 @@ public class LineNumberReader extends BufferedReader */ public LineNumberReader(Reader in) { - super(in, 8192); + super(in, DEFAULT_BUFFER_SIZE); } /** diff --git a/libjava/java/io/OutputStreamWriter.java b/libjava/java/io/OutputStreamWriter.java index a284542d44a..1d63d5650d1 100644 --- a/libjava/java/io/OutputStreamWriter.java +++ b/libjava/java/io/OutputStreamWriter.java @@ -57,11 +57,6 @@ public class OutputStreamWriter extends Writer private char[] work; private int wcount; - public String getEncoding() - { - return out != null ? converter.getName() : null; - } - private OutputStreamWriter(OutputStream out, UnicodeToBytes encoder) { this.out = out instanceof BufferedOutputStream @@ -72,17 +67,29 @@ public class OutputStreamWriter extends Writer this.converter = encoder; } - public OutputStreamWriter(OutputStream out, String enc) + public OutputStreamWriter(OutputStream out, String encoding_scheme) throws UnsupportedEncodingException { - this(out, UnicodeToBytes.getEncoder(enc)); + this(out, UnicodeToBytes.getEncoder(encoding_scheme)); } + /** + * This method initializes a new instance of OutputStreamWriter + * to write to the specified stream using the default encoding. + * + * @param out The OutputStream to write to + */ public OutputStreamWriter(OutputStream out) { this(out, UnicodeToBytes.getDefaultEncoder()); } + /** + * This method closes this stream, and the underlying + * OutputStream + * + * @exception IOException If an error occurs + */ public void close() throws IOException { synchronized (lock) @@ -97,6 +104,23 @@ public class OutputStreamWriter extends Writer } } + /** + * This method returns the name of the character encoding scheme currently + * in use by this stream. If the stream has been closed, then this method + * may return null. + * + * @return The encoding scheme name + */ + public String getEncoding() + { + return out != null ? converter.getName() : null; + } + + /** + * This method flushes any buffered bytes to the underlying output sink. + * + * @exception IOException If an error occurs + */ public void flush() throws IOException { synchronized (lock) @@ -186,6 +210,13 @@ public class OutputStreamWriter extends Writer } } + /** + * This method writes a single character to the output stream. + * + * @param c The char to write, passed as an int. + * + * @exception IOException If an error occurs + */ public void write(int ch) throws IOException { synchronized (lock) @@ -203,4 +234,6 @@ public class OutputStreamWriter extends Writer work[wcount++] = (char) ch; } } -} + +} // class OutputStreamWriter + diff --git a/libjava/java/io/PrintStream.java b/libjava/java/io/PrintStream.java index 3101bb5dea2..8fc1cb831aa 100644 --- a/libjava/java/io/PrintStream.java +++ b/libjava/java/io/PrintStream.java @@ -55,12 +55,30 @@ public class PrintStream extends FilterOutputStream * This leads to some minor duplication, because neither inherits * from the other, and we want to maximize performance. */ + public PrintStream (OutputStream out) + { + this(out, false); + } + + public PrintStream (OutputStream out, boolean auto_flush) + { + super(out); + converter = UnicodeToBytes.getDefaultEncoder(); + error = false; + this.auto_flush = auto_flush; + } + public boolean checkError () { flush(); return error; } + protected void setError () + { + error = true; + } + public void close () { try @@ -258,24 +276,6 @@ public class PrintStream extends FilterOutputStream print(charArray, 0, charArray.length, true); } - public PrintStream (OutputStream out) - { - this(out, false); - } - - public PrintStream (OutputStream out, boolean af) - { - super(out); - converter = UnicodeToBytes.getDefaultEncoder(); - error = false; - auto_flush = af; - } - - protected void setError () - { - error = true; - } - public void write (int oneByte) { try