diff options
author | Michael Koch <konqueror@gmx.de> | 2003-03-24 07:27:52 +0000 |
---|---|---|
committer | Michael Koch <konqueror@gmx.de> | 2003-03-24 07:27:52 +0000 |
commit | b6ce09b2d5553ee6cbf07dde2251c60dacbe3d54 (patch) | |
tree | 28312849ef36489d2c9747347e19afc25e26ee0e /java/io | |
parent | df97c73a89729323fd997662045edca1c9fcfa3e (diff) | |
download | classpath-b6ce09b2d5553ee6cbf07dde2251c60dacbe3d54.tar.gz |
2003-03-24 Michael Koch <konqueror@gmx.de>
* java/io/DataOutputStream.java:
Reordered methods to match libgcj, reformatting.
(writeBoolean): Replaced if ... else ... with a single line of code.
* java/io/FileInputStream.java:
Reordered methods to match libgcj, reformatting.
* java/io/FileOutputStream.java:
Reordered methods to match libgcj, reformatting.
* java/io/InputStreamReader.java:
Merged copyright years with libgcj.
* java/io/OutputStreamWriter.java:
Merged copyright years with libgcj.
* java/io/RandomAccessFile.java:
Merged copyright years with libgcj.
Diffstat (limited to 'java/io')
-rw-r--r-- | java/io/DataOutputStream.java | 297 | ||||
-rw-r--r-- | java/io/FileInputStream.java | 172 | ||||
-rw-r--r-- | java/io/FileOutputStream.java | 113 | ||||
-rw-r--r-- | java/io/InputStreamReader.java | 2 | ||||
-rw-r--r-- | java/io/OutputStreamWriter.java | 2 | ||||
-rw-r--r-- | java/io/RandomAccessFile.java | 2 |
6 files changed, 301 insertions, 287 deletions
diff --git a/java/io/DataOutputStream.java b/java/io/DataOutputStream.java index 19bf2b879..ed7d02779 100644 --- a/java/io/DataOutputStream.java +++ b/java/io/DataOutputStream.java @@ -38,6 +38,11 @@ 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 @@ -46,7 +51,7 @@ package java.io; * * @see DataInputStream * - * @author Aaron M. Renn (arenn@urbanophile.com) + * @author Aaron M. Renn <arenn@urbanophile.com> * @author Tom Tromey <tromey@cygnus.com> */ public class DataOutputStream extends FilterOutputStream implements DataOutput @@ -97,8 +102,8 @@ public class DataOutputStream extends FilterOutputStream implements DataOutput * This is the total number of bytes that have been written to the * stream by this object instance. */ - protected int written = 0; - + protected int written; + /** * This method initializes an instance of <code>DataOutputStream</code> to * write its data to the specified underlying <code>OutputStream</code> @@ -106,11 +111,22 @@ public class DataOutputStream extends FilterOutputStream implements DataOutput * @param out The subordinate <code>OutputStream</code> to which this * object will write */ - public DataOutputStream(OutputStream out) + public DataOutputStream (OutputStream out) { - super(out); + super (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 returns the total number of bytes that have been written to * the underlying output stream so far. This is the value of the @@ -118,126 +134,105 @@ public class DataOutputStream extends FilterOutputStream implements DataOutput * * @return The number of bytes written to the stream. */ - public final int size() + public final int size () { - return(written); + return written; } - + /** - * This method writes a Java <code>boolean</code> to the underlying output - * stream. For a value of <code>true</code>, 1 is written to the stream. - * For a value of <code>false</code>, 0 is written. + * This method writes the specified byte (passed as an <code>int</code>) + * to the underlying output stream. * - * @param b The <code>boolean</code> value to write to the stream + * @param b The byte to write, passed as an <code>int</code>. * - * @exception IOException If an error occurs + * @exception IOException If an error occurs. */ - public final void writeBoolean(boolean b) throws IOException + public synchronized void write (int b) throws IOException { - if (b) - write(1); - else - write(0); + out.write(b); + ++written; } - + /** - * This method writes a Java <code>byte</code> value to the underlying - * output stream. + * 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 b The <code>byte</code> to write to the stream, passed as - * the low eight bits of an <code>int</code>. + * @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 + * @exception IOException If an error occurs. */ - public final void writeByte(int b) throws IOException + public synchronized void write (byte[] buf, int offset, int len) + throws IOException { - write(b & 0xFF); + out.write(buf, offset, len); + written += len; } - + /** - * 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. + * This method writes a Java <code>boolean</code> to the underlying output + * stream. For a value of <code>true</code>, 1 is written to the stream. + * For a value of <code>false</code>, 0 is written. * - * @param s The <code>String</code> to write to the stream + * @param b The <code>boolean</code> value to write to the stream * * @exception IOException If an error occurs */ - public final void writeBytes(String s) throws IOException + public final void writeBoolean (boolean v) throws IOException { - int len = s.length(); - if (len == 0) - return; - - byte[] buf = new byte[len]; - - for (int i = 0; i < len; i++) - buf[i] = (byte)(s.charAt(i) & 0xFF); - - write(buf, 0, buf.length); + write (v ? 1 : 0); } - + /** - * This method writes a single <code>char</code> value to the stream, - * high byte first. + * This method writes a Java <code>byte</code> value to the underlying + * output stream. * - * @param c The <code>char</code> value to write, - * passed as an <code>int</code>. + * @param b 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 */ - public final synchronized void writeChar(int c) throws IOException + public final void writeByte (int v) throws IOException { - buf[0] = (byte)((c & 0xFF00) >> 8); - buf[1] = (byte)((int)c & 0x00FF); - - write(buf, 0, 2); + write (v & 0xff); } - + /** - * This method writes all the characters in a <code>String</code> to the - * stream. There will be two bytes for each character value. The high - * byte of the character will be written first. + * This method writes a Java <code>short</code> to the stream, high byte + * first. This method requires two bytes to encode the value. * - * @param s The <code>String</code> to write to the stream. + * @param s The <code>short</code> value to write to the stream, + * passed as an <code>int</code>. * * @exception IOException If an error occurs */ - public final void writeChars(String s) throws IOException + public final synchronized void writeShort (int s) throws IOException { - int len = s.length(); - if (len == 0) - return; - - byte[] buf = new byte[len * 2]; - - for (int i = 0; i < len; i++) - { - buf[i * 2] = (byte)((s.charAt(i) & 0xFF00) >> 8); - buf[(i * 2) + 1] = (byte)(s.charAt(i) & 0x00FF); - } + buf[0] = (byte)((s & 0xff00) >> 8); + buf[1] = (byte)(s & 0x00ff); - write(buf, 0, buf.length); + write(buf, 0, 2); } - + /** - * This method writes a Java <code>short</code> to the stream, high byte - * first. This method requires two bytes to encode the value. + * This method writes a single <code>char</code> value to the stream, + * high byte first. * - * @param s The <code>short</code> value to write to the stream, + * @param c The <code>char</code> value to write, * passed as an <code>int</code>. * * @exception IOException If an error occurs */ - public final synchronized void writeShort(int s) throws IOException + public final synchronized void writeChar (int c) throws IOException { - buf[0] = (byte)((s & 0xFF00) >> 8); - buf[1] = (byte)(s & 0x00FF); + buf[0] = (byte)((c & 0xff00) >> 8); + buf[1] = (byte)((int)c & 0x00ff); write(buf, 0, 2); } - + /** * This method writes a Java <code>int</code> to the stream, high bytes * first. This method requires four bytes to encode the value. @@ -246,16 +241,16 @@ public class DataOutputStream extends FilterOutputStream implements DataOutput * * @exception IOException If an error occurs */ - public final synchronized void writeInt(int i) throws IOException + public final synchronized void writeInt (int v) throws IOException { - buf[0] = (byte)((i & 0xFF000000) >> 24); - buf[1] = (byte)((i & 0x00FF0000) >> 16); - buf[2] = (byte)((i & 0x0000FF00) >> 8); - buf[3] = (byte)(i & 0x000000FF); + buf[0] = (byte)((v & 0xff000000) >> 24); + buf[1] = (byte)((v & 0x00ff0000) >> 16); + buf[2] = (byte)((v & 0x0000ff00) >> 8); + buf[3] = (byte)(v & 0x000000ff); write(buf, 0, 4); } - + /** * This method writes a Java <code>long</code> to the stream, high bytes * first. This method requires eight bytes to encode the value. @@ -264,20 +259,20 @@ public class DataOutputStream extends FilterOutputStream implements DataOutput * * @exception IOException If an error occurs */ - public final synchronized void writeLong(long l) throws IOException + public final synchronized void writeLong (long v) throws IOException { - buf[0] = (byte)((l & 0xFF00000000000000L) >> 56); - buf[1] = (byte)((l & 0x00FF000000000000L) >> 48); - buf[2] = (byte)((l & 0x0000FF0000000000L) >> 40); - buf[3] = (byte)((l & 0x000000FF00000000L) >> 32); - buf[4] = (byte)((l & 0x00000000FF000000L) >> 24); - buf[5] = (byte)((l & 0x0000000000FF0000L) >> 16); - buf[6] = (byte)((l & 0x000000000000FF00L) >> 8); - buf[7] = (byte)(l & 0x00000000000000FFL); + buf[0] = (byte)((v & 0xff00000000000000L) >> 56); + buf[1] = (byte)((v & 0x00ff000000000000L) >> 48); + buf[2] = (byte)((v & 0x0000ff0000000000L) >> 40); + buf[3] = (byte)((v & 0x000000ff00000000L) >> 32); + buf[4] = (byte)((v & 0x00000000ff000000L) >> 24); + buf[5] = (byte)((v & 0x0000000000ff0000L) >> 16); + buf[6] = (byte)((v & 0x000000000000ff00L) >> 8); + buf[7] = (byte)(v & 0x00000000000000ffL); write(buf, 0, 8); } - + /** * This method writes a Java <code>float</code> value to the stream. This * value is written by first calling the method @@ -292,14 +287,14 @@ public class DataOutputStream extends FilterOutputStream implements DataOutput * * @see writeInt */ - public final void writeFloat(float f) throws IOException + public final void writeFloat (float v) throws IOException { - writeInt(Float.floatToIntBits(f)); + writeInt (Float.floatToIntBits(v)); } - + /** * This method writes a Java <code>double</code> value to the stream. This - * value is written by first calling the method + * value is written by first calling the method * <code>Double.doubleToLongBits</code> * to retrieve an <code>long</code> representing the floating point number, * then writing this <code>long</code> value to the stream exactly the same @@ -312,11 +307,61 @@ public class DataOutputStream extends FilterOutputStream implements DataOutput * * @see writeLong */ - public final void writeDouble(double d) throws IOException + public final void writeDouble (double v) throws IOException { - writeLong(Double.doubleToLongBits(d)); + writeLong (Double.doubleToLongBits(v)); } + + /** + * 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. + * + * @param s The <code>String</code> to write to the stream + * + * @exception IOException If an error occurs + */ + public final void writeBytes (String s) throws IOException + { + int len = s.length(); + if (len == 0) + return; + + byte[] buf = new byte[len]; + + for (int i = 0; i < len; i++) + buf[i] = (byte)(s.charAt(i) & 0xff); + + write(buf, 0, buf.length); + } + + /** + * This method writes all the characters in a <code>String</code> to the + * stream. There will be two bytes for each character value. The high + * byte of the character will be written first. + * + * @param s The <code>String</code> to write to the stream. + * + * @exception IOException If an error occurs + */ + public final void writeChars (String s) throws IOException + { + int len = s.length(); + if (len == 0) + return; + + byte[] buf = new byte[len * 2]; + for (int i = 0; i < len; i++) + { + buf[i * 2] = (byte)((s.charAt(i) & 0xff00) >> 8); + buf[(i * 2) + 1] = (byte)(s.charAt(i) & 0x00ff); + } + + write(buf, 0, buf.length); + } + /** * 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 @@ -344,60 +389,18 @@ public class DataOutputStream extends FilterOutputStream implements DataOutput * * @exception IOException If an error occurs */ - public synchronized final void writeUTF(String s) throws IOException + public synchronized final void writeUTF (String v) throws IOException { // FIXME: Stylistically, replacing this with s.getBytes("UTF-8") // would be better. However, that's likely to be expensive because of // the char encoder overhead. Maybe we should have an easily // invokable UTF-8 converter function, but I'm not sure this is the // right class for it to live in. - byte[] buf = convertToUTF(s); + byte[] buf = convertToUTF(v); writeShort(buf.length); write(buf, 0, buf.length); } - - /** - * This method writes the specified byte (passed as an <code>int</code>) - * to the underlying output stream. - * - * @param b The byte to write, passed as an <code>int</code>. - * - * @exception IOException If an error occurs. - */ - public synchronized void write(int b) throws IOException - { - out.write(b); - ++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 flushes any unwritten bytes to the underlying stream. - * - * @exception IOException If an error occurs. - */ - public void flush() throws IOException - { - out.flush(); - } - + } // class DataOutputStream diff --git a/java/io/FileInputStream.java b/java/io/FileInputStream.java index 022a51228..1092244a6 100644 --- a/java/io/FileInputStream.java +++ b/java/io/FileInputStream.java @@ -42,40 +42,26 @@ import gnu.classpath.Configuration; import java.nio.channels.FileChannel; import gnu.java.nio.FileChannelImpl; +/* 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 class is a stream that reads its bytes from a file. * - * @author Aaron M. Renn (arenn@urbanophile.com) + * @author Aaron M. Renn <arenn@urbanophile.com> + * @author Warren Levy <warrenl@cygnus.com> */ public class FileInputStream extends InputStream { - private FileChannel ch; /* cached associated file-channel */ - /** * This is the native file handle for the file this stream is reading from */ private FileDescriptor fd; - /** - * This method initializes a <code>FileInputStream</code> to read from the - * specified <code>File</code> object. A security check is first - * made to determine - * whether or not access to this file is allowed. This is done by - * calling the <code>checkRead()</code> method of the - * <code>SecurityManager</code> - * (if one exists) with the name of this file. An exception is thrown - * if reading is not allowed. If the file does not exist, an exception - * is also thrown. - * - * @param file The <code>File</code> object this stream should read from - * - * @exception SecurityException If read access to the file is not allowed - * @exception FileNotFoundException If the file does not exist. - */ - public FileInputStream(File file) throws FileNotFoundException - { - this(file.getPath()); - } + private FileChannel ch; /* cached associated file-channel */ /** * This method initializes a <code>FileInputStream</code> to read from the @@ -94,9 +80,9 @@ public class FileInputStream extends InputStream */ public FileInputStream(String name) throws FileNotFoundException { - SecurityManager sm = System.getSecurityManager(); - if (sm != null) - sm.checkRead(name); + SecurityManager s = System.getSecurityManager(); + if (s != null) + s.checkRead(name); fd = new FileDescriptor(); @@ -112,8 +98,29 @@ public class FileInputStream extends InputStream /** * This method initializes a <code>FileInputStream</code> to read from the - * specified <code>FileDescriptor</code> object. A security - * check is first made to + * specified <code>File</code> object. A security check is first + * made to determine + * whether or not access to this file is allowed. This is done by + * calling the <code>checkRead()</code> method of the + * <code>SecurityManager</code> + * (if one exists) with the name of this file. An exception is thrown + * if reading is not allowed. If the file does not exist, an exception + * is also thrown. + * + * @param file The <code>File</code> object this stream should read from + * + * @exception SecurityException If read access to the file is not allowed + * @exception FileNotFoundException If the file does not exist. + */ + public FileInputStream(File file) throws FileNotFoundException + { + this(file.getPath()); + } + + /** + * This method initializes a <code>FileInputStream</code> to read from the + * specified <code>FileDescriptor</code> object. A security + * check is first made to * determine whether or not access to this file is allowed. This is done by * calling the <code>checkRead()</code> method of the * <code>SecurityManager</code> @@ -126,32 +133,18 @@ public class FileInputStream extends InputStream * * @exception SecurityException If read access to the file is not allowed */ - public FileInputStream(FileDescriptor fd) throws SecurityException + public FileInputStream(FileDescriptor fdObj) { // Hmmm, no other exception but this one to throw, but if the descriptor // isn't valid, we surely don't have "permission" to read from it. - if (!fd.valid()) + if (!fdObj.valid()) throw new SecurityException("Invalid FileDescriptor"); - SecurityManager sm = System.getSecurityManager(); - if (sm != null) - sm.checkRead(fd); + SecurityManager s = System.getSecurityManager(); + if (s != null) + s.checkRead(fdObj); - this.fd = fd; - } - - /** - * This method returns a <code>FileDescriptor</code> object representing the - * underlying native file handle of the file this stream is reading - * from - * - * @return A <code>FileDescriptor</code> for this stream - * - * @exception IOException If an error occurs - */ - public final FileDescriptor getFD() throws IOException - { - return(fd); + this.fd = fdObj; } /** @@ -175,33 +168,33 @@ public class FileInputStream extends InputStream */ public int available() throws IOException { - return(fd.available()); + return fd.available(); } /** - * This method skips the specified number of bytes in the stream. It - * returns the actual number of bytes skipped, which may be less than the - * requested amount. - * <p> - * @param numBytes The requested number of bytes to skip + * This method closes the stream. Any futher attempts to read from the + * stream will likely generate an IOException since the underlying file + * will be closed. * - * @return The actual number of bytes skipped. + * @exception IOException If an error occurs. + */ + public void close() throws IOException + { + fd.close(); + } + + /** + * This method returns a <code>FileDescriptor</code> object representing the + * underlying native file handle of the file this stream is reading + * from + * + * @return A <code>FileDescriptor</code> for this stream * * @exception IOException If an error occurs */ - public synchronized long skip(long numBytes) throws IOException + public final FileDescriptor getFD() throws IOException { - if (numBytes < 0) - throw new IllegalArgumentException("Can't skip negative bytes: " + - numBytes); - - if (numBytes == 0) - return(0); - - long curPos = fd.getFilePointer(); - long newPos = fd.seek(numBytes, fd.CUR, true); - - return(newPos-curPos); + return fd; } /** @@ -217,7 +210,7 @@ public class FileInputStream extends InputStream */ public int read() throws IOException { - return(fd.read()); + return fd.read(); } /** @@ -239,7 +232,7 @@ public class FileInputStream extends InputStream */ public int read(byte[] buf) throws IOException { - return(read(buf, 0, buf.length)); + return read(buf, 0, buf.length); } /** @@ -263,19 +256,36 @@ public class FileInputStream extends InputStream */ public int read(byte[] buf, int offset, int len) throws IOException { - return(fd.read(buf, offset, len)); + if (off < 0 || len < 0 || off + len > b.length) + throw new ArrayIndexOutOfBoundsException(); + + return fd.read(buf, offset, len); } /** - * This method closes the stream. Any futher attempts to read from the - * stream will likely generate an IOException since the underlying file - * will be closed. + * This method skips the specified number of bytes in the stream. It + * returns the actual number of bytes skipped, which may be less than the + * requested amount. + * <p> + * @param numBytes The requested number of bytes to skip * - * @exception IOException If an error occurs. + * @return The actual number of bytes skipped. + * + * @exception IOException If an error occurs */ - public void close() throws IOException + public synchronized long skip(long numBytes) throws IOException { - fd.close(); + if (numBytes < 0) + throw new IllegalArgumentException("Can't skip negative bytes: " + + numBytes); + + if (numBytes == 0) + return(0); + + long curPos = fd.getFilePointer(); + long newPos = fd.seek(numBytes, fd.CUR, true); + + return(newPos-curPos); } /** @@ -284,14 +294,10 @@ 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) - { - // FIXME: Convert NIO to 64 bit - if (ch == null) - ch = new FileChannelImpl ((int) (fd.getNativeFd () & 0xFFFF), this); - } + if (ch == null) + ch = new FileChannelImpl ((int) (fd.getNativeFd () & 0xFFFF), this); return ch; } diff --git a/java/io/FileOutputStream.java b/java/io/FileOutputStream.java index 938c55132..409397f7f 100644 --- a/java/io/FileOutputStream.java +++ b/java/io/FileOutputStream.java @@ -42,12 +42,17 @@ import gnu.classpath.Configuration; import java.nio.channels.FileChannel; import gnu.java.nio.FileChannelImpl; +/* 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 classes allows a stream of data to be written to a disk file or - * any open <code>FileDescriptor</code>. - * - * @author Aaron M. Renn (arenn@urbanophile.com) - */ + * This classes allows a stream of data to be written to a disk file or + * any open <code>FileDescriptor</code>. + * + * @author Aaron M. Renn (arenn@urbanophile.com) + */ public class FileOutputStream extends OutputStream { private FileDescriptor fd; @@ -57,7 +62,9 @@ public class FileOutputStream extends OutputStream /** * This method initializes a <code>FileOutputStream</code> object to write * to the named file. The file is created if it does not exist, and - * the bytes written are written starting at the beginning of the file. + * the bytes written are written starting at the beginning of the file if + * the <code>append</code> argument is <code>false</code> or at the end + * of the file if the <code>append</code> argument is true. * <p> * Before opening a file, a security check is performed by calling the * <code>checkWrite</code> method of the <code>SecurityManager</code> (if @@ -65,45 +72,60 @@ public class FileOutputStream extends OutputStream * thrown if writing is not allowed. * * @param name The name of the file this stream should write to + * @param append <code>true</code> to append bytes to the end of the file, + * or <code>false</code> to write bytes to the beginning * * @exception SecurityException If write access to the file is not allowed * @exception FileNotFoundException If a non-security error occurs */ - public - FileOutputStream(String name) throws SecurityException, FileNotFoundException + public FileOutputStream (String name, boolean append) + throws SecurityException, FileNotFoundException { - this(name, false); + SecurityManager sm = System.getSecurityManager(); + if (sm != null) + sm.checkWrite(name); + + fd = new FileDescriptor(); + + try + { + if (append) + fd.open(name, "a"); + else + fd.open(name, "w"); + } + catch(IOException e) + { + throw new FileNotFoundException(name + ": " + e.getMessage()); + } } /** * This method initializes a <code>FileOutputStream</code> object to write - * to the specified <code>File</code> object. The file is created if it - * does not exist, and the bytes written are written starting at the - * beginning of the file. + * to the named file. The file is created if it does not exist, and + * the bytes written are written starting at the beginning of the file. * <p> * Before opening a file, a security check is performed by calling the * <code>checkWrite</code> method of the <code>SecurityManager</code> (if * one exists) with the name of the file to be opened. An exception is * thrown if writing is not allowed. * - * @param file The <code>File</code> object this stream should write to + * @param name The name of the file this stream should write to * * @exception SecurityException If write access to the file is not allowed * @exception FileNotFoundException If a non-security error occurs */ public - FileOutputStream(File file) throws SecurityException, FileNotFoundException + FileOutputStream(String name) throws SecurityException, FileNotFoundException { - this(file.getPath(), false); + this (name, false); } /** * This method initializes a <code>FileOutputStream</code> object to write * to the specified <code>File</code> object. The file is created if it * does not exist, and the bytes written are written starting at the - * beginning of the file if the <code>append</code> parameter is - * <code>false</code>. Otherwise bytes are written at the end of the - * file. + * beginning of the file. * <p> * Before opening a file, a security check is performed by calling the * <code>checkWrite</code> method of the <code>SecurityManager</code> (if @@ -111,57 +133,40 @@ public class FileOutputStream extends OutputStream * thrown if writing is not allowed. * * @param file The <code>File</code> object this stream should write to - * @param append <code>true</code> to append bytes to the end of the file, - * or <code>false</code> to write bytes to the beginning * * @exception SecurityException If write access to the file is not allowed * @exception FileNotFoundException If a non-security error occurs */ - public - FileOutputStream(File file, boolean append) throws FileNotFoundException + public FileOutputStream (File file) + throws SecurityException, FileNotFoundException { - this(file.getPath(), append); + this (file.getPath(), false); } /** * This method initializes a <code>FileOutputStream</code> object to write - * to the named file. The file is created if it does not exist, and - * the bytes written are written starting at the beginning of the file if - * the <code>append</code> argument is <code>false</code> or at the end - * of the file if the <code>append</code> argument is true. + * to the specified <code>File</code> object. The file is created if it + * does not exist, and the bytes written are written starting at the + * beginning of the file if the <code>append</code> parameter is + * <code>false</code>. Otherwise bytes are written at the end of the + * file. * <p> * Before opening a file, a security check is performed by calling the * <code>checkWrite</code> method of the <code>SecurityManager</code> (if * one exists) with the name of the file to be opened. An exception is * thrown if writing is not allowed. * - * @param name The name of the file this stream should write to + * @param file The <code>File</code> object this stream should write to * @param append <code>true</code> to append bytes to the end of the file, * or <code>false</code> to write bytes to the beginning * * @exception SecurityException If write access to the file is not allowed * @exception FileNotFoundException If a non-security error occurs */ - public FileOutputStream(String name, boolean append) - throws SecurityException, FileNotFoundException + public FileOutputStream (File file, boolean append) + throws FileNotFoundException { - SecurityManager sm = System.getSecurityManager(); - if (sm != null) - sm.checkWrite(name); - - fd = new FileDescriptor(); - - try - { - if (append) - fd.open(name, "a"); - else - fd.open(name, "w"); - } - catch(IOException e) - { - throw new FileNotFoundException(name + ": " + e.getMessage()); - } + this (file.getPath(), append); } /** @@ -180,7 +185,7 @@ public class FileOutputStream extends OutputStream * * @exception SecurityException If write access to the file is not allowed */ - public FileOutputStream(FileDescriptor fd) throws SecurityException + public FileOutputStream (FileDescriptor fd) throws SecurityException { // Hmm, no other exception but this one to throw, but if the descriptor // isn't valid, we surely don't have "permission" to write to it. @@ -204,7 +209,7 @@ public class FileOutputStream extends OutputStream */ public final FileDescriptor getFD() throws IOException { - return(fd); + return fd; } /** @@ -216,7 +221,7 @@ public class FileOutputStream extends OutputStream */ public void write(int b) throws IOException { - fd.write(b); + fd.write (b); } /** @@ -229,7 +234,7 @@ public class FileOutputStream extends OutputStream */ public void write(byte[] buf) throws IOException { - write(buf, 0, buf.length); + write (buf, 0, buf.length); } /** @@ -244,7 +249,7 @@ public class FileOutputStream extends OutputStream */ public void write(byte[] buf, int offset, int len) throws IOException { - fd.write(buf, offset, len); + fd.write (buf, offset, len); } /** @@ -254,9 +259,9 @@ public class FileOutputStream extends OutputStream * * @exception IOException If an error occurs */ - public void close() throws IOException + public void close () throws IOException { - fd.close(); + fd.close (); } /** diff --git a/java/io/InputStreamReader.java b/java/io/InputStreamReader.java index 2398b6aca..2cb89bba4 100644 --- a/java/io/InputStreamReader.java +++ b/java/io/InputStreamReader.java @@ -1,5 +1,5 @@ /* InputStreamReader.java -- Reader than transforms bytes to chars - Copyright (C) 1998 Free Software Foundation, Inc. + Copyright (C) 1998, 1999, 2001, 2003 Free Software Foundation, Inc. This file is part of GNU Classpath. diff --git a/java/io/OutputStreamWriter.java b/java/io/OutputStreamWriter.java index f17083920..f04282d2f 100644 --- a/java/io/OutputStreamWriter.java +++ b/java/io/OutputStreamWriter.java @@ -1,5 +1,5 @@ /* OutputStreamWriter.java -- Writer that converts chars to bytes - Copyright (C) 1998, 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/java/io/RandomAccessFile.java b/java/io/RandomAccessFile.java index 5793ce907..0751f582e 100644 --- a/java/io/RandomAccessFile.java +++ b/java/io/RandomAccessFile.java @@ -1,5 +1,5 @@ /* RandomAccessFile.java -- Class supporting random file I/O - Copyright (C) 1998, 2003 Free Software Foundation, Inc. + Copyright (C) 1998, 1999, 2001, 2002, 2003 Free Software Foundation, Inc. This file is part of GNU Classpath. |