2005-04-29 Dalibor Topic <robilad@kaffe.org>

* java/nio/channels/FileChannelImpl.java
	(FileChannelImpl(String, int)): Removed.
	(FileChannelImpl(File, int)): Added. Check if opened file is a
	directory.
	* java/io/FileInputStream.java(FileInputStream): Fixed javadocs.
	Call FileChannelImpl(File, int).
	* java/io/FileOutputStream.java (FileInputStream): Call
	FileChannelImpl(File, int).
	* java/io/RandomAccessFile.java (RandomAccessFile):
	Call FileChannelImpl(File, int). Switched constructors around.

From-SVN: r99011
This commit is contained in:
Dalibor Topic 2005-04-29 18:47:42 +00:00 committed by Michael Koch
parent 2c80f01549
commit b61ae8b261
5 changed files with 80 additions and 43 deletions

View file

@ -76,7 +76,8 @@ public class FileInputStream extends InputStream
* @param name The name of the file this stream should read from
*
* @exception SecurityException If read access to the file is not allowed
* @exception FileNotFoundException If the file does not exist.
* @exception FileNotFoundException If the file does not exist
* or if it is a directory
*/
public FileInputStream(String name) throws FileNotFoundException
{
@ -97,7 +98,8 @@ public class FileInputStream extends InputStream
* @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.
* @exception FileNotFoundException If the file does not exist
* or if it is a directory.
*/
public FileInputStream(File file) throws FileNotFoundException
{
@ -105,7 +107,7 @@ public class FileInputStream extends InputStream
if (s != null)
s.checkRead(file.getPath());
ch = new FileChannelImpl (file.getPath(), FileChannelImpl.READ);
ch = new FileChannelImpl (file, FileChannelImpl.READ);
}
/**

View file

@ -155,10 +155,10 @@ public class FileOutputStream extends OutputStream
if (s != null)
s.checkWrite(file.getPath());
ch = new FileChannelImpl (file.getPath(), (append
? FileChannelImpl.WRITE
| FileChannelImpl.APPEND
: FileChannelImpl.WRITE));
ch = new FileChannelImpl (file, (append
? FileChannelImpl.WRITE
| FileChannelImpl.APPEND
: FileChannelImpl.WRITE));
}
/**

View file

@ -86,12 +86,46 @@ public class RandomAccessFile implements DataOutput, DataInput
* illegal value
* @exception SecurityException If the requested access to the file
* is not allowed
* @exception IOException If any other error occurs
* @exception FileNotFoundException If the file is a directory, or
* any other error occurs
*/
public RandomAccessFile (File file, String mode)
throws FileNotFoundException
{
this (file.getPath(), mode);
int fdmode;
if (mode.equals("r"))
fdmode = FileChannelImpl.READ;
else if (mode.equals("rw"))
fdmode = FileChannelImpl.READ | FileChannelImpl.WRITE;
else if (mode.equals("rws"))
{
fdmode = (FileChannelImpl.READ | FileChannelImpl.WRITE
| FileChannelImpl.SYNC);
}
else if (mode.equals("rwd"))
{
fdmode = (FileChannelImpl.READ | FileChannelImpl.WRITE
| FileChannelImpl.DSYNC);
}
else
throw new IllegalArgumentException ("invalid mode: " + mode);
final String fileName = file.getPath();
// The obligatory SecurityManager stuff
SecurityManager s = System.getSecurityManager();
if (s != null)
{
s.checkRead(fileName);
if ((fdmode & FileChannelImpl.WRITE) != 0)
s.checkWrite(fileName);
}
ch = new FileChannelImpl (file, fdmode);
fd = new FileDescriptor(ch);
out = new DataOutputStream (new FileOutputStream (fd));
in = new DataInputStream (new FileInputStream (fd));
}
/**
@ -113,43 +147,13 @@ public class RandomAccessFile implements DataOutput, DataInput
* illegal value
* @exception SecurityException If the requested access to the file
* is not allowed
* @exception FileNotFoundException If any other error occurs
* @exception FileNotFoundException If the file is a directory or
* any other error occurs
*/
public RandomAccessFile (String fileName, String mode)
throws FileNotFoundException
{
int fdmode;
if (mode.equals("r"))
fdmode = FileChannelImpl.READ;
else if (mode.equals("rw"))
fdmode = FileChannelImpl.READ | FileChannelImpl.WRITE;
else if (mode.equals("rws"))
{
fdmode = (FileChannelImpl.READ | FileChannelImpl.WRITE
| FileChannelImpl.SYNC);
}
else if (mode.equals("rwd"))
{
fdmode = (FileChannelImpl.READ | FileChannelImpl.WRITE
| FileChannelImpl.DSYNC);
}
else
throw new IllegalArgumentException ("invalid mode: " + mode);
// The obligatory SecurityManager stuff
SecurityManager s = System.getSecurityManager();
if (s != null)
{
s.checkRead(fileName);
if ((fdmode & FileChannelImpl.WRITE) != 0)
s.checkWrite(fileName);
}
ch = new FileChannelImpl (fileName, fdmode);
fd = new FileDescriptor(ch);
out = new DataOutputStream (new FileOutputStream (fd));
in = new DataInputStream (new FileInputStream (fd));
this (new File(fileName), mode);
}
/**