本文整理汇总了Java中java.nio.ByteBuffer.get方法的典型用法代码示例。如果您正苦于以下问题:Java ByteBuffer.get方法的具体用法?Java ByteBuffer.get怎么用?Java ByteBuffer.get使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.nio.ByteBuffer
的用法示例。
在下文中一共展示了ByteBuffer.get方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: onReadCompleted
import java.nio.ByteBuffer; //导入方法依赖的package包/类
@Override
public void onReadCompleted(UrlRequest request, UrlResponseInfo info, ByteBuffer byteBuffer) {
assertEquals(mExecutorThread, Thread.currentThread());
assertFalse(request.isDone());
assertTrue(mResponseStep == ResponseStep.ON_RESPONSE_STARTED
|| mResponseStep == ResponseStep.ON_READ_COMPLETED);
assertNull(mError);
mResponseStep = ResponseStep.ON_READ_COMPLETED;
final byte[] lastDataReceivedAsBytes;
final int bytesRead = byteBuffer.position() - mBufferPositionBeforeRead;
mHttpResponseDataLength += bytesRead;
lastDataReceivedAsBytes = new byte[bytesRead];
// Rewind |byteBuffer.position()| to pre-read() position.
byteBuffer.position(mBufferPositionBeforeRead);
// This restores |byteBuffer.position()| to its value on entrance to
// this function.
byteBuffer.get(lastDataReceivedAsBytes);
mResponseAsString += new String(lastDataReceivedAsBytes);
if (maybeThrowCancelOrPause(request)) {
return;
}
startNextRead(request);
}
示例2: IP4Header
import java.nio.ByteBuffer; //导入方法依赖的package包/类
private IP4Header(ByteBuffer buffer) throws UnknownHostException
{
byte versionAndIHL = buffer.get();
this.version = (byte) (versionAndIHL >> 4);
this.IHL = (byte) (versionAndIHL & 0x0F);
this.headerLength = this.IHL << 2;
this.typeOfService = BitUtils.getUnsignedByte(buffer.get());
this.totalLength = BitUtils.getUnsignedShort(buffer.getShort());
this.identificationAndFlagsAndFragmentOffset = buffer.getInt();
this.TTL = BitUtils.getUnsignedByte(buffer.get());
this.protocolNum = BitUtils.getUnsignedByte(buffer.get());
this.protocol = TransportProtocol.numberToEnum(protocolNum);
this.headerChecksum = BitUtils.getUnsignedShort(buffer.getShort());
byte[] addressBytes = new byte[4];
buffer.get(addressBytes, 0, 4);
this.sourceAddress = InetAddress.getByAddress(addressBytes);
buffer.get(addressBytes, 0, 4);
this.destinationAddress = InetAddress.getByAddress(addressBytes);
//this.optionsAndPadding = buffer.getInt();
}
示例3: deserialize
import java.nio.ByteBuffer; //导入方法依赖的package包/类
/**
* {@inheritDoc}
*/
@Override
public RevisionName deserialize( ByteBuffer buffer ) throws IOException
{
// The revision
long revision = buffer.getLong();
// The name's length
int len = buffer.getInt();
switch ( len )
{
case 0:
return new RevisionName( revision, "" );
case -1:
return new RevisionName( revision, null );
default:
byte[] nameBytes = new byte[len];
buffer.get( nameBytes );
return new RevisionName( revision, Strings.utf8ToString( nameBytes ) );
}
}
示例4: alignedWriteSnippet
import java.nio.ByteBuffer; //导入方法依赖的package包/类
byte[] alignedWriteSnippet(byte a, byte b, short c, int d, long e, double f, float g) {
byte[] ret = new byte[28];
ByteBuffer buffer = makeDirect(28, byteOrder);
buffer.put(a);
buffer.put(b);
buffer.putShort(c);
buffer.putInt(d);
buffer.putLong(e);
buffer.putDouble(f);
buffer.putFloat(g);
buffer.position(0);
buffer.get(ret);
return ret;
}
示例5: append
import java.nio.ByteBuffer; //导入方法依赖的package包/类
public void append(char c)
{
if(validChar(c))
{
str.append(c);
}else
{
cb.clear();
cb.put(c);
cb.flip();
ByteBuffer out=StandardCharsets.UTF_8.encode(cb);
while(out.hasRemaining())
{
str.append("\\\\x");
bs[0]=out.get();
str.append(UtilString.toHexPadZero(bs));
}
}
}
示例6: rocketMQProtocolDecode
import java.nio.ByteBuffer; //导入方法依赖的package包/类
public static RemotingCommand rocketMQProtocolDecode(final byte[] headerArray) {
RemotingCommand cmd = new RemotingCommand();
ByteBuffer headerBuffer = ByteBuffer.wrap(headerArray);
// int code(~32767)
cmd.setCode(headerBuffer.getShort());
// LanguageCode language
cmd.setLanguage(LanguageCode.valueOf(headerBuffer.get()));
// int version(~32767)
cmd.setVersion(headerBuffer.getShort());
// int opaque
cmd.setOpaque(headerBuffer.getInt());
// int flag
cmd.setFlag(headerBuffer.getInt());
// String remark
int remarkLength = headerBuffer.getInt();
if (remarkLength > 0) {
byte[] remarkContent = new byte[remarkLength];
headerBuffer.get(remarkContent);
cmd.setRemark(new String(remarkContent, CHARSET_UTF8));
}
// HashMap<String, String> extFields
int extFieldsLength = headerBuffer.getInt();
if (extFieldsLength > 0) {
byte[] extFieldsBytes = new byte[extFieldsLength];
headerBuffer.get(extFieldsBytes);
cmd.setExtFields(mapDeserialize(extFieldsBytes));
}
return cmd;
}
示例7: compare
import java.nio.ByteBuffer; //导入方法依赖的package包/类
public int compare(ByteBuffer buffer1, ByteBuffer buffer2)
{
int end1 = buffer1.limit();
int end2 = buffer2.limit();
for (int i = buffer1.position(), j = buffer2.position(); i < end1 && j < end2; i++, j++)
{
int a = (buffer1.get(i) & 0xff);
int b = (buffer2.get(j) & 0xff);
if (a != b)
{
return a - b;
}
}
return buffer1.remaining() - buffer2.remaining();
}
示例8: unalignedReadSnippet
import java.nio.ByteBuffer; //导入方法依赖的package包/类
Ret unalignedReadSnippet(byte[] arg) {
ByteBuffer buffer = makeDirect(arg, byteOrder);
Ret ret = new Ret();
ret.byteValue = buffer.get();
ret.shortValue = buffer.getShort();
ret.intValue = buffer.getInt();
ret.longValue = buffer.getLong();
ret.doubleValue = buffer.getDouble();
ret.floatValue = buffer.getFloat();
return ret;
}
示例9: compressBuffer
import java.nio.ByteBuffer; //导入方法依赖的package包/类
public static byte[] compressBuffer(ByteBuffer buffer) throws IOException {
assert(buffer.isDirect());
IOBuffers buffers = getBuffersForCompression(buffer.remaining(), true);
ByteBuffer output = buffers.output;
final int compressedSize = Snappy.compress(buffer, output);
byte result[] = new byte[compressedSize];
output.get(result);
return result;
}
示例10: initAllNames
import java.nio.ByteBuffer; //导入方法依赖的package包/类
protected void initAllNames(int requestedID, HashSet names) {
byte[] name = new byte[256];
ByteBuffer buffer = getTableBuffer(nameTag);
if (buffer != null) {
ShortBuffer sbuffer = buffer.asShortBuffer();
sbuffer.get(); // format - not needed.
short numRecords = sbuffer.get();
/* The name table uses unsigned shorts. Many of these
* are known small values that fit in a short.
* The values that are sizes or offsets into the table could be
* greater than 32767, so read and store those as ints
*/
int stringPtr = ((int) sbuffer.get()) & 0xffff;
for (int i=0; i<numRecords; i++) {
short platformID = sbuffer.get();
if (platformID != MS_PLATFORM_ID) {
sbuffer.position(sbuffer.position()+5);
continue; // skip over this record.
}
short encodingID = sbuffer.get();
short langID = sbuffer.get();
short nameID = sbuffer.get();
int nameLen = ((int) sbuffer.get()) & 0xffff;
int namePtr = (((int) sbuffer.get()) & 0xffff) + stringPtr;
if (nameID == requestedID) {
buffer.position(namePtr);
buffer.get(name, 0, nameLen);
names.add(makeString(name, nameLen, encodingID));
}
}
}
}
示例11: deserialize
import java.nio.ByteBuffer; //导入方法依赖的package包/类
@Override
public IPacket deserialize(byte[] data, int offset, int length) {
ByteBuffer bb = ByteBuffer.wrap(data, offset, length);
// LLC header
llcHeader.deserialize(data, offset, 3);
this.protocolId = bb.getShort();
this.version = bb.get();
this.type = bb.get();
// These fields only exist if it's a configuration BPDU
if (this.type == 0x0) {
this.flags = bb.get();
bb.get(rootBridgeId, 0, 6);
this.rootPathCost = bb.getInt();
bb.get(this.senderBridgeId, 0, 6);
this.portId = bb.getShort();
this.messageAge = bb.getShort();
this.maxAge = bb.getShort();
this.helloTime = bb.getShort();
this.forwardDelay = bb.getShort();
}
// TODO should we set other fields to 0?
return this;
}
示例12: verify
import java.nio.ByteBuffer; //导入方法依赖的package包/类
/**
* Verifies that a box can be reconstructed byte-exact after parsing.
*
* @param content the raw content of the box
* @return <code>true</code> if raw content exactly matches the reconstructed content
*/
private boolean verify(ByteBuffer content) {
ByteBuffer bb = ByteBuffer.allocate(l2i(getContentSize() + (deadBytes != null ? deadBytes.limit() : 0)));
getContent(bb);
if (deadBytes != null) {
deadBytes.rewind();
while (deadBytes.remaining() > 0) {
bb.put(deadBytes);
}
}
content.rewind();
bb.rewind();
if (content.remaining() != bb.remaining()) {
LOG.severe(this.getType() + ": remaining differs " + content.remaining() + " vs. " + bb.remaining());
return false;
}
int p = content.position();
for (int i = content.limit() - 1, j = bb.limit() - 1; i >= p; i--, j--) {
byte v1 = content.get(i);
byte v2 = bb.get(j);
if (v1 != v2) {
LOG.severe(String.format("%s: buffers differ at %d: %2X/%2X", this.getType(), i, v1, v2));
byte[] b1 = new byte[content.remaining()];
byte[] b2 = new byte[bb.remaining()];
content.get(b1);
bb.get(b2);
System.err.println("original : " + Hex.encodeHex(b1, 4));
System.err.println("reconstructed : " + Hex.encodeHex(b2, 4));
return false;
}
}
return true;
}
示例13: parse
import java.nio.ByteBuffer; //导入方法依赖的package包/类
public static EmptyQueryResponse parse(ByteBuffer buffer, int offset) {
if (buffer.get(offset) != PacketMarker.B_EmptyQueryResponse.getValue()) {
throw new IllegalArgumentException(
"this packetData not is EmptyQueryResponse");
}
int _offset = offset + 1;
EmptyQueryResponse pack = new EmptyQueryResponse();
pack.length = PIOUtils.redInteger4(buffer, _offset);
return pack;
}
示例14: writeToBytes
import java.nio.ByteBuffer; //导入方法依赖的package包/类
public byte[] writeToBytes(FrontendConnection c) {
ByteBuffer buffer = c.allocate();
this.write(buffer, c);
buffer.flip();
byte[] data = new byte[buffer.limit()];
buffer.get(data);
c.recycle(buffer);
return data;
}
示例15: toBytes
import java.nio.ByteBuffer; //导入方法依赖的package包/类
/**
* Copy the bytes from position to limit into a new byte[] of the exact length and sets the
* position and limit back to their original values (though not thread safe).
* @param buffer copy from here
* @param startPosition put buffer.get(startPosition) into byte[0]
* @return a new byte[] containing the bytes in the specified range
*/
public static byte[] toBytes(ByteBuffer buffer, int startPosition) {
int originalPosition = buffer.position();
byte[] output = new byte[buffer.limit() - startPosition];
buffer.position(startPosition);
buffer.get(output);
buffer.position(originalPosition);
return output;
}