本文整理汇总了Java中libcore.io.SizeOf类的典型用法代码示例。如果您正苦于以下问题:Java SizeOf类的具体用法?Java SizeOf怎么用?Java SizeOf使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
SizeOf类属于libcore.io包,在下文中一共展示了SizeOf类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: writeNewString
import libcore.io.SizeOf; //导入依赖的package包/类
/**
* Write String {@code object} into the receiver. It is assumed the
* String has not been dumped yet. Returns the handle for this object (String) which is dumped here.
* Strings are saved encoded with {@link DataInput modified UTF-8}.
*
* @param object
* the string to dump.
* @return the handle assigned to the String being dumped
*
* @throws IOException
* If an IO exception happened when writing the String.
*/
private int writeNewString(String object, boolean unshared) throws IOException {
long count = ModifiedUtf8.countBytes(object, false);
byte[] buffer;
int offset = 0;
if (count <= 0xffff) {
buffer = new byte[1 + SizeOf.SHORT + (int) count];
buffer[offset++] = TC_STRING;
Memory.pokeShort(buffer, offset, (short) count, ByteOrder.BIG_ENDIAN);
offset += SizeOf.SHORT;
} else {
buffer = new byte[1 + SizeOf.LONG + (int) count];
buffer[offset++] = TC_LONGSTRING;
Memory.pokeLong(buffer, offset, count, ByteOrder.BIG_ENDIAN);
offset += SizeOf.LONG;
}
ModifiedUtf8.encode(buffer, offset, object);
output.write(buffer, 0, buffer.length);
int handle = nextHandle();
if (!unshared) {
objectsWritten.put(object, handle);
}
return handle;
}
示例2: setSeed
import libcore.io.SizeOf; //导入依赖的package包/类
/**
* Seeds this {@code SecureRandom} instance with the specified eight-byte
* {@code seed}. <a href="#insecure_seed">Seeding {@code SecureRandom} may
* be insecure</a>.
*/
@Override
public void setSeed(long seed) {
if (seed == 0) { // skip call from Random
return;
}
byte[] byteSeed = new byte[SizeOf.LONG];
Memory.pokeLong(byteSeed, 0, seed, ByteOrder.BIG_ENDIAN);
setSeed(byteSeed);
}
示例3: compact
import libcore.io.SizeOf; //导入依赖的package包/类
@Override
public ShortBuffer compact() {
if (byteBuffer.isReadOnly()) {
throw new ReadOnlyBufferException();
}
byteBuffer.limit(limit * SizeOf.SHORT);
byteBuffer.position(position * SizeOf.SHORT);
byteBuffer.compact();
byteBuffer.clear();
position = limit - position;
limit = capacity;
mark = UNSET_MARK;
return this;
}
示例4: get
import libcore.io.SizeOf; //导入依赖的package包/类
@Override
public short get() {
if (position == limit) {
throw new BufferUnderflowException();
}
return byteBuffer.getShort(position++ * SizeOf.SHORT);
}
示例5: put
import libcore.io.SizeOf; //导入依赖的package包/类
@Override
public ShortBuffer put(short c) {
if (position == limit) {
throw new BufferOverflowException();
}
byteBuffer.putShort(position++ * SizeOf.SHORT, c);
return this;
}
示例6: slice
import libcore.io.SizeOf; //导入依赖的package包/类
@Override
public ShortBuffer slice() {
byteBuffer.limit(limit * SizeOf.SHORT);
byteBuffer.position(position * SizeOf.SHORT);
ByteBuffer bb = byteBuffer.slice().order(byteBuffer.order());
ShortBuffer result = new ByteBufferAsShortBuffer(bb);
byteBuffer.clear();
return result;
}
示例7: get
import libcore.io.SizeOf; //导入依赖的package包/类
@Override
public float get() {
if (position == limit) {
throw new BufferUnderflowException();
}
return byteBuffer.getFloat(position++ * SizeOf.FLOAT);
}
示例8: put
import libcore.io.SizeOf; //导入依赖的package包/类
@Override
public FloatBuffer put(float[] src, int srcOffset, int floatCount) {
byteBuffer.limit(limit * SizeOf.FLOAT);
byteBuffer.position(position * SizeOf.FLOAT);
if (byteBuffer instanceof DirectByteBuffer) {
((DirectByteBuffer) byteBuffer).put(src, srcOffset, floatCount);
} else {
((ByteArrayBuffer) byteBuffer).put(src, srcOffset, floatCount);
}
this.position += floatCount;
return this;
}
示例9: slice
import libcore.io.SizeOf; //导入依赖的package包/类
@Override
public FloatBuffer slice() {
byteBuffer.limit(limit * SizeOf.FLOAT);
byteBuffer.position(position * SizeOf.FLOAT);
ByteBuffer bb = byteBuffer.slice().order(byteBuffer.order());
FloatBuffer result = new ByteBufferAsFloatBuffer(bb);
byteBuffer.clear();
return result;
}
示例10: getChar
import libcore.io.SizeOf; //导入依赖的package包/类
@Override public final char getChar() {
checkNotFreed();
int newPosition = position + SizeOf.CHAR;
if (newPosition > limit) {
throw new BufferUnderflowException();
}
char result = (char) this.block.peekShort(offset + position, order);
position = newPosition;
return result;
}
示例11: getDouble
import libcore.io.SizeOf; //导入依赖的package包/类
@Override public final double getDouble() {
checkNotFreed();
int newPosition = position + SizeOf.DOUBLE;
if (newPosition > limit) {
throw new BufferUnderflowException();
}
double result = Double.longBitsToDouble(this.block.peekLong(offset + position, order));
position = newPosition;
return result;
}
示例12: getFloat
import libcore.io.SizeOf; //导入依赖的package包/类
@Override public final float getFloat() {
checkNotFreed();
int newPosition = position + SizeOf.FLOAT;
if (newPosition > limit) {
throw new BufferUnderflowException();
}
float result = Float.intBitsToFloat(this.block.peekInt(offset + position, order));
position = newPosition;
return result;
}
示例13: getInt
import libcore.io.SizeOf; //导入依赖的package包/类
@Override public final int getInt() {
checkNotFreed();
int newPosition = position + SizeOf.INT;
if (newPosition > limit) {
throw new BufferUnderflowException();
}
int result = this.block.peekInt(offset + position, order);
position = newPosition;
return result;
}
示例14: getLong
import libcore.io.SizeOf; //导入依赖的package包/类
@Override public final long getLong() {
checkNotFreed();
int newPosition = position + SizeOf.LONG;
if (newPosition > limit) {
throw new BufferUnderflowException();
}
long result = this.block.peekLong(offset + position, order);
position = newPosition;
return result;
}
示例15: getShort
import libcore.io.SizeOf; //导入依赖的package包/类
@Override public final short getShort() {
checkNotFreed();
int newPosition = position + SizeOf.SHORT;
if (newPosition > limit) {
throw new BufferUnderflowException();
}
short result = this.block.peekShort(offset + position, order);
position = newPosition;
return result;
}