List of usage examples for java.nio ByteBuffer array
public final byte[] array()
From source file:de.micromata.genome.logging.spi.ifiles.IndexHeader.java
public void writLogEntryPosition(LogWriteEntry lwe, int position, OutputStream idxOut) throws IOException { ByteBuffer ibb = ByteBuffer.wrap(new byte[Integer.BYTES]); ByteBuffer lbb = ByteBuffer.wrap(new byte[Long.BYTES]); lbb.putLong(lwe.getTimestamp());/*from www. ja va 2 s .c o m*/ idxOut.write(lbb.array()); ibb.putInt(position); idxOut.write(ibb.array()); idxOut.flush(); }
From source file:cn.ac.ncic.mastiff.io.coding.DeltaBinaryArrayZigZarByteReader.java
public void ensureDecompress() throws IOException { // if (compressAlgo != null) { org.apache.hadoop.io.compress.Decompressor decompressor = this.compressAlgo.getDecompressor(); InputStream is = this.compressAlgo.createDecompressionStream(inBuf, decompressor, 0); ByteBuffer buf = ByteBuffer.allocate(decompressedSize); IOUtils.readFully(is, buf.array(), 0, buf.capacity()); is.close();/* w w w.j a va 2s. c o m*/ this.compressAlgo.returnDecompressor(decompressor); inBuf.reset(buf.array(), offset, buf.capacity()); }
From source file:com.navercorp.pinpoint.common.server.bo.serializer.trace.v1.SpanBoTest.java
@Test public void serialize_V1() { final SpanBo spanBo = new SpanBo(); spanBo.setAgentId("agentId"); spanBo.setApplicationId("applicationId"); spanBo.setEndPoint("end"); spanBo.setRpc("rpc"); spanBo.setParentSpanId(5);/*from w w w . ja va 2s . c om*/ spanBo.setAgentStartTime(1); TransactionId transactionId = new TransactionId("agentId", 2, 3); spanBo.setTransactionId(transactionId); spanBo.setElapsed(4); spanBo.setStartTime(5); spanBo.setServiceType(ServiceType.STAND_ALONE.getCode()); spanBo.setLoggingTransactionInfo(LoggingInfo.INFO.getCode()); spanBo.setExceptionInfo(1000, "Exception"); ByteBuffer bytes = spanSerializer.writeColumnValue(spanBo); SpanBo newSpanBo = new SpanBo(); Buffer valueBuffer = new OffsetFixedBuffer(bytes.array(), bytes.arrayOffset(), bytes.remaining()); int i = spanDecoder.readSpan(newSpanBo, valueBuffer); logger.debug("length:{}", i); Assert.assertEquals(bytes.limit(), i); Assert.assertEquals(newSpanBo.getAgentId(), spanBo.getAgentId()); Assert.assertEquals(newSpanBo.getApplicationId(), spanBo.getApplicationId()); Assert.assertEquals(newSpanBo.getAgentStartTime(), spanBo.getAgentStartTime()); Assert.assertEquals(newSpanBo.getElapsed(), spanBo.getElapsed()); Assert.assertEquals(newSpanBo.getEndPoint(), spanBo.getEndPoint()); Assert.assertEquals(newSpanBo.getErrCode(), spanBo.getErrCode()); Assert.assertEquals(newSpanBo.getFlag(), spanBo.getFlag()); // not included for serialization // Assert.assertEquals(newSpanBo.getTraceAgentStartTime(), spanBo.getTraceAgentStartTime()); // Assert.assertEquals(newSpanBo.getTraceTransactionSequence(), spanBo.getTraceTransactionSequence()); Assert.assertEquals(newSpanBo.getParentSpanId(), spanBo.getParentSpanId()); Assert.assertEquals(newSpanBo.getServiceType(), spanBo.getServiceType()); Assert.assertEquals(newSpanBo.getApplicationServiceType(), spanBo.getServiceType()); Assert.assertEquals(newSpanBo.getVersion(), spanBo.getVersion()); Assert.assertEquals(newSpanBo.getLoggingTransactionInfo(), spanBo.getLoggingTransactionInfo()); Assert.assertEquals(newSpanBo.getExceptionId(), spanBo.getExceptionId()); Assert.assertEquals(newSpanBo.getExceptionMessage(), spanBo.getExceptionMessage()); }
From source file:libepg.epg.section.sectionreconstructor.SectionReconstructor.java
/** * ??????????????????// w w w . ja v a 2 s . c om * ByteBuffer?array()???????????????????? * */ private synchronized void addToReturnObject(ByteBuffer buf, Set<byte[]> dest) { byte[] BeforeCutDown = buf.array(); byte[] AfterCutDown = new byte[buf.position()]; System.arraycopy(BeforeCutDown, 0, AfterCutDown, 0, AfterCutDown.length); if (LOG.isTraceEnabled()) { MessageFormat msg1 = new MessageFormat("\n??={0}\n?={1}"); Object[] parameters1 = { Hex.encodeHexString(BeforeCutDown), Hex.encodeHexString(AfterCutDown) }; LOG.trace(msg1.format(parameters1)); } if (dest.add(AfterCutDown)) { if (LOG.isTraceEnabled()) { MessageFormat msg2 = new MessageFormat("\n???={0}"); Object[] parameters2 = { Hex.encodeHexString(AfterCutDown) }; LOG.trace(msg2.format(parameters2)); } } else if (LOG.isTraceEnabled()) { MessageFormat msg3 = new MessageFormat("\n???????={0}"); Object[] parameters3 = { Hex.encodeHexString(AfterCutDown) }; LOG.trace(msg3.format(parameters3)); } }
From source file:com.dreamwork.web.FrontJsonController.java
private byte[] read(InputStream in) throws IOException { ByteBuffer fullBytesRed = ByteBuffer.allocate(0); int n;/* w w w .j a v a2s. com*/ while (true) { byte[] b = new byte[2048]; n = in.read(b); if (n == -1) { break; } byte[] currBytes = fullBytesRed.array(); fullBytesRed = ByteBuffer.allocate(currBytes.length + n); fullBytesRed.put(currBytes); fullBytesRed.put(b, 0, n); } byte[] data = fullBytesRed.array(); return data; }
From source file:de.brendamour.jpasskit.signing.PKInMemorySigningUtil.java
@Override public byte[] createSignedAndZippedPkPassArchive(PKPass pass, IPKPassTemplate passTemplate, PKSigningInformation signingInformation) throws PKSigningException { Map<String, ByteBuffer> allFiles; try {/*from ww w .ja va2s .c om*/ allFiles = passTemplate.getAllFiles(); } catch (IOException e) { throw new PKSigningException("Error when getting files from template", e); } ByteBuffer passJSONFile = createPassJSONFile(pass); allFiles.put(PASS_JSON_FILE_NAME, passJSONFile); ByteBuffer manifestJSONFile = createManifestJSONFile(allFiles); allFiles.put(MANIFEST_JSON_FILE_NAME, manifestJSONFile); ByteBuffer signature = ByteBuffer.wrap(signManifestFile(manifestJSONFile.array(), signingInformation)); allFiles.put(SIGNATURE_FILE_NAME, signature); return createZippedPassAndReturnAsByteArray(allFiles); }
From source file:com.spectralogic.ds3client.helpers.FileObjectPutter_Test.java
private void getFileWithPutter(final Path dir, final Path file) throws IOException { try {//w ww. j a v a 2 s .c om final FileObjectPutter putter = new FileObjectPutter(dir); try (final SeekableByteChannel newChannel = putter.buildChannel(file.getFileName().toString())) { assertThat(newChannel, is(notNullValue())); final ByteBuffer buff = ByteBuffer.allocate(testData.length); assertThat(newChannel.read(buff), is(testData.length)); assertThat(new String(buff.array(), Charset.forName("UTF-8")), is(testString)); } } finally { Files.deleteIfExists(file); } }
From source file:cn.ac.ncic.mastiff.io.coding.RunLengthEncodingByteReader.java
public void ensureDecompress() throws IOException { org.apache.hadoop.io.compress.Decompressor decompressor = this.compressAlgo.getDecompressor(); InputStream is = this.compressAlgo.createDecompressionStream(inBuf, decompressor, 0); ByteBuffer buf = ByteBuffer.allocate(decompressedSize); IOUtils.readFully(is, buf.array(), 0, buf.capacity()); is.close();/*from w w w . j a v a 2s . co m*/ this.compressAlgo.returnDecompressor(decompressor); inBuf.reset(buf.array(), offset, buf.capacity()); }
From source file:com.alibaba.zonda.logger.server.writer.OutputStreamManager.java
public void writeWithLength(byte[] data, String tag) throws IOException { lock.readLock().lock();//w ww .j a va 2 s. c o m try { LogOutputStream os = getOutputStream(tag); ByteBuffer bf = ByteBuffer.allocate(4 + data.length); bf.put(BytesUtil.intToBytes(data.length)); bf.put(data); bf.flip(); IOUtils.write(bf.array(), os.getStream()); os.addBytesWritten(4 + data.length); os.getStream().flush(); } finally { lock.readLock().unlock(); } }
From source file:com.hazelcast.simulator.probes.probes.impl.HdrLatencyDistributionResult.java
@Override public void writeTo(XMLStreamWriter writer) { Histogram tmp = histogram.copy();/*from w w w. j a v a2s . c o m*/ 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); } }