Buffer clear - top ranked examples from Open Source projects

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

This code example shows how to use the following methods:clear, flip, put, slice
        Text startKey = partitioner.getRangeEndKey(partitioner.getRangeNum() - 2);
        byteBuffer.put(startKey.getBytes(), 0, startKey.getLength());
        byteBuffer.put(newline);
      } else { 
        Text startKey = partitioner.getRangeEndKey(range_no - 1);
        byteBuffer.put(startKey.getBytes(), 0, startKey.getLength());
        byteBuffer.put(newline);
        Text endKey = partitioner.getRangeEndKey(range_no);
        byteBuffer.put(endKey.getBytes(), 0, endKey.getLength());
        byteBuffer.put(newline);
      } 
    } 
 
    private void writeCurrentByteBuffer(boolean is_last) throws IOException {
      byteBuffer.flip();
      ByteBuffer tmpByteBuf = byteBuffer.slice();
      ByteBuffer output = sstableBuilder.append(tmpByteBuf, is_first, is_last, is_include_min, is_include_max);
      if (output != null) {
        byte[] reslutBuf = new byte[output.capacity()];
        output.get(reslutBuf);

8
CodeRank
This code example shows how to use the following methods:clear, flip, putLong
    return value;
  } 
 
  public void set(long newVal) throws IOException {
    lazyOpen(); 
    buf.clear();
    buf.putLong(newVal);
    buf.flip();
    IOUtils.writeFully(ch, buf, 0);
    value = newVal;
  } 
   
  private void lazyOpen() throws IOException { 
    if (ch != null) {
      return; 
    } 
 
    // Load current value. 
    byte[] data = null;
    try { 
8
CodeRank
This code example shows how to use the following methods:clear, flip
        b.order(ByteOrder.LITTLE_ENDIAN);
        return b;
    } 
 
    private static void read(ByteBuffer bb, FileChannel ch) throws IOException {
        bb.clear();
        ch.read(bb);
        bb.flip();
    } 
 
    private static void read(ByteBuffer bb, FileChannel ch, long pos) throws IOException {
        bb.clear();
        ch.read(bb, pos);
        bb.flip();
    } 
 
    private static long getUnsignedInt(ByteBuffer bb, int offset) {
        return (bb.getInt(offset) & 0xffffffffL);
    } 
 
8
CodeRank
This code example shows how to use the following methods:clear, flip, position, array
        throw new UnsupportedOperationException();
    } 
 
    private void flushBytes() throws IOException { 
        int position;
        if ((position = mBytes.position()) > 0) {
            mBytes.flip();
            mOutputStream.write(mBytes.array(), 0, position);
            mBytes.clear();
        } 
    } 
 
    public void flush() throws IOException { 
        //Log.i("PackageManager", "flush mPos=" + mPos); 
        if (mPos > 0) {
            if (mOutputStream != null) {
                CharBuffer charBuffer = CharBuffer.wrap(mText, 0, mPos);
                CoderResult result = mCharset.encode(charBuffer, mBytes, true);
                while (true) { 
                    if (result.isError()) {
7
CodeRank
This code example shows how to use the following methods:clear, limit, position, rewind, toString
                                         //   -> "   Fruit Titanesque, Inc." 
        test(cb, "   Fruit Titanesque, Inc.");
    } 
 
    private static void test(CharBuffer cb, String exp) {
        cb.limit(cb.position());
        cb.rewind();
        if (!cb.toString().equals(exp))
            throw new RuntimeException("expect: '" + exp + "'; got: '"
                                       + cb.toString() + "'");
        cb.clear();
    } 
} 
7
CodeRank
This code example shows how to use the following methods:capacity, clear
   * the buffer may be recycled, so the user must not 
   * continue to use it in any way. 
   * @param buf the buffer to return 
   */ 
  public void returnBuffer(ByteBuffer buf) {
    buf.clear(); // reset mark, limit, etc
    int size = buf.capacity();
    Queue<WeakReference<ByteBuffer>> list = buffersBySize.get(size);
    if (list == null) {
      list = new ConcurrentLinkedQueue<WeakReference<ByteBuffer>>();
      Queue<WeakReference<ByteBuffer>> prev = buffersBySize.putIfAbsent(size, list);
      // someone else put a queue in the map before we did 
      if (prev != null) {
        list = prev;
      } 
    } 
    list.add(new WeakReference<ByteBuffer>(buf));
  } 
   
  /** 
7
CodeRank
This code example shows how to use the following methods:clear, flip, position, array
        throw new UnsupportedOperationException();
    } 
 
    private void flushBytes() throws IOException { 
        int position;
        if ((position = mBytes.position()) > 0) {
            mBytes.flip();
            mOutputStream.write(mBytes.array(), 0, position);
            mBytes.clear();
        } 
    } 
 
    public void flush() throws IOException { 
        //Log.i("PackageManager", "flush mPos=" + mPos); 
        if (mPos > 0) {
            if (mOutputStream != null) {
                CharBuffer charBuffer = CharBuffer.wrap(mText, 0, mPos);
                CoderResult result = mCharset.encode(charBuffer, mBytes, true);
                while (true) { 
                    if (result.isError()) {
7
CodeRank
This code example shows how to use the following methods:clear, flip
        } 
    } 
 
    private void byte2char(ByteBuffer bytes, CharBuffer chars) throws IOException {
        decoder.reset();
        chars.clear();
        CoderResult result = decoder.decode(bytes, chars, true);
        if (result.isError() || result.isOverflow()) {
            throw new IOException(result.toString());
        } else if (result.isUnderflow()) {
            chars.flip();
        } 
    } 
} 
7
CodeRank
This code example shows how to use the following methods:clear, flip, remaining
  } 
 
  @Override 
  public int write(ByteBuffer buffer) throws IOException {
    if (!isPuttingInOutBuffer) {
      if (out.remaining() != 0)
        return channel.write(out);
      out.clear();
      isPuttingInOutBuffer = true;
    } 
    sslEngine.wrap(buffer, out);
    isPuttingInOutBuffer = false;
    out.flip();
    return channel.write(out);
  } 
 
  @Override 
  public int outBufferRemaining() { 
    return out.remaining();
  } 
7
CodeRank
This code example shows how to use the following methods:capacity, clear, flip, limit, getInt
    } 
 
    private int readInteger() { 
        ByteBuffer buffer = getBuffer(INT_SIZE_IN_BYTES);
        read(buffer);
        buffer.flip();
        return buffer.getInt();
    } 
 
    /** 
     * Reads an array of <count> longs from the file channel, returning the results as an array. 
     * @param count Number of longs to read. 
     * @return An array of longs.  Size of array should match count. 
     */ 
    private long[] readLongs(final int count) {
        ByteBuffer buffer = getBuffer(count*LONG_SIZE_IN_BYTES);
        read(buffer);
        buffer.flip();
        long[] result = new long[count];
        for(int i = 0; i < count; i++)

7
CodeRank

Related Buffer clear Questions & Answers:

clear Method Overview
Clears this buffer.
See Code Examples for other Java 8 Buffer Methods: