1"====================================================================== 2| 3| Java run-time support. java.nio.channels.FileChannelImpl native methods. 4| 5| 6 ======================================================================" 7 8 9"====================================================================== 10| 11| Copyright 2003 Free Software Foundation, Inc. 12| Written by Paolo Bonzini. 13| 14| This file is part of GNU Smalltalk. 15| 16| The GNU Smalltalk class library is free software; you can redistribute it 17| and/or modify it under the terms of the GNU General Public License 18| as published by the Free Software Foundation; either version 2, or (at 19| your option) any later version. 20| 21| The GNU Smalltalk class library is distributed in the hope that it will be 22| useful, but WITHOUT ANY WARRANTY; without even the implied warranty of 23| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General 24| Public License for more details. 25| 26| You should have received a copy of the GNU Lesser General Public License 27| along with the GNU Smalltalk class library; see the file COPYING. If not, 28| write to the Free Software Foundation, 51 Franklin Street, Fifth Floor, 29| Boston, MA 02110-1301, USA. 30| 31 ======================================================================" 32 33 34!JavaVM methodsFor: 'java.nio.channels.FileChannelImpl'! 35 36java_nio_channels_FileChannelImpl_implPosition 37 <javaNativeMethod: #'implPosition()J' 38 for: #{Java.java.nio.channels.FileChannelImpl} static: false> 39 ^self fd asFileDescriptor position 40! 41 42java_nio_channels_FileChannelImpl_implPosition_long: arg1 43 | desc | 44 <javaNativeMethod: #'implPosition(J)Ljava/nio/channels/FileChannel;' 45 for: #{Java.java.nio.channels.FileChannelImpl} static: false> 46 desc := self fd asFileDescriptor. 47 desc position: (arg1 min: desc size) 48! 49 50java_nio_channels_FileChannelImpl_implTruncate_long: arg1 51 | delta fd position | 52 <javaNativeMethod: #'implTruncate(J)Ljava/nio/channels/FileChannel;' 53 for: #{Java.java.nio.channels.FileChannelImpl} static: false> 54 fd := self fd asFileDescriptor. 55 delta := fd size - arg1. 56 delta = 0 ifTrue: [ ^self ]. 57 delta < 0 ifTrue: [ fd position: arg1; truncate. ^self ]. 58 59 "If the file is too short, we extend it. We can't rely on 60 ftruncate() extending the file. So we lseek() to 1 byte less 61 than we want, and then we write a single byte at the end." 62 position := fd position. 63 fd position: arg1 - 1. 64 fd write: #[0]. 65 fd position: position 66! 67 68java_nio_channels_FileChannelImpl_nio_mmap_file_long: arg1 long: arg2 int: arg3 69 <javaNativeMethod: #'nio_mmap_file(JJI)Lgnu/gcj/RawData;' 70 for: #{Java.java.nio.channels.FileChannelImpl} static: false> 71 self notYetImplemented 72! 73 74java_nio_channels_FileChannelImpl_nio_unmmap_file_gnu_gcj_RawData: arg1 int: arg2 75 <javaNativeMethod: #'nio_unmmap_file(Lgnu/gcj/RawData;I)V' 76 for: #{Java.java.nio.channels.FileChannelImpl} static: false> 77 self notYetImplemented 78! 79 80java_nio_channels_FileChannelImpl_nio_msync_gnu_gcj_RawData: arg1 int: arg2 81 <javaNativeMethod: #'nio_msync(Lgnu/gcj/RawData;I)V' 82 for: #{Java.java.nio.channels.FileChannelImpl} static: false> 83 self notYetImplemented 84! 85 86java_nio_channels_FileChannelImpl_size 87 <javaNativeMethod: #'size()J' 88 for: #{Java.java.nio.channels.FileChannelImpl} static: false> 89 ^self fd asFileDescriptor size 90! 91 92java_nio_channels_FileChannelImpl_implRead_byteArray: arg1 int: arg2 int: arg3 93 | array count | 94 <javaNativeMethod: #'implRead([BII)I' 95 for: #{Java.java.nio.channels.FileChannelImpl} static: false> 96 array := ByteArray new: arg3. 97 count := self fd asFileDescriptor read: array from: 1 to: arg3. 98 arg1 replaceFrom: arg1 + 1 to: arg1 + count with: array startingAt: 1. 99 ^count 100! 101 102java_nio_channels_FileChannelImpl_implWrite_byteArray: arg1 int: arg2 int: arg3 103 | array | 104 <javaNativeMethod: #'implWrite([BII)I' 105 for: #{Java.java.nio.channels.FileChannelImpl} static: false> 106 array := ByteArray new: arg3. 107 array replaceFrom: 1 to: arg3 with: arg1 startingAt: arg2 + 1. 108 ^self fd asFileDescriptor write: array from: 1 to: arg3 109! ! 110 111