Java ByteBuffer Read enlargeThreadLocalByteBuffer()

Here you can find the source of enlargeThreadLocalByteBuffer()

Description

Double the thread local buffer capacity.

License

GNU General Public License

Declaration

public static ByteBuffer enlargeThreadLocalByteBuffer() 

Method Source Code


//package com.java2s;
/*/*from w ww. j  a  v a2 s  . c  o m*/
Pulsar
Copyright (C) 2013-2015 eBay Software Foundation
Licensed under the GPL v2 license.  See LICENSE for full terms.
*/

import java.nio.ByteBuffer;

public class Main {
    private static final ThreadLocal<ByteBuffer> TMP_BUFFER = new ThreadLocal<ByteBuffer>() {
        @Override
        protected ByteBuffer initialValue() {
            return ByteBuffer.allocate(4096);
        }
    };

    /**
     * Double the thread local buffer capacity.
     * 
     * @return
     */
    public static ByteBuffer enlargeThreadLocalByteBuffer() {
        TMP_BUFFER.set(ByteBuffer.allocate(TMP_BUFFER.get().capacity() * 2));
        return TMP_BUFFER.get();
    }
}

Related

  1. assertReadyForFreshRead(ByteBuffer b)
  2. c_read(Channel fd, ByteBuffer buffer, int count)
  3. checkNotReadOnly(ByteBuffer buffer)
  4. contentOfUnreadBuffer(final ByteBuffer buffer)
  5. parseEsInfo(ByteBuffer read)
  6. read(@Nonnull final FileChannel src, @Nonnull final ByteBuffer dst, @Nonnegative final long position)
  7. read(ByteBuffer b)
  8. read(ByteBuffer bb, FileChannel ch)