Package com.thinkaurelius.titan.diskstorage.util

Examples of com.thinkaurelius.titan.diskstorage.util.WriteByteBuffer


        assert value >= 0;
        writeUnsigned(out, value);
    }

    public static StaticBuffer positiveByteBuffer(final long value) {
        WriteBuffer buffer = new WriteByteBuffer(positiveLength(value));
        writePositive(buffer, value);
        return buffer.getStaticBuffer();
    }
View Full Code Here


    public static StaticBuffer positiveByteBuffer(long[] value) {
        int len = 0;
        for (long aValue : value)
            len += positiveLength(aValue);

        WriteBuffer buffer = new WriteByteBuffer(len);

        for (long aValue : value)
            writePositive(buffer, aValue);

        return buffer.getStaticBuffer();
    }
View Full Code Here

        etid = (IDManager.getTypeCount(etid) << 1) + getDirection(dirID);
        VariableLong.writePositiveWithPrefix(out, etid, getRelationType(dirID), PREFIX_BIT_LEN);
    }

    public static StaticBuffer getEdgeType(long etid, int dirID) {
        WriteBuffer b = new WriteByteBuffer(edgeTypeLength(etid));
        IDHandler.writeEdgeType(b, etid, dirID);
        return b.getStaticBuffer();
    }
View Full Code Here

    private void readWriteTest(final ReadWriteLong impl, long maxValue, long jump, boolean negative, boolean backward) {
        Preconditions.checkArgument(maxValue%jump==0);
        long allocate = maxValue / jump * 8 * (negative?2:1);
        Preconditions.checkArgument(allocate < (1 << 28));
        WriteBuffer wb = new WriteByteBuffer((int) allocate);
        int num = 0;
        StopWatch w = new StopWatch();
        w.start();
        for (long i = (negative?-maxValue:0); i <= maxValue; i += jump) {
            impl.write(wb, i);
            num++;
        }
        //for (int i=0;i<b.remaining();i++) System.out.print(b.get(i)+"|");
        w.stop();
        ReadBuffer rb = wb.getStaticBuffer().asReadBuffer();
        log.info("Writing " + num + " longs in " + rb.length() + " bytes. in time: " + w.getTime());

        final ReadVerify read = new ReadVerify() {
            @Override
            public void next(ReadBuffer rb, long expected) {
                int beforePos = rb.getPosition();
                long value = impl.read(rb);
                assertEquals(expected, value);
                int length = Math.abs(rb.getPosition()-beforePos);
                assertEquals("On: " + expected,length,impl.length(expected));
            }
        };

        if (backward) {
            rb.movePosition(rb.length()-1);
            for (long i = maxValue; i != (negative?-maxValue:0); i -= jump) {
                read.next(rb,i);
            }
        } else {
            for (long i = (negative?-maxValue:0); i <= maxValue; i += jump) {
                read.next(rb, i);
            }
        }

        //Test boundaries
        wb = new WriteByteBuffer(512);
        impl.write(wb,0);
        impl.write(wb,Long.MAX_VALUE);
        if (negative) impl.write(wb,-Long.MAX_VALUE);
        rb = wb.getStaticBuffer().asReadBuffer();
        if (backward) {
            rb.movePosition(rb.length()-1);
            if (negative) assertEquals(-Long.MAX_VALUE, impl.read(rb));
            assertEquals(Long.MAX_VALUE, impl.read(rb));
            assertEquals(0, impl.read(rb));
View Full Code Here

            assertEquals(id,vals[0]);
            assertEquals(dirID, vals[1]);
            assertFalse(rb.hasRemaining());

            //Inline edge type
            WriteBuffer wb = new WriteByteBuffer(9);
            IDHandler.writeInlineEdgeType(wb, id);
            long newId = IDHandler.readInlineEdgeType(wb.getStaticBuffer().asReadBuffer());
            assertEquals(id,newId);

            //Compare to Kryo
            DataOutput out = serializer.getDataOutput(10, true);
            IDHandler.writeEdgeType(out, id, dirID);
View Full Code Here

* {@link ConsistentKeyLocker} and vice-versa.
*/
public class ConsistentKeyLockerSerializer {
    
    public StaticBuffer toLockKey(StaticBuffer key, StaticBuffer column) {
        WriteBuffer b = new WriteByteBuffer(key.length() + column.length() + 4);
        b.putInt(key.length());
        WriteBufferUtil.put(b,key);
        WriteBufferUtil.put(b,column);
        return b.getStaticBuffer();
    }
View Full Code Here

        WriteBufferUtil.put(b,column);
        return b.getStaticBuffer();
    }
   
    public StaticBuffer toLockCol(long ts, StaticBuffer rid) {
        WriteBuffer b = new WriteByteBuffer(rid.length() + 8);
        b.putLong(ts);
        WriteBufferUtil.put(b, rid);
        return b.getStaticBuffer();
    }
View Full Code Here

    }

    private static final StaticBuffer relationID2ByteBuffer(RelationIdentifier rid) {
        long[] longs = rid.getLongRepresentation();
        Preconditions.checkArgument(longs.length == 3);
        WriteBuffer buffer = new WriteByteBuffer(24);
        for (int i = 0; i < 3; i++) VariableLong.writePositive(buffer, longs[i]);
        return buffer.getStaticBuffer();
    }
View Full Code Here

TOP

Related Classes of com.thinkaurelius.titan.diskstorage.util.WriteByteBuffer

Copyright © 2018 www.massapicom. 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.