corda/classpath/java/nio/FixedArrayByteBuffer.java
Joel Dice 87b02eb949 update copyright years
Previously, I used a shell script to extract modification date ranges
from the Git history, but that was complicated and unreliable, so now
every file just gets the same year range in its copyright header.  If
someone needs to know when a specific file was modified and by whom,
they can look at the Git history themselves; no need to include it
redundantly in the header.
2013-07-02 20:52:38 -06:00

59 lines
1.7 KiB
Java

/* Copyright (c) 2008-2013, Avian Contributors
Permission to use, copy, modify, and/or distribute this software
for any purpose with or without fee is hereby granted, provided
that the above copyright notice and this permission notice appear
in all copies.
There is NO WARRANTY for this software. See license.txt for
details. */
package java.nio;
class FixedArrayByteBuffer extends DirectByteBuffer {
private final byte[] array;
private final int arrayOffset;
private FixedArrayByteBuffer(long address,
byte[] array,
int offset,
int capacity,
boolean readOnly)
{
super(address, capacity, readOnly);
this.array = array;
this.arrayOffset = offset;
}
public static FixedArrayByteBuffer make(int capacity) {
long[] address = new long[1];
byte[] array = allocateFixed(capacity, address);
return new FixedArrayByteBuffer(address[0], array, 0, capacity, false);
}
private static native byte[] allocateFixed(int capacity, long[] address);
public ByteBuffer asReadOnlyBuffer() {
ByteBuffer b = new FixedArrayByteBuffer
(address, array, arrayOffset, capacity, true);
b.position(position());
b.limit(limit());
return b;
}
public ByteBuffer slice() {
return new FixedArrayByteBuffer
(address + position, array, arrayOffset + position, remaining(), true);
}
public String toString() {
return "(FixedArrayByteBuffer with address: " + address
+ " array: " + array
+ " arrayOffset: " + arrayOffset
+ " position: " + position
+ " limit: " + limit
+ " capacity: " + capacity + ")";
}
}