FileDescriptor.java: Implement on top of FileChannel.
* java/io/FileDescriptor.java: Implement on top of FileChannel. Remove native methods. * java/io/natFileDescriptorEcos.cc: Remove file. * java/io/natFileDescriptorPosix.cc: Remove file. * java/io/natFileDescriptorWin32.cc: Remove file. * java/io/FileInputStream.java (ch): Change type to FileChannelImpl. (<init>(File)): Allocate a FileChannelImpl, not a FileDescriptor. (<init>(FileChannelImpl)): New package-private constructor. (<init>(FileDescriptor)): Extract FileChannelImpl from arg. (available, close, read, skip): Implement using FileChannelImpl. (getFD): Allocate FileDescriptor if needed. (getChannel): Is now trivial. * java/io/FileOutputStream.java: Corresponding changes. * java/io/RandomAccessFile.java: Corresponding changes. From-SVN: r78661
This commit is contained in:
parent
d5fe0403cc
commit
ef3916ef8e
7 changed files with 106 additions and 1184 deletions
|
@ -1,5 +1,5 @@
|
|||
/* FileInputStream.java -- An input stream that reads from disk files.
|
||||
Copyright (C) 1998, 2002, 2003 Free Software Foundation, Inc.
|
||||
Copyright (C) 1998, 2002, 2003, 2004 Free Software Foundation, Inc.
|
||||
|
||||
This file is part of GNU Classpath.
|
||||
|
||||
|
@ -39,7 +39,7 @@ exception statement from your version. */
|
|||
package java.io;
|
||||
|
||||
import java.nio.channels.FileChannel;
|
||||
import java.nio.channels.FileChannelImpl;
|
||||
import gnu.java.nio.channels.FileChannelImpl;
|
||||
|
||||
/* Written using "Java Class Libraries", 2nd edition, ISBN 0-201-31002-3
|
||||
* "The Java Language Specification", ISBN 0-201-63451-1
|
||||
|
@ -60,7 +60,7 @@ public class FileInputStream extends InputStream
|
|||
*/
|
||||
private FileDescriptor fd;
|
||||
|
||||
private FileChannel ch; /* cached associated file-channel */
|
||||
private FileChannelImpl ch;
|
||||
|
||||
/**
|
||||
* This method initializes a <code>FileInputStream</code> to read from the
|
||||
|
@ -107,7 +107,7 @@ public class FileInputStream extends InputStream
|
|||
if (file.isDirectory())
|
||||
throw new FileNotFoundException(file.getPath() + " is a directory");
|
||||
|
||||
fd = new FileDescriptor(file.getPath(), FileDescriptor.READ);
|
||||
ch = new FileChannelImpl (file.getPath(), FileChannelImpl.READ);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -133,6 +133,12 @@ public class FileInputStream extends InputStream
|
|||
s.checkRead(fdObj);
|
||||
|
||||
fd = fdObj;
|
||||
ch = (FileChannelImpl) fdObj.channel;
|
||||
}
|
||||
|
||||
FileInputStream(FileChannelImpl ch)
|
||||
{
|
||||
this.ch = ch;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -156,7 +162,7 @@ public class FileInputStream extends InputStream
|
|||
*/
|
||||
public int available() throws IOException
|
||||
{
|
||||
return fd.available();
|
||||
return ch.available();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -168,8 +174,7 @@ public class FileInputStream extends InputStream
|
|||
*/
|
||||
public void close() throws IOException
|
||||
{
|
||||
if (fd.valid())
|
||||
fd.close();
|
||||
ch.close();
|
||||
}
|
||||
|
||||
protected void finalize() throws IOException
|
||||
|
@ -189,9 +194,12 @@ public class FileInputStream extends InputStream
|
|||
*/
|
||||
public final FileDescriptor getFD() throws IOException
|
||||
{
|
||||
if (!fd.valid())
|
||||
throw new IOException();
|
||||
return fd;
|
||||
synchronized (this)
|
||||
{
|
||||
if (fd == null)
|
||||
fd = new FileDescriptor (ch);
|
||||
return fd;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -207,7 +215,7 @@ public class FileInputStream extends InputStream
|
|||
*/
|
||||
public int read() throws IOException
|
||||
{
|
||||
return fd.read();
|
||||
return ch.read();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -258,7 +266,7 @@ public class FileInputStream extends InputStream
|
|||
|| offset + len > buf.length)
|
||||
throw new ArrayIndexOutOfBoundsException();
|
||||
|
||||
return fd.read(buf, offset, len);
|
||||
return ch.read(buf, offset, len);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -281,9 +289,9 @@ public class FileInputStream extends InputStream
|
|||
if (numBytes == 0)
|
||||
return 0;
|
||||
|
||||
long curPos = fd.getFilePointer ();
|
||||
long newPos = fd.seek (numBytes, FileDescriptor.CUR, true);
|
||||
return newPos - curPos;
|
||||
long oldPos = ch.position ();
|
||||
ch.position(oldPos + numBytes);
|
||||
return ch.position() - oldPos;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -294,9 +302,6 @@ public class FileInputStream extends InputStream
|
|||
*/
|
||||
public synchronized FileChannel getChannel ()
|
||||
{
|
||||
if (ch == null)
|
||||
ch = new FileChannelImpl (fd, false, this);
|
||||
|
||||
return ch;
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue