List of usage examples for java.nio ByteBuffer remaining
public final int remaining()
From source file:org.wso2.carbon.inbound.endpoint.protocol.http2.http2Encoder.java
@Override public int write(ByteBuffer src) throws IOException { while (src.hasRemaining()) { byte[] b; b = new byte[src.remaining()]; src.get(b);/* w w w. j a va 2 s . c om*/ if (src.hasRemaining()) encoder.writeData(chContext, streamId, Unpooled.wrappedBuffer(b), 0, false, promise); else { encoder.writeData(chContext, streamId, Unpooled.wrappedBuffer(b), 0, true, promise); isComplete = true; } } return src.position(); }
From source file:org.apache.avro.file.ZstandardCodec.java
@Override public ByteBuffer decompress(ByteBuffer compressedData) throws IOException { ByteArrayOutputStream baos = getOutputBuffer(compressedData.remaining()); InputStream bytesIn = new ByteArrayInputStream(compressedData.array(), compressedData.arrayOffset() + compressedData.position(), compressedData.remaining()); InputStream ios = new ZstdCompressorInputStream(bytesIn); try {/*from w w w . j a va 2s . c om*/ IOUtils.copy(ios, baos); } finally { ios.close(); } return ByteBuffer.wrap(baos.toByteArray()); }
From source file:org.apache.avro.file.XZCodec.java
@Override public ByteBuffer compress(ByteBuffer data) throws IOException { ByteArrayOutputStream baos = getOutputBuffer(data.remaining()); OutputStream ios = new XZCompressorOutputStream(baos, compressionLevel); writeAndClose(data, ios);/* ww w . j a v a 2s.com*/ return ByteBuffer.wrap(baos.toByteArray()); }
From source file:org.apache.cassandra.db.marshal.TimeUUIDType.java
public String getString(ByteBuffer bytes) { if (bytes.remaining() == 0) { return ""; }/*from w w w . jav a 2 s . c o m*/ if (bytes.remaining() != 16) { throw new MarshalException("UUIDs must be exactly 16 bytes"); } UUID uuid = UUIDGen.getUUID(bytes); if (uuid.version() != 1) { throw new MarshalException("TimeUUID only makes sense with version 1 UUIDs"); } return uuid.toString(); }
From source file:org.apache.avro.file.XZCodec.java
@Override public ByteBuffer decompress(ByteBuffer data) throws IOException { ByteArrayOutputStream baos = getOutputBuffer(data.remaining()); InputStream bytesIn = new ByteArrayInputStream(data.array(), data.arrayOffset() + data.position(), data.remaining());//from ww w. j av a 2 s. co m InputStream ios = new XZCompressorInputStream(bytesIn); try { IOUtils.copy(ios, baos); } finally { ios.close(); } return ByteBuffer.wrap(baos.toByteArray()); }
From source file:org.apache.avro.file.BZip2Codec.java
@Override public ByteBuffer compress(ByteBuffer uncompressedData) throws IOException { ByteArrayOutputStream baos = getOutputBuffer(uncompressedData.remaining()); BZip2CompressorOutputStream outputStream = new BZip2CompressorOutputStream(baos); try {/*from w ww .j a va2 s . co m*/ outputStream.write(uncompressedData.array(), uncompressedData.position(), uncompressedData.remaining()); } finally { outputStream.close(); } ByteBuffer result = ByteBuffer.wrap(baos.toByteArray()); return result; }
From source file:org.codice.alliance.libs.mpegts.MpegTsDecoderImpl.java
private byte[] getByteBufferAsBytes(final ByteBuffer buffer) { final byte[] bytes = new byte[buffer.remaining()]; buffer.get(bytes);/*from w w w .j av a 2s. c om*/ return bytes; }
From source file:com.acciente.oacc.encryptor.jasypt.LegacyJasyptPasswordEncryptor.java
private byte[] getCleanedBytes(char[] password) { final char[] normalizedChars = TextNormalizer.getInstance().normalizeToNfc(password); final ByteBuffer byteBuffer = StandardCharsets.UTF_8.encode(CharBuffer.wrap(normalizedChars)); final byte[] byteArray = new byte[byteBuffer.remaining()]; byteBuffer.get(byteArray);/* www .j a v a 2 s . c o m*/ Arrays.fill(byteBuffer.array(), (byte) 0); return byteArray; }
From source file:org.apache.cassandra.db.marshal.TimeUUIDType.java
public int compare(ByteBuffer o1, ByteBuffer o2) { if (o1.remaining() == 0) { return o2.remaining() == 0 ? 0 : -1; }/*from w w w .j av a2s. c o m*/ if (o2.remaining() == 0) { return 1; } int res = compareTimestampBytes(o1, o2); if (res != 0) return res; return o1.compareTo(o2); }
From source file:Base64Encoder.java
private boolean out(ByteBuffer bb, int outValue) { if (bb.remaining() > 0) { bb.put((byte) outValue); return true; } else {// w w w . java2 s . c o m excessByte = Byte.valueOf((byte) outValue); return false; } }