當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。