本文整理汇总了Java中libcore.io.SizeOf.SHORT属性的典型用法代码示例。如果您正苦于以下问题:Java SizeOf.SHORT属性的具体用法?Java SizeOf.SHORT怎么用?Java SizeOf.SHORT使用的例子?那么, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类libcore.io.SizeOf
的用法示例。
在下文中一共展示了SizeOf.SHORT属性的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: writeNewString
/**
* 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: getShort
@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;
}
示例3: putShort
@Override public ByteBuffer putShort(short value) {
checkNotFreed();
if (isReadOnly) {
throw new ReadOnlyBufferException();
}
int newPosition = position + SizeOf.SHORT;
if (newPosition > limit) {
throw new BufferOverflowException();
}
this.block.pokeShort(offset + position, value, order);
position = newPosition;
return this;
}
示例4: getShort
@Override public final short getShort() {
int newPosition = position + SizeOf.SHORT;
if (newPosition > limit) {
throw new BufferUnderflowException();
}
short result = Memory.peekShort(backingArray, arrayOffset + position, order);
position = newPosition;
return result;
}
示例5: putShort
@Override public ByteBuffer putShort(short value) {
if (isReadOnly) {
throw new ReadOnlyBufferException();
}
int newPosition = position + SizeOf.SHORT;
if (newPosition > limit) {
throw new BufferOverflowException();
}
Memory.pokeShort(backingArray, arrayOffset + position, value, order);
position = newPosition;
return this;
}
示例6: encode
/**
* Returns an array containing the <i>modified UTF-8</i> form of {@code s}, using a
* big-endian 16-bit length. Throws UTFDataFormatException if {@code s} is too long
* for a two-byte length.
*/
public static byte[] encode(String s) throws UTFDataFormatException {
int utfCount = (int) ModifiedUtf8.countBytes(s, true);
byte[] result = new byte[SizeOf.SHORT + utfCount];
Memory.pokeShort(result, 0, (short) utfCount, ByteOrder.BIG_ENDIAN);
ModifiedUtf8.encode(result, SizeOf.SHORT, s);
return result;
}
示例7: ByteBufferAsShortBuffer
private ByteBufferAsShortBuffer(ByteBuffer byteBuffer) {
super(byteBuffer.capacity() / SizeOf.SHORT, byteBuffer.effectiveDirectAddress);
this.byteBuffer = byteBuffer;
this.byteBuffer.clear();
}
示例8: writeShort
public final void writeShort(int val) throws IOException {
Memory.pokeShort(scratch, 0, (short) val, ByteOrder.BIG_ENDIAN);
out.write(scratch, 0, SizeOf.SHORT);
written += SizeOf.SHORT;
}