summaryrefslogtreecommitdiffstats
path: root/libjava/gnu/java/nio/FileChannelImpl.java
diff options
context:
space:
mode:
Diffstat (limited to 'libjava/gnu/java/nio/FileChannelImpl.java')
-rw-r--r--libjava/gnu/java/nio/FileChannelImpl.java75
1 files changed, 36 insertions, 39 deletions
diff --git a/libjava/gnu/java/nio/FileChannelImpl.java b/libjava/gnu/java/nio/FileChannelImpl.java
index 31779bbc64e..22835401816 100644
--- a/libjava/gnu/java/nio/FileChannelImpl.java
+++ b/libjava/gnu/java/nio/FileChannelImpl.java
@@ -38,6 +38,7 @@ exception statement from your version. */
package gnu.java.nio;
import java.io.EOFException;
+import java.io.FileDescriptor;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
@@ -64,41 +65,41 @@ public class FileChannelImpl extends FileChannel
{
public long address;
public int length;
- public int fd;
+ public FileDescriptor fd;
public MappedByteBuffer buf;
public Object file_obj; // just to keep it live...
- /**
- * This method came from java.io.RandomAccessFile
- * It is private there so we will repeat it here.
- */
- private native long lengthInternal (int native_fd) throws IOException;
-
- public FileChannelImpl (int fd, Object obj)
+ public FileChannelImpl (FileDescriptor fd, boolean write, Object obj)
{
+ if (!(obj instanceof RandomAccessFile)
+ && !(obj instanceof FileInputStream)
+ && !(obj instanceof FileOutputStream))
+ throw new InternalError ();
+
this.fd = fd;
this.file_obj = obj;
}
- public long size () throws IOException
- {
- if (!isOpen ())
- throw new ClosedChannelException ();
+ private native long implPosition ();
+ private native FileChannel implPosition (long newPosition);
+ private native FileChannel implTruncate (long size);
+
+ private native long nio_mmap_file (long pos, long size, int mode);
+ private native void nio_unmmap_file (long address, int size);
+ private native void nio_msync (long address, int length);
- return lengthInternal (fd);
- }
+ public native long size () throws IOException;
protected void implCloseChannel() throws IOException
{
+ // FIXME
+
if (address != 0)
{
- nio_unmmap_file (fd, address, (int) length);
+ //nio_unmmap_file (fd, address, (int) length);
address = 0;
}
- // FIXME
- fd = 0;
-
if (file_obj instanceof RandomAccessFile)
{
RandomAccessFile o = (RandomAccessFile) file_obj;
@@ -121,14 +122,14 @@ public class FileChannelImpl extends FileChannel
int s = (int)size();
if (buf == null)
- {
+ {
throw new EOFException("file not mapped");
- }
+ }
for (int i=0; i<s; i++)
- {
+ {
dst.put( buf.get() );
- }
+ }
return s;
}
@@ -165,15 +166,15 @@ public class FileChannelImpl extends FileChannel
int w = 0;
if (buf == null)
- {
+ {
throw new EOFException ("file not mapped");
- }
+ }
while (src.hasRemaining ())
- {
+ {
buf.put (src.get ());
w++;
- }
+ }
return w;
}
@@ -195,14 +196,14 @@ public class FileChannelImpl extends FileChannel
public long write(ByteBuffer[] srcs, int offset, int length)
throws IOException
{
- long res = 0;
+ long result = 0;
for (int i = offset;i < offset + length;i++)
- {
- res += write (srcs[i]);
- }
+ {
+ result += write (srcs[i]);
+ }
- return res;
+ return result;
}
public MappedByteBuffer map (FileChannel.MapMode mode, long position,
@@ -252,7 +253,7 @@ public class FileChannelImpl extends FileChannel
// FIXME: What to do with metaData ?
- nio_msync (fd, address, length);
+ nio_msync (address, length);
}
public long transferTo (long position, long count, WritableByteChannel target)
@@ -322,7 +323,7 @@ public class FileChannelImpl extends FileChannel
if (!isOpen ())
throw new ClosedChannelException ();
- throw new Error ("not implemented");
+ return implPosition ();
}
public FileChannel position (long newPosition)
@@ -334,7 +335,7 @@ public class FileChannelImpl extends FileChannel
if (!isOpen ())
throw new ClosedChannelException ();
- throw new Error ("not implemented");
+ return implPosition (newPosition);
}
public FileChannel truncate (long size)
@@ -348,10 +349,6 @@ public class FileChannelImpl extends FileChannel
// FIXME: check for NonWritableChannelException
- throw new Error ("not implemented");
+ return implTruncate (size);
}
-
- private static native long nio_mmap_file (int fd, long pos, int size, int mode);
- private static native void nio_unmmap_file (int fd, long address, int size);
- private static native void nio_msync (int fd, long address, int length);
}
OpenPOWER on IntegriCloud