aboutsummaryrefslogtreecommitdiff
path: root/libjava/java/io/FileOutputStream.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/FileOutputStream.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/FileOutputStream.java')
-rw-r--r--libjava/java/io/FileOutputStream.java39
1 files changed, 22 insertions, 17 deletions
diff --git a/libjava/java/io/FileOutputStream.java b/libjava/java/io/FileOutputStream.java
index f0d34e3..a8c4b76 100644
--- a/libjava/java/io/FileOutputStream.java
+++ b/libjava/java/io/FileOutputStream.java
@@ -1,5 +1,5 @@
/* FileOutputStream.java -- Writes to a file on disk.
- Copyright (C) 1998, 2001, 2003 Free Software Foundation, Inc.
+ Copyright (C) 1998, 2001, 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
@@ -57,7 +57,7 @@ public class FileOutputStream extends OutputStream
{
private FileDescriptor fd;
- private FileChannel ch; /* cached associated file-channel */
+ private FileChannelImpl ch;
/**
* This method initializes a <code>FileOutputStream</code> object to write
@@ -84,10 +84,10 @@ public class FileOutputStream extends OutputStream
SecurityManager s = System.getSecurityManager();
if (s != null)
s.checkWrite(path);
- fd = new FileDescriptor (path, (append
- ? FileDescriptor.WRITE
- | FileDescriptor.APPEND
- : FileDescriptor.WRITE));
+ ch = new FileChannelImpl (path, (append
+ ? FileChannelImpl.WRITE
+ | FileChannelImpl.APPEND
+ : FileChannelImpl.WRITE));
}
/**
@@ -188,6 +188,12 @@ public class FileOutputStream extends OutputStream
s.checkWrite(fdObj);
fd = fdObj;
+ ch = (FileChannelImpl) fdObj.channel;
+ }
+
+ FileOutputStream(FileChannelImpl ch)
+ {
+ this.ch = ch;
}
protected void finalize () throws IOException
@@ -206,9 +212,12 @@ public class FileOutputStream extends OutputStream
*/
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;
+ }
}
/**
@@ -220,7 +229,7 @@ public class FileOutputStream extends OutputStream
*/
public void write (int b) throws IOException
{
- fd.write (b);
+ ch.write (b);
}
/**
@@ -255,7 +264,7 @@ public class FileOutputStream extends OutputStream
|| offset + len > buf.length)
throw new ArrayIndexOutOfBoundsException ();
- fd.write (buf, offset, len);
+ ch.write (buf, offset, len);
}
/**
@@ -267,8 +276,7 @@ public class FileOutputStream extends OutputStream
*/
public void close () throws IOException
{
- if (fd.valid())
- fd.close();
+ ch.close();
}
/**
@@ -279,9 +287,6 @@ public class FileOutputStream extends OutputStream
*/
public synchronized FileChannel getChannel()
{
- if (ch == null)
- ch = new FileChannelImpl (fd, true, this);
-
return ch;
}