1 // natFileChannelImpl.cc
2 
3 /* Copyright (C) 2003  Free Software Foundation
4 
5    This file is part of libgcj.
6 
7 This software is copyrighted work licensed under the terms of the
8 Libgcj License.  Please consult the file "LIBGCJ_LICENSE" for
9 details.  */
10 
11 #include <config.h>
12 
13 #include <jvm.h>
14 
15 #include <errno.h>
16 #include <string.h>
17 #include <sys/types.h>
18 
19 #ifdef HAVE_UNISTD_H
20 #include <unistd.h>
21 #endif
22 
23 #ifdef HAVE_FCNTL_H
24 #include <fcntl.h>
25 #endif
26 
27 #include <gnu/gcj/RawData.h>
28 #include <java/io/FileDescriptor.h>
29 #include <java/io/IOException.h>
30 #include <java/nio/ByteBuffer.h>
31 #include <java/nio/channels/FileChannel.h>
32 #include <java/nio/channels/FileChannelImpl.h>
33 
34 jlong
size()35 java::nio::channels::FileChannelImpl::size ()
36 {
37   return fd->getLength ();
38 }
39 
40 jlong
implPosition()41 java::nio::channels::FileChannelImpl::implPosition ()
42 {
43   return fd->getFilePointer ();
44 }
45 
46 java::nio::channels::FileChannel*
implPosition(jlong newPosition)47 java::nio::channels::FileChannelImpl::implPosition (jlong newPosition)
48 {
49   fd->seek (newPosition, ::java::io::FileDescriptor::SET, true);
50   return this;
51 }
52 
53 jint
implRead(JArray<jbyte> * buffer,jint offset,jint len)54 java::nio::channels::FileChannelImpl::implRead (JArray<jbyte>* buffer,
55                                                 jint offset, jint len)
56 {
57   return fd->read (buffer, offset, len);
58 }
59 
60 jint
implWrite(JArray<jbyte> * buffer,jint offset,jint len)61 java::nio::channels::FileChannelImpl::implWrite (JArray<jbyte>* buffer,
62                                                  jint offset, jint len)
63 {
64   fd->write (buffer, offset, len);
65   return len;
66 }
67 
68 java::nio::channels::FileChannel*
implTruncate(jlong size)69 java::nio::channels::FileChannelImpl::implTruncate (jlong size)
70 {
71   fd->setLength (size);
72   return this;
73 }
74 
75 gnu::gcj::RawData*
nio_mmap_file(jlong,jlong,jint)76 java::nio::channels::FileChannelImpl::nio_mmap_file (jlong /*pos*/, jlong /*size*/,
77                                                      jint /*mode*/)
78 {
79   throw new ::java::io::IOException (JvNewStringUTF ("mmap not implemented"));
80 }
81 
82 void
nio_unmmap_file(gnu::gcj::RawData *,jint)83 java::nio::channels::FileChannelImpl::nio_unmmap_file (gnu::gcj::RawData* /*address*/,
84 				                       jint /*size*/)
85 {
86   throw new ::java::io::IOException (JvNewStringUTF ("munmap not implemented"));
87 }
88 
89 void
nio_msync(gnu::gcj::RawData *,jint)90 java::nio::channels::FileChannelImpl::nio_msync (gnu::gcj::RawData* /*map_address*/,
91                                                  jint /*length*/)
92 {
93   throw new ::java::io::IOException (JvNewStringUTF ("msync not implemented"));
94 }
95