Package com.netflix.astyanax.serializers

Examples of com.netflix.astyanax.serializers.ByteBufferOutputStream


    public ByteBuffer serialize() {
        if (serialized != null) {
            return serialized.duplicate();
        }

        ByteBufferOutputStream out = new ByteBufferOutputStream();

        int i = 0;
        for (Component c : components) {
            Serializer<?> s = serializerForPosition(i);
            ByteBuffer cb = c.getBytes(s);
            if (cb == null) {
                cb = ByteBuffer.allocate(0);
            }

            if (dynamic) {
                String comparator = comparatorForPosition(i);
                if (comparator == null) {
                    comparator = c.getComparator();
                }
                if (comparator == null) {
                    comparator = ComparatorType.BYTESTYPE.getTypeName();
                }
                int p = comparator.indexOf("(reversed=true)");
                boolean desc = false;
                if (p >= 0) {
                    comparator = comparator.substring(0, p);
                    desc = true;
                }
                if (aliasToComparatorMapping.inverse().containsKey(comparator)) {
                    byte a = aliasToComparatorMapping.inverse().get(comparator);
                    if (desc) {
                        a = (byte) Character.toUpperCase((char) a);
                    }
                    out.writeShort((short) (0x8000 | a));
                }
                else {
                    out.writeShort((short) comparator.length());
                    out.write(ByteBufferUtil.bytes(comparator));
                }
            }
            out.writeShort((short) cb.remaining());
            out.write(cb.slice());
            out.write(c.getEquality().toByte());
            i++;
        }

        serialized = out.getByteBuffer();
        return serialized.duplicate();
    }
View Full Code Here


    public ByteBuffer serialize() throws Exception {
        if (mutationMap.isEmpty()) {
            throw new Exception("Mutation is empty");
        }

        ByteBufferOutputStream out       = new ByteBufferOutputStream();
        TIOStreamTransport     transport = new TIOStreamTransport(out);
        batch_mutate_args      args      = new batch_mutate_args();
        args.setMutation_map(mutationMap);

        try {
            args.write(new TBinaryProtocol(transport));
        }
        catch (TException e) {
            throw ThriftConverter.ToConnectionPoolException(e);
        }

        return out.getByteBuffer();
    }
View Full Code Here


public class CompositeTest {
    @Test
    public void testByteBufferOutputStream() throws Exception {
        ByteBufferOutputStream out = new ByteBufferOutputStream();

        int length = 0;
        for ( int i = 0; i < 300; i++ ) {
            length += i;
            out.write( StringUtils.repeat( "*", i ).getBytes() );
        }

        ByteBuffer buffer = out.getByteBuffer();
        Assert.assertEquals( buffer.capacity(), length );
    }
View Full Code Here

TOP

Related Classes of com.netflix.astyanax.serializers.ByteBufferOutputStream

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.