下面列出了java.nio.MappedByteBuffer#asIntBuffer ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
@Override
public void serialize(int[] a, File file) throws IOException {
MappedByteBuffer buffer = Files.map(file, FileChannel.MapMode.READ_WRITE, a.length * 4);
buffer.order(ByteOrder.BIG_ENDIAN);
IntBuffer intBuffer = buffer.asIntBuffer();
for (int i = 0; i < a.length; ++i) {
intBuffer.put(i, a[i]);
}
}
@Override
public int[] deserialize(File file) throws IOException {
MappedByteBuffer buffer = Files.map(file, FileChannel.MapMode.READ_ONLY, file.length());
buffer.order(ByteOrder.BIG_ENDIAN);
IntBuffer intBuffer = buffer.asIntBuffer();
int[] ret = new int[(int)(file.length() / 4)];
intBuffer.get(ret);
return ret;
}
@Override
public void serialize(int[] a, File file) throws IOException {
MappedByteBuffer buffer = Files.map(file, FileChannel.MapMode.READ_WRITE, a.length * 4);
buffer.order(ByteOrder.LITTLE_ENDIAN);
IntBuffer intBuffer = buffer.asIntBuffer();
for (int i = 0; i < a.length; ++i) {
intBuffer.put(i, a[i]);
}
}
@Override
public int[] deserialize(File file) throws IOException {
MappedByteBuffer buffer = Files.map(file, FileChannel.MapMode.READ_ONLY, file.length());
buffer.order(ByteOrder.LITTLE_ENDIAN);
IntBuffer intBuffer = buffer.asIntBuffer();
int[] ret = new int[(int)(file.length() / 4)];
intBuffer.get(ret);
return ret;
}