当前位置: 首页>>代码示例>>Java>>正文


Java SizeOf.SHORT属性代码示例

本文整理汇总了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;
}
 
开发者ID:Sellegit,项目名称:j2objc,代码行数:37,代码来源:ObjectOutputStream.java

示例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;
}
 
开发者ID:Sellegit,项目名称:j2objc,代码行数:10,代码来源:DirectByteBuffer.java

示例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;
}
 
开发者ID:Sellegit,项目名称:j2objc,代码行数:13,代码来源:DirectByteBuffer.java

示例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;
}
 
开发者ID:Sellegit,项目名称:j2objc,代码行数:9,代码来源:ByteArrayBuffer.java

示例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;
}
 
开发者ID:Sellegit,项目名称:j2objc,代码行数:12,代码来源:ByteArrayBuffer.java

示例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;
}
 
开发者ID:Sellegit,项目名称:j2objc,代码行数:12,代码来源:ModifiedUtf8.java

示例7: ByteBufferAsShortBuffer

private ByteBufferAsShortBuffer(ByteBuffer byteBuffer) {
    super(byteBuffer.capacity() / SizeOf.SHORT, byteBuffer.effectiveDirectAddress);
    this.byteBuffer = byteBuffer;
    this.byteBuffer.clear();
}
 
开发者ID:Sellegit,项目名称:j2objc,代码行数:5,代码来源:ByteBufferAsShortBuffer.java

示例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;
}
 
开发者ID:Sellegit,项目名称:j2objc,代码行数:5,代码来源:DataOutputStream.java


注:本文中的libcore.io.SizeOf.SHORT属性示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。