List of usage examples for java.nio ByteBuffer isDirect
public abstract boolean isDirect();
From source file:org.apache.hadoop.hdfs.protocol.datatransfer.PacketReceiver.java
private static void doReadFully(ReadableByteChannel ch, InputStream in, ByteBuffer buf) throws IOException { if (ch != null) { readChannelFully(ch, buf);//from w w w. jav a 2s. c om } else { Preconditions.checkState(!buf.isDirect(), "Must not use direct buffers with InputStream API"); IOUtils.readFully(in, buf.array(), buf.arrayOffset() + buf.position(), buf.remaining()); buf.position(buf.position() + buf.remaining()); } }
From source file:org.apache.hadoop.io.ElasticByteBufferPool.java
@Override public synchronized void putBuffer(ByteBuffer buffer) { TreeMap<Key, ByteBuffer> tree = getBufferTree(buffer.isDirect()); while (true) { Key key = new Key(buffer.capacity(), System.nanoTime()); if (!tree.containsKey(key)) { tree.put(key, buffer);/*from www. j av a 2s . co m*/ return; } // Buffers are indexed by (capacity, time). // If our key is not unique on the first try, we try again, since the // time will be different. Since we use nanoseconds, it's pretty // unlikely that we'll loop even once, unless the system clock has a // poor granularity. } }
From source file:org.apache.hadoop.mapred.nativetask.buffer.DirectBufferPool.java
public void returnBuffer(ByteBuffer buffer) throws IOException { if (null == buffer || !buffer.isDirect()) { throw new IOException("the buffer is null or the buffer returned is not direct buffer"); }/*from w w w.j ava 2 s .c o m*/ buffer.clear(); int capacity = buffer.capacity(); Queue<WeakReference<ByteBuffer>> list = bufferMap.get(capacity); if (null == list) { list = new ConcurrentLinkedQueue<WeakReference<ByteBuffer>>(); Queue<WeakReference<ByteBuffer>> prev = bufferMap.putIfAbsent(capacity, list); if (prev != null) { list = prev; } } list.add(new WeakReference<ByteBuffer>(buffer)); }
From source file:org.apache.tajo.storage.thirdparty.orc.ByteBufferAllocatorPool.java
public void putBuffer(ByteBuffer buffer) { TreeMap<Key, ByteBuffer> tree = getBufferTree(buffer.isDirect()); while (true) { Key key = new Key(buffer.capacity(), currentGeneration++); if (!tree.containsKey(key)) { tree.put(key, buffer);/*from w w w . ja va 2s . c om*/ return; } // Buffers are indexed by (capacity, generation). // If our key is not unique on the first try, we try again } }