本文整理汇总了Java中java.nio.ByteBuffer.getShort方法的典型用法代码示例。如果您正苦于以下问题:Java ByteBuffer.getShort方法的具体用法?Java ByteBuffer.getShort怎么用?Java ByteBuffer.getShort使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.nio.ByteBuffer
的用法示例。
在下文中一共展示了ByteBuffer.getShort方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: ChmFtsHeader
import java.nio.ByteBuffer; //导入方法依赖的package包/类
ChmFtsHeader(ByteBuffer bb) throws IOException {
ByteBufferHelper.skip(bb, 0x14);
nodeOffset = bb.getInt();
treeDepth = bb.getShort();
ByteBufferHelper.skip(bb, 4);
docIndexS = bb.get();
docIndexR = bb.get();
codeCountS = bb.get();
codeCountR = bb.get();
locCodesS = bb.get();
locCodesR = bb.get();
ByteBufferHelper.skip(bb, 10);
nodeLen = bb.getInt();
ByteBufferHelper.skip(bb, 12);
maxWordLen = bb.getInt();
}
示例2: deserialize
import java.nio.ByteBuffer; //导入方法依赖的package包/类
@Override
public IPacket deserialize(byte[] data, int offset, int length) {
final ByteBuffer bb = ByteBuffer.wrap(data, offset, length);
this.nextHeader = bb.get();
bb.get();
short sscratch = bb.getShort();
this.fragmentOffset = (short) (sscratch >> 3 & 0x1fff);
this.moreFragment = (byte) (sscratch & 0x1);
this.identification = bb.getInt();
Deserializer<? extends IPacket> deserializer;
if (IPv6.PROTOCOL_DESERIALIZER_MAP.containsKey(this.nextHeader)) {
deserializer = IPv6.PROTOCOL_DESERIALIZER_MAP.get(this.nextHeader);
} else {
deserializer = Data.deserializer();
}
try {
this.payload = deserializer.deserialize(data, bb.position(),
bb.limit() - bb.position());
this.payload.setParent(this);
} catch (DeserializationException e) {
return this;
}
return this;
}
示例3: verifyPFB
import java.nio.ByteBuffer; //导入方法依赖的package包/类
private void verifyPFB(ByteBuffer bb) throws FontFormatException {
int pos = 0;
while (true) {
try {
int segType = bb.getShort(pos) & 0xffff;
if (segType == 0x8001 || segType == 0x8002) {
bb.order(ByteOrder.LITTLE_ENDIAN);
int segLen = bb.getInt(pos+2);
bb.order(ByteOrder.BIG_ENDIAN);
if (segLen <= 0) {
throw new FontFormatException("bad segment length");
}
pos += segLen+6;
} else if (segType == 0x8003) {
return;
} else {
throw new FontFormatException("bad pfb file");
}
} catch (BufferUnderflowException bue) {
throw new FontFormatException(bue.toString());
} catch (Exception e) {
throw new FontFormatException(e.toString());
}
}
}
示例4: newInstance
import java.nio.ByteBuffer; //导入方法依赖的package包/类
@Nullable
private static Entry newInstance(ByteBuffer buffer, TypeChunk parent) {
int headerSize = buffer.getShort() & 0xFFFF;
int flags = buffer.getShort() & 0xFFFF;
int keyIndex = buffer.getInt();
ResourceValue value = null;
Map<Integer, ResourceValue> values = new LinkedHashMap<>();
int parentEntry = 0;
if ((flags & FLAG_COMPLEX) != 0) {
parentEntry = buffer.getInt(); //2131427792
int valueCount = buffer.getInt();
for (int i = 0; i < valueCount; ++i) {
values.put(buffer.getInt(), ResourceValue.create(buffer));
}
} else {
value = ResourceValue.create(buffer);
}
return new AutoValue_TypeChunk_Entry(headerSize, flags, keyIndex, value, values, parentEntry, parent);
}
示例5: parseTypeAnnotations
import java.nio.ByteBuffer; //导入方法依赖的package包/类
private static TypeAnnotation[] parseTypeAnnotations(byte[] rawAnnotations,
ConstantPool cp,
AnnotatedElement baseDecl,
Class<?> container) {
if (rawAnnotations == null)
return EMPTY_TYPE_ANNOTATION_ARRAY;
ByteBuffer buf = ByteBuffer.wrap(rawAnnotations);
int annotationCount = buf.getShort() & 0xFFFF;
List<TypeAnnotation> typeAnnotations = new ArrayList<>(annotationCount);
// Parse each TypeAnnotation
for (int i = 0; i < annotationCount; i++) {
TypeAnnotation ta = parseTypeAnnotation(buf, cp, baseDecl, container);
if (ta != null)
typeAnnotations.add(ta);
}
return typeAnnotations.toArray(EMPTY_TYPE_ANNOTATION_ARRAY);
}
示例6: parseCharArray
import java.nio.ByteBuffer; //导入方法依赖的package包/类
private static Object parseCharArray(int length,
ByteBuffer buf, ConstantPool constPool) {
char[] result = new char[length];
boolean typeMismatch = false;
byte tag = 0;
for (int i = 0; i < length; i++) {
tag = buf.get();
if (tag == 'C') {
int index = buf.getShort() & 0xFFFF;
result[i] = (char) constPool.getIntAt(index);
} else {
skipMemberValue(tag, buf);
typeMismatch = true;
}
}
return typeMismatch ? exceptionProxy(tag) : result;
}
示例7: mapDeserialize
import java.nio.ByteBuffer; //导入方法依赖的package包/类
public static HashMap<String, String> mapDeserialize(byte[] bytes) {
if (bytes == null || bytes.length <= 0)
return null;
HashMap<String, String> map = new HashMap<String, String>();
ByteBuffer byteBuffer = ByteBuffer.wrap(bytes);
short keySize = 0;
byte[] keyContent = null;
int valSize = 0;
byte[] valContent = null;
while (byteBuffer.hasRemaining()) {
keySize = byteBuffer.getShort();
keyContent = new byte[keySize];
byteBuffer.get(keyContent);
valSize = byteBuffer.getInt();
valContent = new byte[valSize];
byteBuffer.get(valContent);
map.put(new String(keyContent, RemotingSerializable.CHARSET_UTF8), new String(valContent,
RemotingSerializable.CHARSET_UTF8));
}
return map;
}
示例8: parseIntArray
import java.nio.ByteBuffer; //导入方法依赖的package包/类
private static Object parseIntArray(int length,
ByteBuffer buf, ConstantPool constPool) {
int[] result = new int[length];
boolean typeMismatch = false;
int tag = 0;
for (int i = 0; i < length; i++) {
tag = buf.get();
if (tag == 'I') {
int index = buf.getShort() & 0xFFFF;
result[i] = constPool.getIntAt(index);
} else {
skipMemberValue(tag, buf);
typeMismatch = true;
}
}
return typeMismatch ? exceptionProxy(tag) : result;
}
示例9: byteArrayToShort
import java.nio.ByteBuffer; //导入方法依赖的package包/类
/**
* byte[] to short
*
* @param bytes array must is 1 ~ 2 bytes. little endian
* @return short value
*/
public static short byteArrayToShort(byte[] bytes)
{
Short newValue;
ByteBuffer temp = ByteBuffer.wrap(bytes);
temp.order(ByteOrder.LITTLE_ENDIAN);
newValue = temp.getShort();
return newValue;
}
示例10: skipAnnotation
import java.nio.ByteBuffer; //导入方法依赖的package包/类
/**
* Skips the annotation at the current position in the specified
* byte buffer. The cursor of the byte buffer must point to
* an "annotation structure" OR two bytes into an annotation
* structure (i.e., after the type index).
*
* @parameter complete true if the byte buffer points to the beginning
* of an annotation structure (rather than two bytes in).
*/
private static void skipAnnotation(ByteBuffer buf, boolean complete) {
if (complete)
buf.getShort(); // Skip type index
int numMembers = buf.getShort() & 0xFFFF;
for (int i = 0; i < numMembers; i++) {
buf.getShort(); // Skip memberNameIndex
skipMemberValue(buf);
}
}
示例11: binDecode_SHORT_ARRAY
import java.nio.ByteBuffer; //导入方法依赖的package包/类
private DataWrapper binDecode_SHORT_ARRAY(ByteBuffer buffer) throws CodecException {
short arraySize = this.getTypeArraySize(buffer);
ArrayList<Short> array = new ArrayList<Short>();
for (int j = 0; j < arraySize; ++j) {
short shortValue = buffer.getShort();
array.add(Short.valueOf(shortValue));
}
return new DataWrapper(DataType.SHORT_ARRAY, array);
}
示例12: ComplexBlock
import java.nio.ByteBuffer; //导入方法依赖的package包/类
public ComplexBlock(ByteBuffer bb)
{
_data = new short[IBlock.BLOCK_CELLS];
for (int cellOffset = 0; cellOffset < IBlock.BLOCK_CELLS; cellOffset++)
{
_data[cellOffset] = bb.getShort();
}
}
示例13: create
import java.nio.ByteBuffer; //导入方法依赖的package包/类
static ResourceConfiguration create(ByteBuffer buffer) {
int startPosition = buffer.position(); // The starting buffer position to calculate bytes read.
int size = buffer.getInt();
int mcc = buffer.getShort() & 0xFFFF;
int mnc = buffer.getShort() & 0xFFFF;
byte[] language = new byte[2];
buffer.get(language);
byte[] region = new byte[2];
buffer.get(region);
int orientation = UnsignedBytes.toInt(buffer.get());
int touchscreen = UnsignedBytes.toInt(buffer.get());
int density = buffer.getShort() & 0xFFFF;
int keyboard = UnsignedBytes.toInt(buffer.get());
int navigation = UnsignedBytes.toInt(buffer.get());
int inputFlags = UnsignedBytes.toInt(buffer.get());
buffer.get(); // 1 byte of padding
int screenWidth = buffer.getShort() & 0xFFFF;
int screenHeight = buffer.getShort() & 0xFFFF;
int sdkVersion = buffer.getShort() & 0xFFFF;
int minorVersion = buffer.getShort() & 0xFFFF;
// At this point, the configuration's size needs to be taken into account as not all
// configurations have all values.
int screenLayout = 0;
int uiMode = 0;
int smallestScreenWidthDp = 0;
int screenWidthDp = 0;
int screenHeightDp = 0;
byte[] localeScript = new byte[4];
byte[] localeVariant = new byte[8];
int screenLayout2 = 0;
if (size >= SCREEN_CONFIG_MIN_SIZE) {
screenLayout = UnsignedBytes.toInt(buffer.get());
uiMode = UnsignedBytes.toInt(buffer.get());
smallestScreenWidthDp = buffer.getShort() & 0xFFFF;
}
if (size >= SCREEN_DP_MIN_SIZE) {
screenWidthDp = buffer.getShort() & 0xFFFF;
screenHeightDp = buffer.getShort() & 0xFFFF;
}
if (size >= LOCALE_MIN_SIZE) {
buffer.get(localeScript);
buffer.get(localeVariant);
}
if (size >= SCREEN_CONFIG_EXTENSION_MIN_SIZE) {
screenLayout2 = UnsignedBytes.toInt(buffer.get());
buffer.get(); // Reserved padding
buffer.getShort(); // More reserved padding
}
// After parsing everything that's known, account for anything that's unknown.
int bytesRead = buffer.position() - startPosition;
byte[] unknown = new byte[size - bytesRead];
buffer.get(unknown);
return new AutoValue_ResourceConfiguration(size, mcc, mnc, language, region, orientation,
touchscreen, density, keyboard, navigation, inputFlags, screenWidth, screenHeight,
sdkVersion, minorVersion, screenLayout, uiMode, smallestScreenWidthDp, screenWidthDp,
screenHeightDp, localeScript, localeVariant, screenLayout2, unknown);
}
示例14: getUnsignedInt16
import java.nio.ByteBuffer; //导入方法依赖的package包/类
public static int getUnsignedInt16(ByteBuffer buffer) {
return buffer.getShort() & 0xffff;
}
示例15: socks5rawSocketConnection
import java.nio.ByteBuffer; //导入方法依赖的package包/类
public static Socket socks5rawSocketConnection(String networkHost, int networkPort, String socksHost, int socksPort)
throws IOException {
int bytesRead = 0;
boolean end = false;
String messageString = "";
final byte[] messageByte = new byte[1000];
Socket socket = new Socket();
socket.setSoTimeout(READ_TIMEOUT_MILLISECONDS);
SocketAddress socksAddress = new InetSocketAddress(socksHost, socksPort);
socket.connect(socksAddress, CONNECT_TIMEOUT_MILLISECONDS);
DataOutputStream outputStream = new DataOutputStream(socket.getOutputStream());
outputStream.write((byte) 0x05);
outputStream.write((byte) 0x01);
outputStream.write((byte) 0x00);
outputStream.write((byte) 0x01);
outputStream.write(networkHost.getBytes());
outputStream.writeShort((short) networkPort);
DataInputStream inputStream = new DataInputStream(socket.getInputStream());
messageByte[0] = inputStream.readByte();
messageByte[1] = inputStream.readByte();
if (messageByte[0] != (byte) 0x05 || messageByte[1] != (byte) 0x00) {
socket.close();
throw new IOException("SOCKS4a connect failed, got " + messageByte[0] + " - " + messageByte[1] +
", but expected 0x00 - 0x5a");
}
ByteBuffer byteBuffer = ByteBuffer.wrap(messageByte, 0, 2);
int bytesToRead = byteBuffer.getShort();
LOG.info("About to read " + bytesToRead + " octets");
while (!end) {
bytesRead = inputStream.read(messageByte);
messageString += new String(messageByte, 0, bytesRead);
if (messageString.length() == bytesToRead) {
end = true;
}
}
return socket;
}