diff options
Diffstat (limited to 'libjava/java/io/FileInputStream.java')
-rw-r--r-- | libjava/java/io/FileInputStream.java | 41 |
1 files changed, 23 insertions, 18 deletions
diff --git a/libjava/java/io/FileInputStream.java b/libjava/java/io/FileInputStream.java index c88f83d..57f6143 100644 --- a/libjava/java/io/FileInputStream.java +++ b/libjava/java/io/FileInputStream.java @@ -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; } |