ByteBuffer duplicate - top ranked examples from Open Source projects

These code examples were ranked by Codota’s semantic indexing as the best open source examples for ByteBuffer duplicate method.

This code example shows how to use the following methods:limit, position, duplicate
        return buffer.remaining();
    } 
 
    @Override 
    public BytesReference slice(int from, int length) {
        ByteBuffer dup = buffer.duplicate();
        dup.position(buffer.position() + from);
        dup.limit(buffer.position() + from + length);
        return new ByteBufferBytesReference(dup);
    } 
 
    @Override 
    public StreamInput streamInput() { 
        return new ByteBufferStreamInput(buffer);
    } 
 
    @Override 
    public void writeTo(OutputStream os) throws IOException {
        if (buffer.hasArray()) {
            os.write(buffer.array(), buffer.arrayOffset() + buffer.position(), buffer.remaining());
9
CodeRank
This code example shows how to use the following methods:position, asLongBuffer, duplicate, putFloat
  } 
 
  @Override 
  public void init(ByteBuffer buf, int position)
  { 
    ByteBuffer mutationBuffer = buf.duplicate();
    mutationBuffer.position(position);
 
    final long[] bins = new long[breaks.length + 1];
    mutationBuffer.asLongBuffer().put(bins);
    mutationBuffer.putFloat(position + minOffset, Float.MAX_VALUE);
    mutationBuffer.putFloat(position + maxOffset, Float.MIN_VALUE);
  } 
 
  @Override 
  public void aggregate(ByteBuffer buf, int position)
  { 
    final float value = selector.get();
    final int minPos = position + minOffset;
    final int maxPos = position + maxOffset;
9
CodeRank
This code example shows how to use the following methods:limit, position, duplicate, get
public abstract class AbstractCompositeType extends AbstractType<ByteBuffer>
{ 
    // changes bb position 
    public static int getShortLength(ByteBuffer bb)
    { 
        int length = (bb.get() & 0xFF) << 8;
        return length | (bb.get() & 0xFF);
    } 
 
    // changes bb position 
    public static void putShortLength(ByteBuffer bb, int length)
    { 
        bb.put((byte) ((length >> 8) & 0xFF));
        bb.put((byte) (length & 0xFF));
    } 
 
    // changes bb position 
    public static ByteBuffer getBytes(ByteBuffer bb, int length)
    { 
        ByteBuffer copy = bb.duplicate();

8
CodeRank
This code example shows how to use the following methods:limit, position, remaining, duplicate
        } 
 
        @Override 
        public int read(ByteBuffer dst) throws IOException {
            // delay buffer read.. 
            int willActuallyRead = randomInt(dst.remaining());
            ByteBuffer mockDst = dst.duplicate();
            mockDst.limit(mockDst.position() + willActuallyRead);
            try { 
                return delegate.read(mockDst);
            } finally { 
                dst.position(mockDst.position());
            } 
        } 
 
        @Override 
        public long read(ByteBuffer[] dsts, int offset, int length) throws IOException {
            return delegate.read(dsts, offset, length);
        } 
 
8
CodeRank
This code example shows how to use the following methods:limit, position, duplicate, get
    if (length < 0)
    { 
      return ""; 
    } 
 
    final int endOfs = Math.min(buf.limit(), bufOfs + length + 1);
    final byte[] bytes = new byte[endOfs - bufOfs];
 
    buf = buf.duplicate();
    buf.position(bufOfs);
    buf.get(bytes);
    return new String(Hex.encodeHex(bytes));
  } 
 
 
  /** 
   * Strip username/password information from the JDBC DB uri to be used for logging 
   * @param uri     the JDBC URI to sanitize 
   * @return the sanitized DB URI 
   */ 
8
CodeRank
This code example shows how to use the following methods:remaining, duplicate
  @Override 
  public BigInteger fromByteBuffer(ByteBuffer byteBuffer) {
    if (byteBuffer == null) {
      return null; 
    } 
    int length = byteBuffer.remaining();
    byte[] bytes = new byte[length];
    byteBuffer.duplicate().get(bytes);
    return new BigInteger(bytes);
  } 
 
  @Override 
  public ByteBuffer toByteBuffer(BigInteger obj) {
    if (obj == null) {
      return null; 
    } 
    return ByteBuffer.wrap(obj.toByteArray());
  } 
 
  @Override 
7
CodeRank
This code example shows how to use the following methods:duplicate
    } 
 
    @Override 
    public Map<K, V> fromByteBuffer(ByteBuffer arg0) {
        if (arg0 == null) return null;
            ByteBuffer dup = arg0.duplicate();
            return myMap.compose(dup);
            } 
 
    @Override 
    public ByteBuffer toByteBuffer(Map<K, V> arg0) {
        return arg0 == null ? null : myMap.decompose(arg0);
    } 
} 
7
CodeRank
This code example shows how to use the following methods:capacity, flip, hasRemaining, position, duplicate
7
CodeRank
This code example shows how to use the following methods:remaining, duplicate, getInt
 
    @Override 
    public Long fromByteBuffer(ByteBuffer byteBuffer) {
        if (byteBuffer == null)
            return null; 
        ByteBuffer dup = byteBuffer.duplicate();
        if (dup.remaining() == 8) {
            long l = dup.getLong();
            return l;
        } else if (dup.remaining() == 4) {
            return (long) dup.getInt();
        } 
        return null; 
    } 
 
    @Override 
    public ComparatorType getComparatorType() { 
        return ComparatorType.LONGTYPE; 
    } 
 
7
CodeRank
This code example shows how to use the following methods:limit, position, duplicate, slice
		this.buffer = buffer;
	} 
	 
	public void intialize(ByteBuffer buffer, int off, int len)
	{ 
		buffer = buffer.duplicate();
		buffer.position(off);
		buffer.limit(off + len);
		this.buffer = buffer.slice();
	} 
	 
	@Override 
	public int read() throws IOException 
	{ 
		return buffer.hasRemaining() ? (buffer.get() & 0xff) : -1;
	} 
	 
	@Override 
	public int read(byte b[], int off, int len) throws IOException
	{ 
7
CodeRank

Related ByteBuffer duplicate Questions & Answers:

duplicate Method Overview
Creates a new byte buffer that shares this buffer's content.
See Code Examples for other Java 8 ByteBuffer Methods: