Commit 01312d12 by Michael Koch Committed by Michael Koch

File.java: Import needed classes instead of whole packages...

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

	* java/io/File.java:
	Import needed classes instead of whole packages, merged class
	documentation with classpath, moved constants and variables to top of
	class.
	* java/io/PrintStream.java:
	Merged class documentation with classpath, moved constants and
	variables to top of class.
	* java/io/RandomAccessFile.java
	(RandomAccessFile): Merged with classpath.
	(read): Merged with classpath).
	(read*): Reformatted.

From-SVN: r64974
parent bcfaead0
2003-03-28 Michael Koch <konqueror@gmx.de> 2003-03-28 Michael Koch <konqueror@gmx.de>
* java/io/File.java:
Import needed classes instead of whole packages, merged class
documentation with classpath, moved constants and variables to top of
class.
* java/io/PrintStream.java:
Merged class documentation with classpath, moved constants and
variables to top of class.
* java/io/RandomAccessFile.java
(RandomAccessFile): Merged with classpath.
(read): Merged with classpath).
(read*): Reformatted.
2003-03-28 Michael Koch <konqueror@gmx.de>
* java/io/FileDescriptor.java * java/io/FileDescriptor.java
(finalize): Throws Throwable, not IOException. (finalize): Throws Throwable, not IOException.
* java/io/ObjectOutputStream.java * java/io/ObjectOutputStream.java
......
...@@ -38,22 +38,49 @@ exception statement from your version. */ ...@@ -38,22 +38,49 @@ exception statement from your version. */
package java.io; package java.io;
import java.util.*; import java.net.MalformedURLException;
import java.net.*; import java.net.URL;
import gnu.gcj.runtime.FileDeleter; import gnu.gcj.runtime.FileDeleter;
/**
* @author Tom Tromey <tromey@cygnus.com>
* @date September 24, 1998
*/
/* Written using "Java Class Libraries", 2nd edition, ISBN 0-201-31002-3 /* Written using "Java Class Libraries", 2nd edition, ISBN 0-201-31002-3
* "The Java Language Specification", ISBN 0-201-63451-1 * "The Java Language Specification", ISBN 0-201-63451-1
* Status: Complete to version 1.3. * Status: Complete to version 1.3.
*/ */
/**
* This class represents a file or directory on a local disk. It provides
* facilities for dealing with a variety of systems that use various
* types of path separators ("/" versus "\", for example). It also
* contains method useful for creating and deleting files and directories.
*
* @author Aaron M. Renn <arenn@urbanophile.com>
* @author Tom Tromey <tromey@cygnus.com>
*/
public class File implements Serializable, Comparable public class File implements Serializable, Comparable
{ {
private static final long serialVersionUID = 301077366599181567L;
// QUERY arguments to access function.
private final static int READ = 0;
private final static int WRITE = 1;
private final static int EXISTS = 2;
// QUERY arguments to stat function.
private final static int DIRECTORY = 0;
private final static int ISFILE = 1;
private final static int ISHIDDEN = 2;
// QUERY arguments to attr function.
private final static int MODIFIED = 0;
private final static int LENGTH = 1;
private final native long attr (int query);
// On OSF1 V5.0, `stat' is a macro. It is easiest to use the name
// `_stat' instead. We do the same thing for `_access' just in
// case.
private final native boolean _access (int query);
private final native boolean _stat (int query);
public boolean canRead () public boolean canRead ()
{ {
checkRead(); checkRead();
...@@ -612,26 +639,4 @@ public class File implements Serializable, Comparable ...@@ -612,26 +639,4 @@ public class File implements Serializable, Comparable
path = path.replace (oldSeparatorChar, separatorChar); path = path.replace (oldSeparatorChar, separatorChar);
} }
// QUERY arguments to access function.
private final static int READ = 0;
private final static int WRITE = 1;
private final static int EXISTS = 2;
// QUERY arguments to stat function.
private final static int DIRECTORY = 0;
private final static int ISFILE = 1;
private final static int ISHIDDEN = 2;
// QUERY arguments to attr function.
private final static int MODIFIED = 0;
private final static int LENGTH = 1;
private final native long attr (int query);
// On OSF1 V5.0, `stat' is a macro. It is easiest to use the name
// `_stat' instead. We do the same thing for `_access' just in
// case.
private final native boolean _access (int query);
private final native boolean _stat (int query);
private static final long serialVersionUID = 301077366599181567L;
} }
...@@ -37,24 +37,55 @@ exception statement from your version. */ ...@@ -37,24 +37,55 @@ exception statement from your version. */
package java.io; package java.io;
import gnu.gcj.convert.UnicodeToBytes;
/** import gnu.gcj.convert.UnicodeToBytes;
* @author Tom Tromey <tromey@cygnus.com>
* @date September 24, 1998
*/
/* Written using "Java Class Libraries", 2nd edition, ISBN 0-201-31002-3 /* Written using "Java Class Libraries", 2nd edition, ISBN 0-201-31002-3
* "The Java Language Specification", ISBN 0-201-63451-1 * "The Java Language Specification", ISBN 0-201-63451-1
* Status: Believed complete and correct to 1.3 * Status: Believed complete and correct to 1.3
*/ */
/**
* This class prints Java primitive values and object to a stream as
* text. None of the methods in this class throw an exception. However,
* errors can be detected by calling the <code>checkError()</code> method.
* Additionally, this stream can be designated as "autoflush" when
* created so that any writes are automatically flushed to the underlying
* output sink when the current line is terminated.
* <p>
* <b>Note that this class is deprecated</b>. It exists for backward
* compatibility only. New code should be written to use
* <code>PrintWriter</code> instead.
* <p>
* This class converts char's into byte's using the system default encoding.
*
* @deprecated
*
* @author Aaron M. Renn <arenn@urbanophile.com>
* @author Tom Tromey <tromey@cygnus.com>
*/
public class PrintStream extends FilterOutputStream public class PrintStream extends FilterOutputStream
{ {
/* Notice the implementation is quite similar to OutputStreamWriter. /* Notice the implementation is quite similar to OutputStreamWriter.
* This leads to some minor duplication, because neither inherits * This leads to some minor duplication, because neither inherits
* from the other, and we want to maximize performance. */ * from the other, and we want to maximize performance. */
// Line separator string.
private static final char[] line_separator
= System.getProperty("line.separator").toCharArray();
UnicodeToBytes converter;
// Work buffer of characters for converter.
char[] work = new char[100];
// Work buffer of bytes where we temporarily keep converter output.
byte[] work_bytes = new byte[100];
// True if error occurred.
private boolean error;
// True if auto-flush.
private boolean auto_flush;
public PrintStream (OutputStream out) public PrintStream (OutputStream out)
{ {
this(out, false); this(out, false);
...@@ -312,19 +343,4 @@ public class PrintStream extends FilterOutputStream ...@@ -312,19 +343,4 @@ public class PrintStream extends FilterOutputStream
} }
} }
UnicodeToBytes converter;
// Work buffer of characters for converter.
char[] work = new char[100];
// Work buffer of bytes where we temporarily keep converter output.
byte[] work_bytes = new byte[100];
// True if error occurred.
private boolean error;
// True if auto-flush.
private boolean auto_flush;
// Line separator string.
private static final char[] line_separator
= System.getProperty("line.separator").toCharArray();
} }
...@@ -87,7 +87,8 @@ public class RandomAccessFile implements DataOutput, DataInput ...@@ -87,7 +87,8 @@ public class RandomAccessFile implements DataOutput, DataInput
* is not allowed * is not allowed
* @exception IOException If any other error occurs * @exception IOException If any other error occurs
*/ */
public RandomAccessFile (File file, String mode) throws FileNotFoundException public RandomAccessFile (File file, String mode)
throws FileNotFoundException
{ {
this (file.getPath(), mode); this (file.getPath(), mode);
} }
...@@ -102,7 +103,7 @@ public class RandomAccessFile implements DataOutput, DataInput ...@@ -102,7 +103,7 @@ public class RandomAccessFile implements DataOutput, DataInput
* opening the file to determine whether or not this file is allowed to * opening the file to determine whether or not this file is allowed to
* be read or written. * be read or written.
* *
* @param name The name of the file to read and/or write * @param fileName The name of the file to read and/or write
* @param mode "r" for read only or "rw" for read-write access to the file * @param mode "r" for read only or "rw" for read-write access to the file
* *
* @exception IllegalArgumentException If <code>mode</code> has an * @exception IllegalArgumentException If <code>mode</code> has an
...@@ -114,6 +115,11 @@ public class RandomAccessFile implements DataOutput, DataInput ...@@ -114,6 +115,11 @@ public class RandomAccessFile implements DataOutput, DataInput
public RandomAccessFile (String fileName, String mode) public RandomAccessFile (String fileName, String mode)
throws FileNotFoundException throws FileNotFoundException
{ {
// Check the mode
if (!mode.equals("r") && !mode.equals("rw") && !mode.equals("rws") &&
!mode.equals("rwd"))
throw new IllegalArgumentException("Bad mode value: " + mode);
int fdmode; int fdmode;
if (mode.compareTo ("r") == 0) if (mode.compareTo ("r") == 0)
fdmode = FileDescriptor.READ; fdmode = FileDescriptor.READ;
...@@ -122,12 +128,14 @@ public class RandomAccessFile implements DataOutput, DataInput ...@@ -122,12 +128,14 @@ public class RandomAccessFile implements DataOutput, DataInput
else else
throw new IllegalArgumentException ("invalid mode: " + mode); throw new IllegalArgumentException ("invalid mode: " + mode);
// The obligatory SecurityManager stuff
SecurityManager s = System.getSecurityManager(); SecurityManager s = System.getSecurityManager();
if (s != null) if (s != null)
{ {
s.checkRead(fileName); s.checkRead(fileName);
if ((fdmode & FileDescriptor.WRITE) != 0)
s.checkWrite(fileName); if ((fdmode & FileDescriptor.WRITE) != 0)
s.checkWrite(fileName);
} }
fd = new FileDescriptor (fileName, fdmode); fd = new FileDescriptor (fileName, fdmode);
...@@ -159,6 +167,7 @@ public class RandomAccessFile implements DataOutput, DataInput ...@@ -159,6 +167,7 @@ public class RandomAccessFile implements DataOutput, DataInput
{ {
if (! fd.valid()) if (! fd.valid())
throw new IOException (); throw new IOException ();
return fd; return fd;
} }
...@@ -231,12 +240,12 @@ public class RandomAccessFile implements DataOutput, DataInput ...@@ -231,12 +240,12 @@ public class RandomAccessFile implements DataOutput, DataInput
*/ */
public int read (byte[] buffer) throws IOException public int read (byte[] buffer) throws IOException
{ {
return in.read(buffer); return in.read (buffer);
} }
/** /**
* This methods reads up to <code>len</code> bytes from the file into the s * This methods reads up to <code>len</code> bytes from the file into the
* pecified array starting at position <code>offset</code> into the array. * specified array starting at position <code>offset</code> into the array.
* *
* @param buf The array to read the bytes into * @param buf The array to read the bytes into
* @param offset The index into the array to start storing bytes * @param offset The index into the array to start storing bytes
...@@ -246,9 +255,9 @@ public class RandomAccessFile implements DataOutput, DataInput ...@@ -246,9 +255,9 @@ public class RandomAccessFile implements DataOutput, DataInput
* *
* @exception IOException If an error occurs * @exception IOException If an error occurs
*/ */
public int read (byte[] buffer, int offset, int count) throws IOException public int read (byte[] buffer, int offset, int len) throws IOException
{ {
return in.read(buffer, offset, count); return in.read (buffer, offset, len);
} }
/** /**
...@@ -270,7 +279,7 @@ public class RandomAccessFile implements DataOutput, DataInput ...@@ -270,7 +279,7 @@ public class RandomAccessFile implements DataOutput, DataInput
*/ */
public final boolean readBoolean () throws IOException public final boolean readBoolean () throws IOException
{ {
return in.readBoolean(); return in.readBoolean ();
} }
/** /**
...@@ -290,7 +299,7 @@ public class RandomAccessFile implements DataOutput, DataInput ...@@ -290,7 +299,7 @@ public class RandomAccessFile implements DataOutput, DataInput
*/ */
public final byte readByte () throws IOException public final byte readByte () throws IOException
{ {
return in.readByte(); return in.readByte ();
} }
/** /**
...@@ -347,7 +356,7 @@ public class RandomAccessFile implements DataOutput, DataInput ...@@ -347,7 +356,7 @@ public class RandomAccessFile implements DataOutput, DataInput
*/ */
public final double readDouble () throws IOException public final double readDouble () throws IOException
{ {
return in.readDouble(); return in.readDouble ();
} }
/** /**
...@@ -412,7 +421,7 @@ public class RandomAccessFile implements DataOutput, DataInput ...@@ -412,7 +421,7 @@ public class RandomAccessFile implements DataOutput, DataInput
public final void readFully (byte[] buffer, int offset, int count) public final void readFully (byte[] buffer, int offset, int count)
throws IOException throws IOException
{ {
in.readFully(buffer, offset, count); in.readFully (buffer, offset, count);
} }
/** /**
...@@ -477,7 +486,7 @@ public class RandomAccessFile implements DataOutput, DataInput ...@@ -477,7 +486,7 @@ public class RandomAccessFile implements DataOutput, DataInput
*/ */
public final String readLine () throws IOException public final String readLine () throws IOException
{ {
return in.readLine(); return in.readLine ();
} }
/** /**
......
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