1 |
package gnu.java.nio; |
package gnu.java.nio; |
2 |
|
|
3 |
import java.nio.*; |
import java.nio.*; |
4 |
|
import java.io.IOException; |
5 |
|
|
6 |
#include "temp.h" |
#include "temp.h" |
7 |
|
|
21 |
{ |
{ |
22 |
this.ch = ch; |
this.ch = ch; |
23 |
address = ch.address; |
address = ch.address; |
24 |
|
try { |
25 |
|
long si = ch.size() / SIZE; |
26 |
|
limit((int)si); |
27 |
|
} catch (IOException e) { |
28 |
|
System.err.println("failed to get size of file-channel's file"); |
29 |
|
} |
30 |
} |
} |
31 |
|
|
32 |
public MappedTYPEFileBuffer(MappedTYPEFileBuffer b) |
public MappedTYPEFileBuffer(MappedTYPEFileBuffer b) |
34 |
this.ro = b.ro; |
this.ro = b.ro; |
35 |
this.ch = b.ch; |
this.ch = b.ch; |
36 |
address = b.address; |
address = b.address; |
37 |
|
|
38 |
|
limit(b.limit()); |
39 |
} |
} |
40 |
|
|
41 |
public boolean isReadOnly() |
public boolean isReadOnly() |
45 |
|
|
46 |
#if SIZE == 1 |
#if SIZE == 1 |
47 |
#define GO(TYPE,ELT) \ |
#define GO(TYPE,ELT) \ |
48 |
public static native ELT nio_read_ ## TYPE ## _file_channel(FileChannelImpl ch, int index); \ |
public static native ELT nio_read_ ## TYPE ## _file_channel(FileChannelImpl ch, int index, int limit, long address); \ |
49 |
public static native void nio_write_ ## TYPE ## _file_channel(FileChannelImpl ch, int index, ELT value) |
public static native void nio_write_ ## TYPE ## _file_channel(FileChannelImpl ch, int index, int limit, ELT value, long address) |
50 |
|
|
51 |
GO(Byte,byte); |
GO(Byte,byte); |
52 |
GO(Short,short); |
GO(Short,short); |
59 |
|
|
60 |
final public ELT get() |
final public ELT get() |
61 |
{ |
{ |
62 |
ELT a = MappedByteFileBuffer.nio_read_TYPE_file_channel(ch, position()); |
ELT a = MappedByteFileBuffer.nio_read_TYPE_file_channel(ch, position(), limit(), address); |
63 |
position(position() + SIZE); |
position(position() + SIZE); |
64 |
return a; |
return a; |
65 |
} |
} |
66 |
|
|
67 |
final public TYPEBuffer put(ELT b) |
final public TYPEBuffer put(ELT b) |
68 |
{ |
{ |
69 |
MappedByteFileBuffer.nio_write_TYPE_file_channel(ch, position(), b); |
MappedByteFileBuffer.nio_write_TYPE_file_channel(ch, position(), limit(), b, address); |
70 |
position(position() + SIZE); |
position(position() + SIZE); |
71 |
return this; |
return this; |
72 |
} |
} |
73 |
|
|
74 |
final public ELT get(int index) |
final public ELT get(int index) |
75 |
{ |
{ |
76 |
ELT a = MappedByteFileBuffer.nio_read_TYPE_file_channel(ch, index); |
ELT a = MappedByteFileBuffer.nio_read_TYPE_file_channel(ch, index, limit(), address); |
77 |
return a; |
return a; |
78 |
} |
} |
79 |
|
|
80 |
final public TYPEBuffer put(int index, ELT b) |
final public TYPEBuffer put(int index, ELT b) |
81 |
{ |
{ |
82 |
MappedByteFileBuffer.nio_write_TYPE_file_channel(ch, index, b); |
MappedByteFileBuffer.nio_write_TYPE_file_channel(ch, index, limit(), b, address); |
83 |
return this; |
return this; |
84 |
} |
} |
85 |
|
|
110 |
return b; |
return b; |
111 |
} |
} |
112 |
|
|
113 |
#define CONVERT(TYPE,STYPE) \ |
#define CONVERT(TYPE,STYPE,TO_SIZE) \ |
114 |
final public TYPE ## Buffer as ## TYPE ## Buffer() \ |
final public TYPE ## Buffer as ## TYPE ## Buffer() \ |
115 |
{ \ |
{ \ |
116 |
return new Mapped ## TYPE ## FileBuffer(ch); \ |
TYPE ## Buffer res = new Mapped ## TYPE ## FileBuffer(ch); \ |
117 |
|
res.limit((limit()*SIZE)/TO_SIZE); \ |
118 |
|
return res; \ |
119 |
} \ |
} \ |
120 |
final public STYPE get ## TYPE() \ |
final public STYPE get ## TYPE() \ |
121 |
{ \ |
{ \ |
122 |
STYPE a = MappedByteFileBuffer.nio_read_ ## TYPE ## _file_channel(ch, position()); \ |
STYPE a = MappedByteFileBuffer.nio_read_ ## TYPE ## _file_channel(ch, position(), limit(), address); \ |
123 |
position(position() + SIZE); \ |
position(position() + SIZE); \ |
124 |
return a; \ |
return a; \ |
125 |
} \ |
} \ |
126 |
final public TYPEBuffer put ## TYPE(STYPE value) \ |
final public TYPEBuffer put ## TYPE(STYPE value) \ |
127 |
{ \ |
{ \ |
128 |
MappedByteFileBuffer.nio_write_ ## TYPE ## _file_channel(ch, position(), value); \ |
MappedByteFileBuffer.nio_write_ ## TYPE ## _file_channel(ch, position(), limit(), value, address); \ |
129 |
position(position() + SIZE); \ |
position(position() + SIZE); \ |
130 |
return this; \ |
return this; \ |
131 |
} \ |
} \ |
132 |
final public STYPE get ## TYPE(int index) \ |
final public STYPE get ## TYPE(int index) \ |
133 |
{ \ |
{ \ |
134 |
STYPE a = MappedByteFileBuffer.nio_read_ ## TYPE ## _file_channel(ch, index); \ |
STYPE a = MappedByteFileBuffer.nio_read_ ## TYPE ## _file_channel(ch, index, limit(), address); \ |
135 |
return a; \ |
return a; \ |
136 |
} \ |
} \ |
137 |
final public TYPEBuffer put ## TYPE(int index, STYPE value) \ |
final public TYPEBuffer put ## TYPE(int index, STYPE value) \ |
138 |
{ \ |
{ \ |
139 |
MappedByteFileBuffer.nio_write_ ## TYPE ## _file_channel(ch, index, value); \ |
MappedByteFileBuffer.nio_write_ ## TYPE ## _file_channel(ch, index, limit(), value, address); \ |
140 |
return this; \ |
return this; \ |
141 |
} |
} |
142 |
|
|
143 |
CONVERT(Byte,byte); |
CONVERT(Byte,byte,1); |
144 |
CONVERT(Char,char); |
CONVERT(Char,char,2); |
145 |
CONVERT(Short,short); |
CONVERT(Short,short,2); |
146 |
CONVERT(Int,int); |
CONVERT(Int,int,4); |
147 |
CONVERT(Long,long); |
CONVERT(Long,long,8); |
148 |
CONVERT(Float,float); |
CONVERT(Float,float,4); |
149 |
CONVERT(Double,double); |
CONVERT(Double,double,8); |
150 |
|
|
151 |
} |
} |
152 |
|
|