org.nustaq.offheap.bytez.niobuffers.ByteBufferBasicBytez Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of fst Show documentation
Show all versions of fst Show documentation
A fast java serialization drop in-replacement and some serialization based utils such as Structs and OffHeap Memory.
package org.nustaq.offheap.bytez.niobuffers;
import org.nustaq.offheap.bytez.BasicBytez;
import java.nio.ByteBuffer;
/**
* Created by moelrue on 5/5/15.
*/
public class ByteBufferBasicBytez implements BasicBytez {
ByteBuffer buffer;
public ByteBufferBasicBytez(ByteBuffer buffer) {
this.buffer = buffer;
}
@Override
public byte get(long byteIndex) {
return buffer.get((int) byteIndex);
}
@Override
public boolean getBool(long byteIndex) {
return buffer.get((int) byteIndex) != 0;
}
@Override
public char getChar(long byteIndex) {
return buffer.getChar((int) byteIndex);
}
@Override
public short getShort(long byteIndex) {
return buffer.getShort((int) byteIndex);
}
@Override
public int getInt(long byteIndex) {
return buffer.getInt((int) byteIndex);
}
@Override
public long getLong(long byteIndex) {
return buffer.getLong((int) byteIndex);
}
@Override
public float getFloat(long byteIndex) {
return buffer.getFloat((int) byteIndex);
}
@Override
public double getDouble(long byteIndex) {
return buffer.getDouble((int) byteIndex);
}
@Override
public void put(long byteIndex, byte value) {
buffer.put((int) byteIndex,value);
}
@Override
public void putBool(long byteIndex, boolean val) {
buffer.put((int) byteIndex, (byte) (val?1:0));
}
@Override
public void putChar(long byteIndex, char c) {
buffer.putChar((int) byteIndex, c);
}
@Override
public void putShort(long byteIndex, short s) {
buffer.putShort((int) byteIndex, s);
}
@Override
public void putInt(long byteIndex, int i) {
buffer.putInt((int) byteIndex, i);
}
@Override
public void putLong(long byteIndex, long l) {
buffer.putLong((int) byteIndex, l);
}
@Override
public void putFloat(long byteIndex, float f) {
buffer.putFloat((int) byteIndex, f);
}
@Override
public void putDouble(long byteIndex, double d) {
buffer.putDouble((int) byteIndex, d);
}
@Override
public long length() {
return buffer.limit();
}
@Override
public void getArr(long byteIndex, byte[] target, int elemoff, int numElems) {
int position = buffer.position();
buffer.position((int) byteIndex);
buffer.get(target,elemoff,numElems);
buffer.position(position);
}
@Override
public void getCharArr(long byteIndex, char[] target, int elemoff, int numElems) {
for ( int i=0; i
© 2015 - 2024 Weber Informatics LLC | Privacy Policy