List of usage examples for java.nio ByteBuffer rewind
public final Buffer rewind()
From source file:com.jordanwilliams.heftydb.test.generator.KeyValueGenerator.java
public synchronized ByteBuffer testValue(int size) { if (!testValues.containsKey(size)) { testValues.put(size, randomValue(size)); }/* www . j a va2s. co m*/ ByteBuffer testValue = testValues.get(size).duplicate(); testValue.rewind(); return testValue; }
From source file:com.jordanwilliams.heftydb.test.generator.KeyValueGenerator.java
public synchronized ByteBuffer testKey(int size, int reuseWeight) { int next = rand.nextInt(100); if (next <= reuseWeight && reuseWeight != 0 && testKeys.size() > 0) { ByteBuffer existing = testKeys.get(rand.nextInt(testKeys.size())); ByteBuffer reusedKey = existing.duplicate(); reusedKey.rewind(); return reusedKey; } else {// www.ja v a2s . c om ByteBuffer random = randomKey(size); if (testKeys.size() < MAX_CACHED_KEYS) { testKeys.add(random); } return random.duplicate(); } }
From source file:org.apache.hadoop.yarn.server.nodemanager.NodeStatusUpdaterImpl.java
private static Map<ApplicationId, Credentials> parseCredentials( Map<ApplicationId, ByteBuffer> systemCredentials) throws IOException { Map<ApplicationId, Credentials> map = new HashMap<ApplicationId, Credentials>(); for (Map.Entry<ApplicationId, ByteBuffer> entry : systemCredentials.entrySet()) { Credentials credentials = new Credentials(); DataInputByteBuffer buf = new DataInputByteBuffer(); ByteBuffer buffer = entry.getValue(); buffer.rewind(); buf.reset(buffer);/*from ww w. ja v a 2s . c o m*/ credentials.readTokenStorageStream(buf); map.put(entry.getKey(), credentials); } if (LOG.isDebugEnabled()) { for (Map.Entry<ApplicationId, Credentials> entry : map.entrySet()) { LOG.debug("Retrieved credentials form RM for " + entry.getKey() + ": " + entry.getValue().getAllTokens()); } } return map; }
From source file:org.apache.cassandra.cache.RowCacheKey.java
public ByteBuffer serializeForStorage() { ByteBuffer bytes = ByteBuffer.allocate(serializedSize()); bytes.put(key.slice());//from w w w . ja v a 2s.co m bytes.rewind(); return bytes; }
From source file:com.github.neoio.net.message.staging.memory.TestMemoryMessageStaging.java
@Test public void test_tempRead() { ByteBuffer buffer = ByteBuffer.allocate(1024); buffer.put("Hello World".getBytes()); buffer.rewind(); staging.writeTempReadBytes(buffer);//from w w w.j a va 2 s . co m Assert.assertTrue(staging.hasTempReadBytes()); buffer.clear(); staging.readTempReadBytes(buffer); Assert.assertEquals("Hello World", new String(ArrayUtils.subarray(buffer.array(), 0, "Hello World".getBytes().length))); staging.resetTempReadBytes(); Assert.assertFalse(staging.hasTempReadBytes()); }
From source file:com.github.neoio.net.message.staging.memory.TestMemoryMessageStaging.java
@Test public void test_tempWrite() { ByteBuffer buffer = ByteBuffer.allocate(1024); buffer.put("Hello World".getBytes()); buffer.rewind(); staging.writeTempWriteBytes(buffer); Assert.assertTrue(staging.hasTempWriteBytes()); buffer.clear();//ww w.j av a 2 s .c o m staging.readTempWriteBytes(buffer); Assert.assertEquals("Hello World", new String(ArrayUtils.subarray(buffer.array(), 0, "Hello World".getBytes().length))); staging.resetTempWriteBytes(); Assert.assertFalse(staging.hasTempWriteBytes()); }
From source file:com.hazelcast.simulator.probes.xml.HistogramConverter.java
@Override public void marshal(Object object, HierarchicalStreamWriter writer, MarshallingContext marshallingContext) { Histogram histogram = (Histogram) object; int size = histogram.getNeededByteBufferCapacity(); ByteBuffer byteBuffer = ByteBuffer.allocate(size); int bytesWritten = histogram.encodeIntoCompressedByteBuffer(byteBuffer); byteBuffer.rewind(); byteBuffer.limit(bytesWritten);//from w w w .ja v a 2 s .c o m String encodedHistogram = encodeBase64String(byteBuffer.array()); writer.setValue(encodedHistogram); }
From source file:ch.ledcom.jpreseed.UsbCreatorTest.java
private CpioArchiveInputStream getCpioArchiveInputStream(FsDirectoryEntry newInitRdGzEntry) throws IOException { FsFile initrdGzFile = newInitRdGzEntry.getFile(); ByteBuffer initRdBuffer = ByteBuffer.allocate((int) initrdGzFile.getLength()); initrdGzFile.read(0, initRdBuffer);/* w w w . ja v a 2 s .c om*/ initRdBuffer.rewind(); return new CpioArchiveInputStream(new GZIPInputStream(new ByteBufferDataInputStream(initRdBuffer))); }
From source file:org.apache.james.protocols.smtp.core.DataLineMessageHookHandler.java
private byte[] readBytes(ByteBuffer line) { line.rewind(); byte[] bline; if (line.hasArray()) { bline = line.array();/* w w w . ja va 2s . c o m*/ } else { bline = new byte[line.remaining()]; line.get(bline); } return bline; }
From source file:org.ros.internal.message.new_style.ServiceLoader.java
private void addServiceDefinitionFromPaths(File searchPath, File servicePath, CharsetDecoder decoder) throws IOException { FileInputStream inputStream = new FileInputStream(servicePath); FileChannel channel = inputStream.getChannel(); ByteBuffer buffer = ByteBuffer.allocate((int) channel.size()); channel.read(buffer);//w w w .j a v a 2 s .com buffer.rewind(); decoder.reset(); String definition = decoder.decode(buffer).toString().trim(); serviceDefinitions.put(pathToServiceName(searchPath, servicePath), definition); channel.close(); inputStream.close(); }