Package java.nio

Examples of java.nio.ByteBuffer.duplicate()


        for (int i = 0; i < size(); i++)
        {
            ByteBuffer bb = get(i);
            ByteBufferUtil.writeShortLength(result, bb.remaining());
            result.put(bb.duplicate());
            result.put((byte)0);
        }
        result.flip();
        return result;
    }
View Full Code Here


                            numbytes += channel.read(message);
                        }
                        message.position(0);
                        synchronized (recvQueue) {
                            recvQueue
                                    .put(new Message(message.duplicate(), sid));
                        }
                        msgLength.position(0);
                    }
                }
View Full Code Here

                            numbytes += channel.read(message);
                        }
                        message.position(0);
                        synchronized (recvQueue) {
                            recvQueue
                                    .put(new Message(message.duplicate(), sid));
                        }
                        msgLength.position(0);
                    }
                }
View Full Code Here

            if (count > buffer.remaining()) {
                throw runtime.newIndexError("read count too big for output buffer");
            }

            if (count < buffer.remaining()) {
                buffer = buffer.duplicate();
                buffer.limit(count);
            }

            // TODO: This used to use ChannelStream and honor its buffers; it does not honor OpenFile buffers now
            return runtime.newFixnum(openFile.readChannel().read(buffer));
View Full Code Here

        /**
         * Test the basic write and drain
         */
        final ByteBuffer b = ByteBuffer.allocate(5);
        wstream.enqueue(b.duplicate());
        assertEquals( 5, wstream.calculatePendingWriteDelta(EstTime.currentTimeMillis() + 5));
        wstream.drainTo( channel, wstream.swapAndSerializeQueuedWrites(pool));
        assertEquals( 0, wstream.calculatePendingWriteDelta(EstTime.currentTimeMillis() + 5));

        Thread.sleep(20);
View Full Code Here

        assertEquals( 0, wstream.calculatePendingWriteDelta(EstTime.currentTimeMillis() + 5));

        Thread.sleep(20);
        EstTimeUpdater.update(System.currentTimeMillis());

        wstream.enqueue(b.duplicate());
        assertEquals( 5, wstream.calculatePendingWriteDelta(EstTime.currentTimeMillis() + 5));
        wstream.enqueue(b.duplicate());
        assertEquals( 5, wstream.calculatePendingWriteDelta(EstTime.currentTimeMillis() + 5));
        channel.m_behavior = MockChannel.PARTIAL;
        wstream.drainTo( channel, wstream.swapAndSerializeQueuedWrites(pool));
View Full Code Here

        Thread.sleep(20);
        EstTimeUpdater.update(System.currentTimeMillis());

        wstream.enqueue(b.duplicate());
        assertEquals( 5, wstream.calculatePendingWriteDelta(EstTime.currentTimeMillis() + 5));
        wstream.enqueue(b.duplicate());
        assertEquals( 5, wstream.calculatePendingWriteDelta(EstTime.currentTimeMillis() + 5));
        channel.m_behavior = MockChannel.PARTIAL;
        wstream.drainTo( channel, wstream.swapAndSerializeQueuedWrites(pool));
        assertEquals( 5, wstream.calculatePendingWriteDelta(EstTime.currentTimeMillis() + 5));
View Full Code Here

            LOG.trace("c_aggregate position :" + c_aggregate.position());
            LOG.trace("c_aggregate capacity :" + c_aggregate.capacity());

            if (needsConversion == null) {
                VoltTable old_table = PrivateVoltTableFactory.createVoltTableFromBuffer(c_aggregate.duplicate(), true);
                needsConversion = SavedTableConverter.needsConversion(old_table, new_catalog_table);
            }

            final VoltTable old_table = PrivateVoltTableFactory.createVoltTableFromBuffer(c_aggregate, true);
            if (needsConversion) {
View Full Code Here

            throw new NullPointerException("Null bufferArray argument");
        if (!(isBufferArray(bufferArray)))
            throw new IllegalArgumentException("The passed argument is not a buffer array");
        ByteBuffer bb = ((DirectDataStorages.DirectStorage)((AbstractBufferArray)bufferArray).storage).bb;
        ByteOrder o = bb.order();
        return bufferArray.isImmutable() ? bb.asReadOnlyBuffer().order(o) : bb.duplicate().order(o);
    }

    /**
     * Returns the start offset in the buffer returned by {@link #getByteBuffer(Array)} call,
     * corresponding to the first element of the passed AlgART array.
View Full Code Here

    @Test
    public void testDataOutputDirectByteBuffer() throws IOException
    {
        ByteBuffer buf = wrap(new byte[345], true);
        DataOutputByteBuffer write = new DataOutputByteBuffer(buf.duplicate());
        DataInput canon = testWrite(write);
        DataInput test = new DataInputStream(new ByteArrayInputStream(ByteBufferUtil.getArray(buf)));
        testRead(test, canon);
    }
View Full Code Here

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.