List of usage examples for java.nio ByteBuffer rewind
public final Buffer rewind()
From source file:com.hazelcast.simulator.probes.probes.impl.HdrLatencyDistributionResult.java
@Override public void writeTo(XMLStreamWriter writer) { Histogram tmp = histogram.copy();/*from ww w . j av a2 s . c om*/ int size = tmp.getNeededByteBufferCapacity(); ByteBuffer byteBuffer = ByteBuffer.allocate(size); int bytesWritten = tmp.encodeIntoCompressedByteBuffer(byteBuffer); byteBuffer.rewind(); byteBuffer.limit(bytesWritten); String encodedData = Base64.encodeBase64String(byteBuffer.array()); try { writer.writeStartElement(ProbesResultXmlElements.HDR_LATENCY_DATA.getName()); writer.writeCData(encodedData); writer.writeEndElement(); } catch (XMLStreamException e) { throw new RuntimeException(e); } }
From source file:org.colombbus.tangara.io.ScriptReader.java
private String extractScriptWithHeader(ByteBuffer content) throws UnsupportedEncodingException { content.rewind(); ScriptHeader header = ScriptHeaderHelper.extractHeader(content); lastScriptCharset = header.getCharset(); String script = extractScriptWithCharset(content, header.getCharset()); return script; }
From source file:org.ros.internal.message.new_style.MessageLoader.java
private void addMessageDefinitionFromPaths(File searchPath, File messagePath, CharsetDecoder decoder) throws IOException { FileInputStream inputStream = new FileInputStream(messagePath); FileChannel channel = inputStream.getChannel(); ByteBuffer buffer = ByteBuffer.allocate((int) channel.size()); channel.read(buffer);// w w w.j a v a2 s . c om buffer.rewind(); decoder.reset(); String definition = decoder.decode(buffer).toString().trim(); messageDefinitions.put(pathToMessageName(searchPath, messagePath), definition); channel.close(); inputStream.close(); }
From source file:org.openteufel.file.mpq.MPQFileSector.java
public ByteBuffer getDecompressed() throws DataFormatException, IOException { ByteBuffer ret = ByteBuffer.allocate(sizeUncompressed); getDecompressed(ret);/*ww w . j a v a 2s . c o m*/ ret.rewind(); return ret; }
From source file:com.smartitengineering.util.simple.io.BufferedInputStream.java
protected ByteBuffer nextBuffer() { if (currentBuffer == null) { return null; }//www .java 2 s. c o m Iterator<ByteBuffer> bufferIterator = buffers.keySet().iterator(); while (bufferIterator.hasNext()) { ByteBuffer buffer = bufferIterator.next(); if (buffer == currentBuffer) { if (bufferIterator.hasNext()) { final ByteBuffer next = bufferIterator.next(); next.rewind(); return next; } else { return null; } } } return null; }
From source file:com.eventsourcing.hlc.HybridTimestampTest.java
@Test @SneakyThrows//from w ww. jav a 2 s .c om public void layout() { Layout<HybridTimestamp> layout = Layout.forClass(HybridTimestamp.class); List<Property<HybridTimestamp>> properties = layout.getProperties(); assertEquals(properties.size(), 2); assertTrue(properties.stream().anyMatch(p -> p.getName().contentEquals("logicalTime"))); assertTrue(properties.stream().anyMatch(p -> p.getName().contentEquals("logicalCounter"))); HybridTimestamp timestamp = new HybridTimestamp(physicalTimeProvider); timestamp.update(); BinarySerialization serialization = BinarySerialization.getInstance(); ObjectSerializer<HybridTimestamp> serializer = serialization.getSerializer(HybridTimestamp.class); ObjectDeserializer<HybridTimestamp> deserializer = serialization.getDeserializer(HybridTimestamp.class); ByteBuffer buffer = serializer.serialize(timestamp); buffer.rewind(); HybridTimestamp timestamp1 = deserializer.deserialize(buffer); assertEquals(timestamp1.compareTo(timestamp), 0); }
From source file:org.docx4j.openpackaging.parts.WordprocessingML.BinaryPart.java
public byte[] getBytes() { ByteBuffer bb = this.getBuffer(); bb.rewind(); byte[] bytes = new byte[bb.limit()]; bb.get(bytes, 0, bytes.length);/*from w w w.j a va 2 s . c o m*/ bb.rewind(); return bytes; }
From source file:org.apache.myriad.state.utils.ByteBufferSupportTest.java
private ByteBuffer getByteBuffer(byte[] bytes) { ByteBuffer bb = ByteBuffer.allocate(bytes.length); bb.put(bytes);/*from ww w . j a v a 2 s.com*/ bb.rewind(); return bb; }
From source file:FindInt.java
public int seek() throws IOException { int num = -1; try (SeekableByteChannel fc = Files.newByteChannel(file)) { ByteBuffer buf = ByteBuffer.allocate(8); //Get the offset into the file. fc.read(buf);//from w w w. j a v a 2 s . c o m long offset = buf.getLong(0); //Seek to the offset location. fc.position(offset); buf.rewind(); //Read the 'secret' value. fc.read(buf); num = buf.getInt(0); } catch (IOException x) { System.err.println(x); } return num; }
From source file:org.docx4j.openpackaging.parts.WordprocessingML.BinaryPart.java
/** * Copy the ByteBuffer containing this part's binary data * to an output stream.//from w ww.j av a2 s.c om * * @param out * @throws IOException */ public void writeDataToOutputStream(OutputStream out) throws IOException { ByteBuffer buf = this.getBuffer(); buf.rewind(); // Fix for https://github.com/plutext/docx4j/issues/80 // from http://stackoverflow.com/questions/579600/how-to-put-the-content-of-a-bytebuffer-into-an-outputstream WritableByteChannel channel = Channels.newChannel(out); channel.write(buf); buf.rewind(); }