本文整理汇总了Java中java.nio.ByteBuffer.getInt方法的典型用法代码示例。如果您正苦于以下问题:Java ByteBuffer.getInt方法的具体用法?Java ByteBuffer.getInt怎么用?Java ByteBuffer.getInt使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.nio.ByteBuffer
的用法示例。
在下文中一共展示了ByteBuffer.getInt方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getLengthPrefixedSlice
import java.nio.ByteBuffer; //导入方法依赖的package包/类
private static ByteBuffer getLengthPrefixedSlice(ByteBuffer source) throws ApkFormatException {
if (source.remaining() < 4) {
throw new ApkFormatException(
"Remaining buffer too short to contain length of length-prefixed field"
+ ". Remaining: " + source.remaining());
}
int len = source.getInt();
if (len < 0) {
throw new IllegalArgumentException("Negative length");
} else if (len > source.remaining()) {
throw new ApkFormatException(
"Length-prefixed field longer than remaining buffer"
+ ". Field length: " + len + ", remaining: " + source.remaining());
}
return getByteBuffer(source, len);
}
示例2: validate
import java.nio.ByteBuffer; //导入方法依赖的package包/类
/**
* Checks that the ByteBuffer contains a valid, usable ICU .dat package.
* Moves the buffer position from 0 to after the data header.
*/
static boolean validate(ByteBuffer bytes) {
try {
readHeader(bytes, DATA_FORMAT, IS_ACCEPTABLE);
} catch (IOException ignored) {
return false;
}
int count = bytes.getInt(bytes.position()); // Do not move the position.
if (count <= 0) {
return false;
}
// For each item, there is one ToC entry (8 bytes) and a name string
// and a data item of at least 16 bytes.
// (We assume no data item duplicate elimination for now.)
if (bytes.position() + 4 + count * (8 + 16) > bytes.capacity()) {
return false;
}
if (!startsWithPackageName(bytes, getNameOffset(bytes, 0)) ||
!startsWithPackageName(bytes, getNameOffset(bytes, count - 1))) {
return false;
}
return true;
}
示例3: testBadBlockSize
import java.nio.ByteBuffer; //导入方法依赖的package包/类
@Test
public void testBadBlockSize() throws Exception {
if (!close || (useBrokenFlagDescriptorChecksum && !ignoreFlagDescriptorChecksum)) return;
thrown.expect(IOException.class);
thrown.expectMessage(CoreMatchers.containsString("exceeded max"));
byte[] compressed = compressedBytes();
final ByteBuffer buffer = ByteBuffer.wrap(compressed).order(ByteOrder.LITTLE_ENDIAN);
int blockSize = buffer.getInt(7);
blockSize = (blockSize & LZ4_FRAME_INCOMPRESSIBLE_MASK) | (1 << 24 & ~LZ4_FRAME_INCOMPRESSIBLE_MASK);
buffer.putInt(7, blockSize);
testDecompression(buffer);
}
示例4: testIntGet
import java.nio.ByteBuffer; //导入方法依赖的package包/类
@Test(dataProvider = "intViewProvider")
public void testIntGet(String desc, IntFunction<ByteBuffer> fbb,
Function<ByteBuffer, IntBuffer> fbi) {
ByteBuffer bb = allocate(fbb);
IntBuffer vb = fbi.apply(bb);
int o = bb.position();
for (int i = 0; i < vb.limit(); i++) {
int fromBytes = getIntFromBytes(bb, o + i * 4);
int fromMethodView = bb.getInt(o + i * 4);
assertValues(i, fromBytes, fromMethodView, bb);
int fromBufferView = vb.get(i);
assertValues(i, fromMethodView, fromBufferView, bb, vb);
}
for (int i = 0; i < vb.limit(); i++) {
int v = getIntFromBytes(bb, o + i * 4);
int a = bb.getInt();
assertValues(i, v, a, bb);
int b = vb.get();
assertValues(i, a, b, bb, vb);
}
}
示例5: CRCCheck
import java.nio.ByteBuffer; //导入方法依赖的package包/类
/**
* Check if the CRC of the snapshot file matches the digest.
* @param f The snapshot file object
* @return The table list as a string
* @throws IOException If CRC does not match
*/
public static String CRCCheck(File f) throws IOException {
final FileInputStream fis = new FileInputStream(f);
try {
final BufferedInputStream bis = new BufferedInputStream(fis);
ByteBuffer crcBuffer = ByteBuffer.allocate(4);
if (4 != bis.read(crcBuffer.array())) {
throw new EOFException("EOF while attempting to read CRC from snapshot digest");
}
final int crc = crcBuffer.getInt();
final InputStreamReader isr = new InputStreamReader(bis, "UTF-8");
CharArrayWriter caw = new CharArrayWriter();
while (true) {
int nextChar = isr.read();
if (nextChar == -1) {
throw new EOFException("EOF while reading snapshot digest");
}
if (nextChar == '\n') {
break;
}
caw.write(nextChar);
}
String tableList = caw.toString();
byte tableListBytes[] = tableList.getBytes("UTF-8");
CRC32 tableListCRC = new CRC32();
tableListCRC.update(tableListBytes);
tableListCRC.update("\n".getBytes("UTF-8"));
final int calculatedValue = (int)tableListCRC.getValue();
if (crc != calculatedValue) {
throw new IOException("CRC of snapshot digest did not match digest contents");
}
return tableList;
} finally {
try {
if (fis != null)
fis.close();
} catch (IOException e) {}
}
}
示例6: DefaultSessionIdGenerator
import java.nio.ByteBuffer; //导入方法依赖的package包/类
public DefaultSessionIdGenerator(String s, boolean babble) {
if (!isValid(s))
throw new IllegalArgumentException("invalid ObjectId [" + s + "]");
if (babble)
s = babbleToMongod(s);
byte b[] = new byte[12];
for (int i = 0; i < b.length; i++) {
b[i] = (byte) Integer.parseInt(s.substring(i * 2, i * 2 + 2), 16);
}
ByteBuffer bb = ByteBuffer.wrap(b);
_time = bb.getInt();
_machine = bb.getInt();
_inc = bb.getInt();
_new = false;
}
示例7: putData
import java.nio.ByteBuffer; //导入方法依赖的package包/类
private void putData(ByteBuffer input, ByteBuffer output) {
int id = input.getInt();
int size = input.getInt();
byte[] entity = new byte[size];
try {
input.get(entity);
} catch (BufferUnderflowException bue) {
}
publish(id, entity);
System.out.println("Bytes sent into the data server: ");
/*ByteBuffer buf = ByteBuffer.wrap(entity);
while (true) {
try {
System.out.println("" + buf.get() + " " + buf.get() + " " + buf.get() + " " + buf.get());
} catch (BufferUnderflowException bue) {
break;
}
}*/
}
示例8: deserializer
import java.nio.ByteBuffer; //导入方法依赖的package包/类
/**
* Deserializer function for neighbor solicitation packets.
*
* @return deserializer function
*/
public static Deserializer<NeighborSolicitation> deserializer() {
return (data, offset, length) -> {
checkInput(data, offset, length, HEADER_LENGTH);
NeighborSolicitation neighborSolicitation = new NeighborSolicitation();
ByteBuffer bb = ByteBuffer.wrap(data, offset, length);
bb.getInt();
bb.get(neighborSolicitation.targetAddress, 0, Ip6Address.BYTE_LENGTH);
if (bb.limit() - bb.position() > 0) {
NeighborDiscoveryOptions options = NeighborDiscoveryOptions.deserializer()
.deserialize(data, bb.position(), bb.limit() - bb.position());
for (NeighborDiscoveryOptions.Option option : options.options()) {
neighborSolicitation.addOption(option.type(), option.data());
}
}
return neighborSolicitation;
};
}
示例9: deserialize
import java.nio.ByteBuffer; //导入方法依赖的package包/类
/**
* {@inheritDoc}
*/
public byte[] deserialize( ByteBuffer buffer ) throws IOException
{
int len = buffer.getInt();
switch ( len )
{
case 0:
return new byte[]
{};
case -1:
return null;
default:
byte[] bytes = new byte[len];
buffer.get( bytes );
return bytes;
}
}
示例10: alignedReadSnippet
import java.nio.ByteBuffer; //导入方法依赖的package包/类
Ret alignedReadSnippet(byte[] arg) {
ByteBuffer buffer = makeDirect(arg, byteOrder);
Ret ret = new Ret();
ret.byteValue = buffer.get();
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;
}
示例11: XmlStartElementChunk
import java.nio.ByteBuffer; //导入方法依赖的package包/类
protected XmlStartElementChunk(ByteBuffer buffer, @Nullable Chunk parent) {
super(buffer, parent);
namespace = buffer.getInt();
name = buffer.getInt();
attributeStart = (buffer.getShort() & 0xFFFF);
int attributeSize = (buffer.getShort() & 0xFFFF);
Preconditions
.checkState(attributeSize == XmlAttribute.SIZE, "attributeSize is wrong size. Got %s, want %s", attributeSize, XmlAttribute.SIZE);
attributeCount = (buffer.getShort() & 0xFFFF);
// The following indices are 1-based and need to be adjusted.
idIndex = (buffer.getShort() & 0xFFFF) - 1;
classIndex = (buffer.getShort() & 0xFFFF) - 1;
styleIndex = (buffer.getShort() & 0xFFFF) - 1;
}
示例12: loadAllReferences
import java.nio.ByteBuffer; //导入方法依赖的package包/类
public void loadAllReferences() {
try {
RandomAccessFile raf = new RandomAccessFile(daaFile, "r");
try {
raf.seek(getLocationOfBlockInFile(refNamesBlockIndex));
referenceNames = new byte[(int) dbSeqsUsed][];
referenceLocations = new long[1 + ((int) dbSeqsUsed >>> referenceLocationChunkBits)];
for (int i = 0; i < (int) dbSeqsUsed; i++) {
if ((i & (referenceLocationChunkSize - 1)) == 0) {
referenceLocations[i >>> referenceLocationChunkBits] = raf.getFilePointer();
}
int c = raf.read();
while (c != 0)
c = raf.read();
}
refLengths = new int[(int) dbSeqsUsed];
for (int i = 0; i < dbSeqsUsed; i++) {
ByteBuffer buffer = ByteBuffer.allocate(4);
buffer.order(ByteOrder.LITTLE_ENDIAN);
raf.read(buffer.array());
refLengths[i] = buffer.getInt();
}
} finally {
raf.close();
}
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
示例13: decode1
import java.nio.ByteBuffer; //导入方法依赖的package包/类
@Override
public Document decode1(ByteBuffer buffer) {
String id = readString(buffer);
Document result = Document.getDocument(this, corpus, id);
sectionDecoder.setDoc(result);
int nSec = buffer.getInt();
for (int i = 0; i < nSec; ++i) {
int secRef = buffer.getInt();
sectionUnmarshaller.read(secRef);
}
return result;
}
示例14: parse
import java.nio.ByteBuffer; //导入方法依赖的package包/类
/***
* 解析数据包
*
* @param buffer
* @param offset
* @return
* @throws IllegalArgumentException
*/
public static BackendKeyData parse(ByteBuffer buffer, int offset) {
if (buffer.get(offset) != PacketMarker.B_BackendKey.getValue()) {
throw new IllegalArgumentException("this packet not is BackendKeyData");
}
BackendKeyData pac = new BackendKeyData();
pac.length = buffer.getInt(offset + 1);
pac.pid = buffer.getInt(offset + 1 + 4);
pac.secretKey = buffer.getInt(offset + 1 + 4 + 4);
return pac;
}
示例15: seekToParameterSet
import java.nio.ByteBuffer; //导入方法依赖的package包/类
public static void seekToParameterSet(ByteBuffer buffer) {
// Skip to the procedure name
//buffer.position(14); // modified by hawk, 2014-3-7
buffer.position(22);
int procNameLen = buffer.getInt();
buffer.position(buffer.position() + procNameLen);
}