aboutsummaryrefslogtreecommitdiff
path: root/libjava/java/io/FileInputStream.java
diff options
context:
space:
mode:
authorPer Bothner <bothner@gcc.gnu.org>2004-02-29 11:12:15 -0800
committerPer Bothner <bothner@gcc.gnu.org>2004-02-29 11:12:15 -0800
commitef3916ef8e8a15b800e293ed2555b1b60c9f96f3 (patch)
treedac2f13072b5f9eb856b86bd0a047fabdd09419a /libjava/java/io/FileInputStream.java
parentd5fe0403cc53ebf2b9303d8cb78f305584d02910 (diff)
downloadgcc-ef3916ef8e8a15b800e293ed2555b1b60c9f96f3.zip
gcc-ef3916ef8e8a15b800e293ed2555b1b60c9f96f3.tar.gz
gcc-ef3916ef8e8a15b800e293ed2555b1b60c9f96f3.tar.bz2
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
Diffstat (limited to 'libjava/java/io/FileInputStream.java')
-rw-r--r--libjava/java/io/FileInputStream.java41
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;
}