diff options
| author | mkoch <mkoch@138bc75d-0d04-0410-961f-82ee72b054a4> | 2003-03-20 11:14:35 +0000 |
|---|---|---|
| committer | mkoch <mkoch@138bc75d-0d04-0410-961f-82ee72b054a4> | 2003-03-20 11:14:35 +0000 |
| commit | dadab084821ab678e4dce4c4faf1f76c7d86e92f (patch) | |
| tree | 9fe3a88d762e1d449fc098bc9f0bf3f4d473b82f /libjava/gnu/java/nio/FileChannelImpl.java | |
| parent | 8c10f814b621d4dd5284e911aafc01f2f86e6d02 (diff) | |
| download | ppe42-gcc-dadab084821ab678e4dce4c4faf1f76c7d86e92f.tar.gz ppe42-gcc-dadab084821ab678e4dce4c4faf1f76c7d86e92f.zip | |
2003-03-20 Michael Koch <konqueror@gmx.de>
* gnu/java/nio/FileChannelImpl.java
(address): Removed.
(map_address): New member variable.
(length): Make it package private.
(fd): Make it package private.
(buf): Make it package private.
(file_obj): Make it package private.
(FileChannelImpl): New constructor.
(nio_mmap_file): Use RawData instead of long.
(nio_munmap_file): Use RawData instead of long.
(nio_msync): Use RawData instead of long.
(implCloseChannel): New implementation using map_address.
(read): Reformated.
(map): Implemented.
(create_direct_mapped_buffer): Implemented, use RawData, throws
IOException.
(force): Use map_address instead of address.
* gnu/java/nio/MappedByteFileBuffer.java
(address): Removed.
(map_address): New member variable.
(MappedByteFileBuffer): Use map_address instead of address, reformated.
(several methods): Use map_address instead of address, replaced long
with RawData where appropriate.
* gnu/java/nio/natFileChannelImpl.cc
(nio_mmap_file): Replaced long with RawData.
(nio_munmap_file): Replaced long with RawData.
(nio_msync): Replaced long with RawData.
* gnu/java/nio/natMappedByteFileBuffer.cc
(several methods): Replaced long with RawData where appropriate.
git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@64612 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'libjava/gnu/java/nio/FileChannelImpl.java')
| -rw-r--r-- | libjava/gnu/java/nio/FileChannelImpl.java | 70 |
1 files changed, 38 insertions, 32 deletions
diff --git a/libjava/gnu/java/nio/FileChannelImpl.java b/libjava/gnu/java/nio/FileChannelImpl.java index 22835401816..c233d8210a7 100644 --- a/libjava/gnu/java/nio/FileChannelImpl.java +++ b/libjava/gnu/java/nio/FileChannelImpl.java @@ -52,6 +52,7 @@ import java.nio.channels.NonReadableChannelException; import java.nio.channels.NonWritableChannelException; import java.nio.channels.ReadableByteChannel; import java.nio.channels.WritableByteChannel; +import gnu.gcj.RawData; /** * This file is not user visible ! @@ -63,11 +64,14 @@ import java.nio.channels.WritableByteChannel; public class FileChannelImpl extends FileChannel { - public long address; - public int length; - public FileDescriptor fd; - public MappedByteBuffer buf; - public Object file_obj; // just to keep it live... + // GCJ LOCAL: This variable stores a pointer to the memory + // where the file is mapped. + RawData map_address; + + int length; + FileDescriptor fd; + MappedByteBuffer buf; + Object file_obj; // just to keep it live... public FileChannelImpl (FileDescriptor fd, boolean write, Object obj) { @@ -80,24 +84,27 @@ public class FileChannelImpl extends FileChannel this.file_obj = obj; } + public FileChannelImpl () + { + this (new FileDescriptor (-1), true, null); + } + 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); + private native RawData nio_mmap_file (long pos, long size, int mode); + private native void nio_unmmap_file (RawData map_address, int size); + private native void nio_msync (RawData map_address, int length); public native long size () throws IOException; protected void implCloseChannel() throws IOException { - // FIXME - - if (address != 0) + if (map_address != null) { - //nio_unmmap_file (fd, address, (int) length); - address = 0; + nio_unmmap_file (map_address, (int) length); + map_address = null; } if (file_obj instanceof RandomAccessFile) @@ -126,9 +133,9 @@ public class FileChannelImpl extends FileChannel throw new EOFException("file not mapped"); } - for (int i=0; i<s; i++) + for (int i = 0; i < s; i++) { - dst.put( buf.get() ); + dst.put (buf.get()); } return s; @@ -154,9 +161,9 @@ public class FileChannelImpl extends FileChannel long result = 0; for (int i = offset; i < offset + length; i++) - { - result += write (dsts[i]); - } + { + result += write (dsts [i]); + } return result; } @@ -218,23 +225,22 @@ public class FileChannelImpl extends FileChannel || size > Integer.MAX_VALUE) throw new IllegalArgumentException (); -// int cmode = mode.m; -// address = nio_mmap_file (fd, position, size, cmode); -// length = size; -// buf = new MappedByteFileBuffer (this); -// return buf; - return null; + int cmode = mode.m; + map_address = nio_mmap_file (position, size, cmode); + length = (int) size; + buf = new MappedByteFileBuffer (this); + return buf; } - static MappedByteBuffer create_direct_mapped_buffer (long address, + static MappedByteBuffer create_direct_mapped_buffer (RawData map_address, long length) + throws IOException { -// FileChannelImpl ch = new FileChannelImpl (-1, null); -// ch.address = address; -// ch.length = (int) length; -// ch.buf = new MappedByteFileBuffer (ch); -// return ch.buf; - return null; + FileChannelImpl ch = new FileChannelImpl (); + ch.map_address = map_address; + ch.length = (int) length; + ch.buf = new MappedByteFileBuffer (ch); + return ch.buf; } public long write (ByteBuffer[] srcs) @@ -253,7 +259,7 @@ public class FileChannelImpl extends FileChannel // FIXME: What to do with metaData ? - nio_msync (address, length); + nio_msync (map_address, length); } public long transferTo (long position, long count, WritableByteChannel target) |

