本文整理了Java中java.nio.ByteBuffer.putShort()
方法的一些代码示例,展示了ByteBuffer.putShort()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。ByteBuffer.putShort()
方法的具体详情如下:
包路径:java.nio.ByteBuffer
类名称:ByteBuffer
方法名:putShort
[英]Writes the given short to the specified index of this buffer.
The short is converted to bytes using the current byte order. The position is not changed.
[中]将给定的短路写入此缓冲区的指定索引。
使用当前字节顺序将短字符转换为字节。位置没有改变。
代码示例来源:origin: apache/incubator-druid
@Override
public void setMaxOverflowRegister(ByteBuffer buffer, short register)
{
buffer.putShort(buffer.position() + MAX_OVERFLOW_REGISTER_BYTE, register);
}
代码示例来源:origin: neo4j/neo4j
private void putIds( int[] ids )
{
target.putShort( (short) ids.length );
for ( int entityTokenId : ids )
{
target.putInt( entityTokenId );
}
}
}
代码示例来源:origin: apache/storm
public ByteBuffer serialize() {
ByteBuffer bb = ByteBuffer.allocate(_message.length + 2);
bb.putShort((short) _task);
bb.put(_message);
return bb;
}
代码示例来源:origin: apache/rocketmq
private static byte[] createUniqIDBuffer() {
ByteBuffer buffer = ByteBuffer.allocate(4 + 2);
long current = System.currentTimeMillis();
if (current >= nextStartTime) {
setStartTime(current);
}
buffer.position(0);
buffer.putInt((int) (System.currentTimeMillis() - startTime));
buffer.putShort((short) COUNTER.getAndIncrement());
return buffer.array();
}
代码示例来源:origin: stackoverflow.com
byte[] arr = { 0x00, 0x01 };
ByteBuffer wrapped = ByteBuffer.wrap(arr); // big-endian by default
short num = wrapped.getShort(); // 1
ByteBuffer dbuf = ByteBuffer.allocate(2);
dbuf.putShort(num);
byte[] bytes = dbuf.array(); // { 0, 1 }
代码示例来源:origin: mcxiaoke/packer-ng-plugin
public void testByteBuffer() throws IOException {
byte[] string = "Hello".getBytes();
ByteBuffer buf = ByteBuffer.allocate(1024);
buf.order(ByteOrder.LITTLE_ENDIAN);
buf.putInt(123);
buf.putChar('z');
buf.putShort((short) 2017);
buf.putFloat(3.1415f);
buf.put(string);
buf.putLong(9876543210L);
buf.putDouble(3.14159265);
buf.put((byte) 5);
buf.flip(); // important
// TestUtils.showBuffer(buf);
assertEquals(123, buf.getInt());
assertEquals('z', buf.getChar());
assertEquals(2017, buf.getShort());
assertEquals(3.1415f, buf.getFloat());
byte[] so = new byte[string.length];
buf.get(so);
assertTrue(TestUtils.sameBytes(string, so));
assertEquals(9876543210L, buf.getLong());
assertEquals(3.14159265, buf.getDouble());
assertEquals((byte) 5, buf.get());
}
代码示例来源:origin: pxb1988/dex2jar
private byte[] build32x(Op op, int vAAAA, int vBBBB) {
checkRegAAAA(op, "vAAAA", vAAAA);
checkRegAAAA(op, "vBBBB", vBBBB);
b.position(0);
b.put((byte) op.opcode).put((byte) 0).putShort((short) vAAAA).putShort((short) vBBBB);
return copy(b);
}
代码示例来源:origin: Genymobile/gnirehtet
private static ByteBuffer createMockTCPHeader() {
ByteBuffer buffer = ByteBuffer.allocate(20);
buffer.putShort((short) 0x1234); // source port
buffer.putShort((short) 0x5678); // destination port
buffer.putInt(0x111); // sequence number
buffer.putInt(0x222); // acknowledgment number
buffer.putShort((short) (5 << 12)); // data offset + flags(0)
buffer.putShort((short) 0); // window (don't care for these tests)
buffer.putShort((short) 0); // checksum
buffer.putShort((short) 0); // urgent pointer
buffer.flip();
return buffer;
}
代码示例来源:origin: robolectric/robolectric
public static void write(ByteBuffer buf, int dataType, int data) {
buf.putShort((short) SIZEOF); // size
buf.put((byte) 0); // res0
buf.put((byte) dataType); // dataType
buf.putInt(data); // data
}
代码示例来源:origin: apache/incubator-druid
public int storeInByteBuffer(ByteBuffer buffer, int position)
{
buffer.position(position);
buffer.putShort((short) (((isLeaf ? 0x1 : 0x0) << 15) | getChildren().size()));
for (float v : getMinCoordinates()) {
buffer.putFloat(v);
}
for (float v : getMaxCoordinates()) {
buffer.putFloat(v);
}
byte[] bytes = bitmap.toBytes();
buffer.putInt(bytes.length);
buffer.put(bytes);
int pos = buffer.position();
int childStartOffset = pos + getChildren().size() * Integer.BYTES;
for (Node child : getChildren()) {
buffer.putInt(pos, childStartOffset);
childStartOffset = child.storeInByteBuffer(buffer, childStartOffset);
pos += Integer.BYTES;
}
return childStartOffset;
}
代码示例来源:origin: alibaba/fescar
@Override
public void doEncode() {
// super.doEncode();
byteBuffer.put(this.identified ? (byte) 1 : (byte) 0);
if (this.version != null) {
byte[] bs = version.getBytes(UTF8);
byteBuffer.putShort((short) bs.length);
if (bs.length > 0) {
byteBuffer.put(bs);
}
} else {
byteBuffer.putShort((short) 0);
}
}
代码示例来源:origin: ltsopensource/light-task-scheduler
@Override
public void write(FileChannel fileChannel) throws IOException {
byteBuffer().position(0);
byteBuffer().putShort(magic);
byteBuffer().putLong(this.firstRecordId);
byteBuffer().flip();
fileChannel.position(0);
fileChannel.write(byteBuffer());
fileChannel.force(true);
}
}
代码示例来源:origin: bumptech/glide
private static ByteBuffer getExifMagicNumber() {
ByteBuffer jpegHeaderBytes = ByteBuffer.allocate(2);
jpegHeaderBytes.putShort((short) DefaultImageHeaderParser.EXIF_MAGIC_NUMBER);
jpegHeaderBytes.position(0);
return jpegHeaderBytes;
}
代码示例来源:origin: apache/kafka
@Test
public void testParseUnknownType() {
ByteBuffer buffer = ByteBuffer.allocate(32);
buffer.putShort(ControlRecordType.CURRENT_CONTROL_RECORD_KEY_VERSION);
buffer.putShort((short) 337);
buffer.flip();
ControlRecordType type = ControlRecordType.parse(buffer);
assertEquals(ControlRecordType.UNKNOWN, type);
}
代码示例来源:origin: apache/ignite
/**
* @param states Cache states.
*/
private static void putCacheStates(ByteBuffer buf, Map<Integer, CacheState> states) {
buf.putShort((short)states.size());
for (Map.Entry<Integer, CacheState> entry : states.entrySet()) {
buf.putInt(entry.getKey());
CacheState state = entry.getValue();
// Need 2 bytes for the number of partitions.
buf.putShort((short)state.size());
for (int i = 0; i < state.size(); i++) {
buf.putShort((short)state.partitionByIndex(i));
buf.putLong(state.partitionSizeByIndex(i));
buf.putLong(state.partitionCounterByIndex(i));
}
}
}
代码示例来源:origin: sannies/mp4parser
@Override
protected byte[] writeData() {
ByteBuffer bb = ByteBuffer.allocate(6);
bb.putInt(a);
bb.putShort(b);
return bb.array();
}
代码示例来源:origin: stackoverflow.com
byte [] ShortToByte_ByteBuffer_Method(short [] input)
{
int index;
int iterations = input.length;
ByteBuffer bb = ByteBuffer.allocate(input.length * 2);
for(index = 0; index != iterations; ++index)
{
bb.putShort(input[index]);
}
return bb.array();
}
代码示例来源:origin: wildfly/wildfly
public ByteBuffer toByteBuffer() {
byte[] data = reason.getBytes(StandardCharsets.UTF_8);
ByteBuffer buffer = ByteBuffer.allocate(data.length + 2);
buffer.putShort((short) code);
buffer.put(data);
buffer.flip();
return buffer;
}
代码示例来源:origin: mcxiaoke/packer-ng-plugin
public void testBufferWrite() throws IOException {
File f = newTestFile();
byte[] string = "Hello".getBytes();
ByteBuffer in = ByteBuffer.allocate(1024);
in.order(ByteOrder.LITTLE_ENDIAN);
in.putInt(123);
in.putChar('z');
in.putShort((short) 2017);
in.putFloat(3.1415f);
in.putLong(9876543210L);
in.putDouble(3.14159265);
in.put((byte) 5);
in.put(string);
代码示例来源:origin: pxb1988/dex2jar
private byte[] build22x(Op op, int vAA, int vBBBB) {
checkRegAA(op, "vAA", vAA);
checkRegAAAA(op, "vBBBB", vBBBB);
b.position(0);
b.put((byte) op.opcode).put((byte) vAA).putShort((short) vBBBB);
return copy(b);
}
内容来源于网络,如有侵权,请联系作者删除!