本文整理汇总了Java中java.nio.ByteBuffer.rewind方法的典型用法代码示例。如果您正苦于以下问题:Java ByteBuffer.rewind方法的具体用法?Java ByteBuffer.rewind怎么用?Java ByteBuffer.rewind使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.nio.ByteBuffer
的用法示例。
在下文中一共展示了ByteBuffer.rewind方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: growBuffer
import java.nio.ByteBuffer; //导入方法依赖的package包/类
private void growBuffer(int p_181670_1_)
{
if (MathHelper.roundUp(p_181670_1_, 4) / 4 > this.rawIntBuffer.remaining() || this.vertexCount * this.vertexFormat.getNextOffset() + p_181670_1_ > this.byteBuffer.capacity())
{
int i = this.byteBuffer.capacity();
int j = i + MathHelper.roundUp(p_181670_1_, 2097152);
LOGGER.debug("Needed to grow BufferBuilder buffer: Old size {} bytes, new size {} bytes.", new Object[] {Integer.valueOf(i), Integer.valueOf(j)});
int k = this.rawIntBuffer.position();
ByteBuffer bytebuffer = GLAllocation.createDirectByteBuffer(j);
this.byteBuffer.position(0);
bytebuffer.put(this.byteBuffer);
bytebuffer.rewind();
this.byteBuffer = bytebuffer;
this.rawFloatBuffer = this.byteBuffer.asFloatBuffer().asReadOnlyBuffer();
this.rawIntBuffer = this.byteBuffer.asIntBuffer();
this.rawIntBuffer.position(k);
this.rawShortBuffer = this.byteBuffer.asShortBuffer();
this.rawShortBuffer.position(k << 1);
}
}
示例2: serialize
import java.nio.ByteBuffer; //导入方法依赖的package包/类
public byte[] serialize(String topic, ByteBuffer data) {
if (data == null)
return null;
data.rewind();
if (data.hasArray()) {
byte[] arr = data.array();
if (data.arrayOffset() == 0 && arr.length == data.remaining()) {
return arr;
}
}
byte[] ret = new byte[data.remaining()];
data.get(ret, 0, ret.length);
data.rewind();
return ret;
}
示例3: calculateChecksumOverPage
import java.nio.ByteBuffer; //导入方法依赖的package包/类
/**
* Calculate checkSum over the Page
*
* @param page
*/
private void calculateChecksumOverPage(ByteBuffer page)
{
//CRC should be zero before calculating it
page.putInt(OggPageHeader.FIELD_PAGE_CHECKSUM_POS, 0);
//Compute CRC over the page //TODO shouldnt really use array();
byte[] crc = OggCRCFactory.computeCRC(page.array());
for (int i = 0; i < crc.length; i++)
{
page.put(OggPageHeader.FIELD_PAGE_CHECKSUM_POS + i, crc[i]);
}
//Rewind to start of Page
page.rewind();
}
示例4: verify
import java.nio.ByteBuffer; //导入方法依赖的package包/类
/**
* Verifies the given secp256k1 signature in native code. Calling when enabled == false is undefined (probably
* library not loaded)
*
* @param data The data which was signed, must be exactly 32 bytes
* @param signature The signature
* @param pub The public key which did the signing
*/
public static boolean verify(byte[] data, byte[] signature, byte[] pub) throws AssertFailException {
Preconditions.checkArgument(data.length == 32 && signature.length <= 520 && pub.length <= 520);
ByteBuffer byteBuff = nativeECDSABuffer.get();
if (byteBuff == null || byteBuff.capacity() < 520) {
byteBuff = ByteBuffer.allocateDirect(520);
byteBuff.order(ByteOrder.nativeOrder());
nativeECDSABuffer.set(byteBuff);
}
byteBuff.rewind();
byteBuff.put(data);
byteBuff.put(signature);
byteBuff.put(pub);
r.lock();
try {
return secp256k1_ecdsa_verify(byteBuff, Secp256k1Context.getContext(), signature.length, pub.length) == 1;
} finally {
r.unlock();
}
}
示例5: createLargeFile
import java.nio.ByteBuffer; //导入方法依赖的package包/类
private static void createLargeFile(long filesize,
File file) throws Exception {
// Recreate a large file as a sparse file if possible
Files.delete(file.toPath());
try (FileChannel fc =
FileChannel.open(file.toPath(),
CREATE_NEW, WRITE, SPARSE)) {
ByteBuffer bb = ByteBuffer.allocate(1).put((byte)1);
bb.rewind();
System.out.println(" Writing large file...");
long t0 = System.nanoTime();
int rc = fc.write(bb, filesize - 1);
long t1 = System.nanoTime();
System.out.printf(" Wrote large file in %d ns (%d ms) %n",
t1 - t0, TimeUnit.NANOSECONDS.toMillis(t1 - t0));
if (rc != 1) {
throw new RuntimeException("Failed to write 1 byte"
+ " to the large file");
}
}
return;
}
示例6: main
import java.nio.ByteBuffer; //导入方法依赖的package包/类
public static void main(String[] args) {
ByteBuffer bb=ByteBuffer.allocate(BSIZE);
int i=0;
while (i++<bb.limit()){
if(bb.get()!=0){
print("nonzero");
}
print("i="+i);
}
bb.rewind();
bb.asCharBuffer().put("Howdy!");
char c;
while ((c=bb.getChar())!=0){
printnb(c+"");
}
print();
bb.rewind();
bb.asShortBuffer().put((short)471142);
print(bb.getShort());
bb.rewind();
bb.asIntBuffer().put(99471142);
print(bb.getShort());
bb.rewind();
bb.asLongBuffer().put(99471142);
print(bb.getLong());
bb.rewind();
bb.asFloatBuffer().put(99471142);
print(bb.getFloat());
bb.rewind();
bb.asDoubleBuffer().put(99471142);
print(bb.getDouble());
bb.rewind();
}
示例7: func_181670_b
import java.nio.ByteBuffer; //导入方法依赖的package包/类
private void func_181670_b(int p_181670_1_)
{
if (Config.isShaders())
{
p_181670_1_ *= 2;
}
if (p_181670_1_ > this.rawIntBuffer.remaining())
{
int i = this.byteBuffer.capacity();
int j = i % 2097152;
int k = j + (((this.rawIntBuffer.position() + p_181670_1_) * 4 - j) / 2097152 + 1) * 2097152;
LogManager.getLogger().warn("Needed to grow BufferBuilder buffer: Old size " + i + " bytes, new size " + k + " bytes.");
int l = this.rawIntBuffer.position();
ByteBuffer bytebuffer = GLAllocation.createDirectByteBuffer(k);
this.byteBuffer.position(0);
bytebuffer.put(this.byteBuffer);
bytebuffer.rewind();
this.byteBuffer = bytebuffer;
this.rawFloatBuffer = this.byteBuffer.asFloatBuffer();
this.rawIntBuffer = this.byteBuffer.asIntBuffer();
this.rawIntBuffer.position(l);
this.field_181676_c = this.byteBuffer.asShortBuffer();
this.field_181676_c.position(l << 1);
if (this.quadSprites != null)
{
TextureAtlasSprite[] atextureatlassprite = this.quadSprites;
int i1 = this.getBufferQuadSize();
this.quadSprites = new TextureAtlasSprite[i1];
System.arraycopy(atextureatlassprite, 0, this.quadSprites, 0, Math.min(atextureatlassprite.length, this.quadSprites.length));
this.quadSpritesPrev = null;
}
}
}
示例8: decode
import java.nio.ByteBuffer; //导入方法依赖的package包/类
@Test
public void decode() {
final IntegerValue value = new IntegerValue(213);
final EncodingRegistry reg = new EncodingRegistry(Optional.empty());
final ByteBuffer buf = ByteBuffer.allocate(1000);
(new IntegerEncoding()).encode(Format.BINARY, value, new TestBufferWriter(buf));
buf.rewind();
final Value<?> decoded = reg.decode(Oid.INT4, Format.BINARY, new TestBufferReader(buf));
assertEquals(value, decoded);
}
示例9: IPv4Packet
import java.nio.ByteBuffer; //导入方法依赖的package包/类
public IPv4Packet(ByteBuffer raw) {
this.raw = raw;
raw.rewind();
ipv4Header = new IPv4Header(raw.duplicate());
if (!ipv4Header.isSupported()) {
Log.d(TAG, "Unsupported IPv4 headers");
transportHeader = null;
return;
}
transportHeader = createTransportHeader();
raw.limit(ipv4Header.getTotalLength());
}
示例10: getBytes
import java.nio.ByteBuffer; //导入方法依赖的package包/类
private byte[] getBytes(CreateArkTransactionRequest createArkTransactionRequest, String senderPublicKey) {
ByteBuffer buffer = ByteBuffer.allocate(1000);
buffer.order(ByteOrder.LITTLE_ENDIAN);
buffer.put(createArkTransactionRequest.getType());
buffer.putInt((int) createArkTransactionRequest.getTimestamp()); // todo: fix downcast
buffer.put(BaseEncoding.base16().lowerCase().decode(senderPublicKey));
if(createArkTransactionRequest.getRecipientId() != null){
buffer.put(Base58.decodeChecked(createArkTransactionRequest.getRecipientId()));
} else {
buffer.put(new byte[21]);
}
if (createArkTransactionRequest.getVendorField() != null) {
byte[] vbytes = createArkTransactionRequest.getVendorField().getBytes();
if(vbytes.length < 65){
buffer.put(vbytes);
buffer.put(new byte[64-vbytes.length]);
}
} else {
buffer.put(new byte[64]);
}
buffer.putLong(createArkTransactionRequest.getAmount());
buffer.putLong(createArkTransactionRequest.getFee());
byte[] outBuffer = new byte[buffer.position()];
buffer.rewind();
buffer.get(outBuffer);
return outBuffer;
}
示例11: addTimelineDelegationToken
import java.nio.ByteBuffer; //导入方法依赖的package包/类
private void addTimelineDelegationToken(
ContainerLaunchContext clc) throws YarnException, IOException {
Credentials credentials = new Credentials();
DataInputByteBuffer dibb = new DataInputByteBuffer();
ByteBuffer tokens = clc.getTokens();
if (tokens != null) {
dibb.reset(tokens);
credentials.readTokenStorageStream(dibb);
tokens.rewind();
}
// If the timeline delegation token is already in the CLC, no need to add
// one more
for (org.apache.hadoop.security.token.Token<? extends TokenIdentifier> token : credentials
.getAllTokens()) {
if (token.getKind().equals(TimelineDelegationTokenIdentifier.KIND_NAME)) {
return;
}
}
org.apache.hadoop.security.token.Token<TimelineDelegationTokenIdentifier>
timelineDelegationToken = getTimelineDelegationToken();
if (timelineDelegationToken == null) {
return;
}
credentials.addToken(timelineService, timelineDelegationToken);
if (LOG.isDebugEnabled()) {
LOG.debug("Add timline delegation token into credentials: "
+ timelineDelegationToken);
}
DataOutputBuffer dob = new DataOutputBuffer();
credentials.writeTokenStorageToStream(dob);
tokens = ByteBuffer.wrap(dob.getData(), 0, dob.getLength());
clc.setTokens(tokens);
}
示例12: getBuffer
import java.nio.ByteBuffer; //导入方法依赖的package包/类
static ByteBuffer getBuffer(long size) {
if (size < 0 || Integer.MAX_VALUE < size) {
throw new IndexOutOfBoundsException("size");
}
ByteBuffer result = null;
if (size > LARGE_BUFFER) {
result = allocateBuffer(size);
} else {
BufferReference[] cache = CACHE.get();
// buffers are ordered by decreasing capacity
// cache[MAX_CACHED_BUFFERS] is always null
for (int i = MAX_CACHED_BUFFERS - 1; i >= 0; i--) {
BufferReference reference = cache[i];
if (reference != null) {
ByteBuffer buffer = reference.get();
if (buffer != null && size <= buffer.capacity()) {
cache[i] = null;
result = buffer;
result.rewind();
break;
}
}
}
if (result == null) {
result = allocateBuffer(size);
}
}
result.limit((int)size);
return result;
}
示例13: VbriFrame
import java.nio.ByteBuffer; //导入方法依赖的package包/类
/**
* Read the VBRI Properties from the buffer
*/
private VbriFrame(ByteBuffer header)
{
this.header=header;
//Go to start of Buffer
header.rewind();
header.position(10);
setAudioSize();
setFrameCount();
}
示例14: sign
import java.nio.ByteBuffer; //导入方法依赖的package包/类
/**
* libsecp256k1 Create an ECDSA signature.
*
* @param data Message hash, 32 bytes
* @param key Secret key, 32 bytes
* @return sig byte array of signature
*/
public static byte[] sign(byte[] data, byte[] sec) throws AssertFailException {
Preconditions.checkArgument(data.length == 32 && sec.length <= 32);
ByteBuffer byteBuff = nativeECDSABuffer.get();
if (byteBuff == null || byteBuff.capacity() < 32 + 32) {
byteBuff = ByteBuffer.allocateDirect(32 + 32);
byteBuff.order(ByteOrder.nativeOrder());
nativeECDSABuffer.set(byteBuff);
}
byteBuff.rewind();
byteBuff.put(data);
byteBuff.put(sec);
byte[][] retByteArray;
r.lock();
try {
retByteArray = secp256k1_ecdsa_sign(byteBuff, Secp256k1Context.getContext());
} finally {
r.unlock();
}
byte[] sigArr = retByteArray[0];
int sigLen = new BigInteger(new byte[] { retByteArray[1][0] }).intValue();
int retVal = new BigInteger(new byte[] { retByteArray[1][1] }).intValue();
assertEquals(sigArr.length, sigLen, "Got bad signature length.");
return retVal == 0 ? new byte[0] : sigArr;
}
示例15: subscriptionUserData
import java.nio.ByteBuffer; //导入方法依赖的package包/类
private ByteBuffer subscriptionUserData() {
final UUID uuid = UUID.randomUUID();
final ByteBuffer buf = ByteBuffer.allocate(4 + 16 + 4 + 4);
// version
buf.putInt(1);
// encode client processId
buf.putLong(uuid.getMostSignificantBits());
buf.putLong(uuid.getLeastSignificantBits());
// previously running tasks
buf.putInt(0);
// cached tasks
buf.putInt(0);
buf.rewind();
return buf;
}