java.nio.ByteBuffer.order()方法的使用及代码示例

x33g5p2x  于2022-01-16 转载在 其他  
字(6.5k)|赞(0)|评价(0)|浏览(559)

本文整理了Java中java.nio.ByteBuffer.order()方法的一些代码示例,展示了ByteBuffer.order()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。ByteBuffer.order()方法的具体详情如下:
包路径:java.nio.ByteBuffer
类名称:ByteBuffer
方法名:order

ByteBuffer.order介绍

[英]The byte order of this buffer, default is BIG_ENDIAN.
[中]此缓冲区的字节顺序,默认为BIG_ENDIAN。

代码示例

代码示例来源:origin: Tencent/tinker

/**
 * Creates a new empty dex of the specified size.
 */
public Dex(int byteCount) {
  this.data = ByteBuffer.wrap(new byte[byteCount]);
  this.data.order(ByteOrder.LITTLE_ENDIAN);
  this.tableOfContents.fileSize = byteCount;
}

代码示例来源:origin: libgdx/libgdx

public static ByteBuffer newByteBuffer (int numBytes) {
  ByteBuffer buffer = ByteBuffer.allocateDirect(numBytes);
  buffer.order(ByteOrder.nativeOrder());
  return buffer;
}

代码示例来源:origin: bumptech/glide

RandomAccessReader(byte[] data, int length) {
 this.data = (ByteBuffer) ByteBuffer.wrap(data)
   .order(ByteOrder.BIG_ENDIAN)
   .limit(length);
}

代码示例来源:origin: google/guava

@Override
public HashCode hashUnencodedChars(CharSequence input) {
 int len = input.length();
 ByteBuffer buffer = ByteBuffer.allocate(len * 2).order(ByteOrder.LITTLE_ENDIAN);
 for (int i = 0; i < len; i++) {
  buffer.putChar(input.charAt(i));
 }
 return hashBytes(buffer.array());
}

代码示例来源:origin: neo4j/neo4j

private static ByteBuffer grow( ByteBuffer buffer, int required )
{
  buffer.flip();
  int capacity = buffer.capacity();
  do
  {
    capacity *= 2;
  }
  while ( capacity - buffer.limit() < required );
  return ByteBuffer.allocate( capacity ).order( ByteOrder.LITTLE_ENDIAN ).put( buffer );
}

代码示例来源:origin: apache/flink

private static String deserializeV1(byte[] serialized) {
  final ByteBuffer bb = ByteBuffer.wrap(serialized).order(ByteOrder.LITTLE_ENDIAN);
  final byte[] targetStringBytes = new byte[bb.getInt()];
  bb.get(targetStringBytes);
  return new String(targetStringBytes, CHARSET);
}

代码示例来源:origin: stackoverflow.com

public static int byteArrayToLeInt(byte[] b) {
  final ByteBuffer bb = ByteBuffer.wrap(b);
  bb.order(ByteOrder.LITTLE_ENDIAN);
  return bb.getInt();
}

public static byte[] leIntToByteArray(int i) {
  final ByteBuffer bb = ByteBuffer.allocate(Integer.SIZE / Byte.SIZE);
  bb.order(ByteOrder.LITTLE_ENDIAN);
  bb.putInt(i);
  return bb.array();
}

代码示例来源:origin: pxb1988/dex2jar

private static ByteBuffer slice(ByteBuffer in, int offset, int length) {
  in.position(offset);
  ByteBuffer b = in.slice();
  b.limit(length);
  b.order(ByteOrder.LITTLE_ENDIAN);
  return b;
}

代码示例来源:origin: Tencent/tinker

private void ensureBufferSize(int bytes) {
  if (this.data.position() + bytes > this.data.limit()) {
    if (this.isResizeAllowed) {
      byte[] array = this.data.array();
      byte[] newArray = new byte[array.length + bytes + (array.length >> 1)];
      System.arraycopy(array, 0, newArray, 0, this.data.position());
      int lastPos = this.data.position();
      this.data = ByteBuffer.wrap(newArray);
      this.data.order(ByteOrder.LITTLE_ENDIAN);
      this.data.position(lastPos);
      this.data.limit(this.data.capacity());
    }
  }
}

代码示例来源:origin: libgdx/libgdx

void setup (byte[] pcm, int channels, int sampleRate) {
  int bytes = pcm.length - (pcm.length % (channels > 1 ? 4 : 2));
  int samples = bytes / (2 * channels);
  duration = samples / (float)sampleRate;
  ByteBuffer buffer = ByteBuffer.allocateDirect(bytes);
  buffer.order(ByteOrder.nativeOrder());
  buffer.put(pcm, 0, bytes);
  buffer.flip();
  if (bufferID == -1) {
    bufferID = alGenBuffers();
    alBufferData(bufferID, channels > 1 ? AL_FORMAT_STEREO16 : AL_FORMAT_MONO16, buffer.asShortBuffer(), sampleRate);
  }
}

代码示例来源:origin: google/guava

@Override
public HashCode makeHash() {
 h1 ^= length;
 h2 ^= length;
 h1 += h2;
 h2 += h1;
 h1 = fmix64(h1);
 h2 = fmix64(h2);
 h1 += h2;
 h2 += h1;
 return HashCode.fromBytesNoCopy(
   ByteBuffer.wrap(new byte[CHUNK_SIZE])
     .order(ByteOrder.LITTLE_ENDIAN)
     .putLong(h1)
     .putLong(h2)
     .array());
}

代码示例来源:origin: google/ExoPlayer

@Override
public void queueInput(ByteBuffer inputBuffer) {
 Assertions.checkState(outputChannels != null);
 int position = inputBuffer.position();
 int limit = inputBuffer.limit();
 int frameCount = (limit - position) / (2 * channelCount);
 int outputSize = frameCount * outputChannels.length * 2;
 if (buffer.capacity() < outputSize) {
  buffer = ByteBuffer.allocateDirect(outputSize).order(ByteOrder.nativeOrder());
 } else {
  buffer.clear();
 }
 while (position < limit) {
  for (int channelIndex : outputChannels) {
   buffer.putShort(inputBuffer.getShort(position + 2 * channelIndex));
  }
  position += channelCount * 2;
 }
 inputBuffer.position(limit);
 buffer.flip();
 outputBuffer = buffer;
}

代码示例来源:origin: apache/flink

@Override
public byte[] serialize(String value) {
  final byte[] serialized = value.getBytes(StandardCharsets.UTF_8);
  final byte[] targetBytes = new byte[Integer.BYTES + serialized.length];
  final ByteBuffer bb = ByteBuffer.wrap(targetBytes).order(ByteOrder.LITTLE_ENDIAN);
  bb.putInt(serialized.length);
  bb.put(serialized);
  return targetBytes;
}

代码示例来源:origin: Tencent/tinker

public DexDataBuffer() {
  this.data = ByteBuffer.allocate(DEFAULT_BUFFER_SIZE);
  this.data.order(ByteOrder.LITTLE_ENDIAN);
  this.dataBound = this.data.position();
  this.data.limit(this.data.capacity());
  this.isResizeAllowed = true;
}

代码示例来源:origin: google/guava

@Override
public HashCode hashLong(long input) {
 return hashBytes(ByteBuffer.allocate(8).order(ByteOrder.LITTLE_ENDIAN).putLong(input).array());
}

代码示例来源:origin: h2oai/h2o-2

/** Read from a fixed byte[]; should not be closed. */
AutoBuffer( byte[] buf, int off ) {
 assert buf != null : "null fed to ByteBuffer.wrap";
 _bb = ByteBuffer.wrap(buf).order(ByteOrder.nativeOrder());
 _bb.position(off);
 _chan = null;
 _h2o = null;
 _read = true;
 _firstPage = true;
 _persist = 0;               // No persistance
}

代码示例来源:origin: apache/hive

public Binary toBinary() {
 ByteBuffer buf = ByteBuffer.allocate(12);
 buf.order(ByteOrder.LITTLE_ENDIAN);
 buf.putLong(timeOfDayNanos);
 buf.putInt(julianDay);
 buf.flip();
 return Binary.fromByteBuffer(buf);
}

代码示例来源:origin: google/ExoPlayer

/**
 * Initializes the buffer.
 *
 * @param timeUs The presentation timestamp for the buffer, in microseconds.
 * @param size An upper bound on the size of the data that will be written to the buffer.
 * @return The {@link #data} buffer, for convenience.
 */
public ByteBuffer init(long timeUs, int size) {
 this.timeUs = timeUs;
 if (data == null || data.capacity() < size) {
  data = ByteBuffer.allocateDirect(size).order(ByteOrder.nativeOrder());
 }
 data.position(0);
 data.limit(size);
 return data;
}

代码示例来源:origin: google/guava

/**
 * Gets a byte array representation of this instance.
 *
 * <p><b>Note:</b> No guarantees are made regarding stability of the representation between
 * versions.
 */
public byte[] toByteArray() {
 ByteBuffer buff = ByteBuffer.allocate(BYTES).order(ByteOrder.LITTLE_ENDIAN);
 writeTo(buff);
 return buff.array();
}

代码示例来源:origin: google/guava

/**
 * Gets a byte array representation of this instance.
 *
 * <p><b>Note:</b> No guarantees are made regarding stability of the representation between
 * versions.
 */
public byte[] toByteArray() {
 ByteBuffer buffer = ByteBuffer.allocate(BYTES).order(ByteOrder.LITTLE_ENDIAN);
 xStats.writeTo(buffer);
 yStats.writeTo(buffer);
 buffer.putDouble(sumOfProductsOfDeltas);
 return buffer.array();
}

相关文章