Package org.lilyproject.bytes.api

Examples of org.lilyproject.bytes.api.DataInput


        dataOutput.writeUTF(string);
        dataOutput.writeVInt(Math.abs(i));
        dataOutput.writeVLong(Math.abs(l));

        byte[] data = dataOutput.toByteArray();
        DataInput dataInput = new DataInputImpl(data);
        Assert.assertEquals(b, dataInput.readBoolean());
        Assert.assertEquals(bytes[0], dataInput.readByte());
        Assert.assertArrayEquals(bytes, dataInput.readBytes(10));
        Assert.assertEquals(d, dataInput.readDouble(), 0.0001);
        Assert.assertEquals(f, dataInput.readFloat(), 0.0001);
        Assert.assertEquals(i, dataInput.readInt());
        Assert.assertEquals(l, dataInput.readLong());
        Assert.assertEquals(s, dataInput.readShort());
        Assert.assertEquals(string, dataInput.readUTF());
        Assert.assertEquals(Math.abs(i), dataInput.readVInt());
        Assert.assertEquals(Math.abs(l), dataInput.readVLong());
    }
View Full Code Here


                    int length = dataInput.getSize();
                    dataInput.setPosition(length - 8);
                    int nrOfVariants = dataInput.readInt();
                    int masterRecordIdLength = dataInput.readInt();

                    DataInput masterRecordIdInput = new DataInputImpl((DataInputImpl)dataInput, position, masterRecordIdLength);
                    RecordId masterRecordId = decode(masterRecordIdInput, idGenerator);
                    dataInput.setPosition(masterRecordIdLength);

                    SortedMap<String, String> varProps = new TreeMap<String, String>();
                    for (int i = 0; i < nrOfVariants; i++) {
View Full Code Here

        byte idType = dataInput.readByte();
        // Note: will throw arrayindexoutofbounds if id is not known
        IdType id = ID_TYPES[idType];

        DataInput[] splitted = id.factory.splitInMasterAndVariant(dataInput);
        DataInput masterIdInput = splitted[0];
        DataInput variantParamsInput = splitted[1];

        RecordId masterRecordId = id.factory.fromBytes(masterIdInput, this);

        if (variantParamsInput != null) {
            return new VariantRecordId(masterRecordId, variantParamsInput, this);
View Full Code Here

    @Override
    public DataInput[] splitInMasterAndVariant(DataInput dataInput) {
        if (dataInput.getSize() - dataInput.getPosition() > UUID_LENGTH) {

            DataInput keyInput = new DataInputImpl(((DataInputImpl) dataInput), dataInput.getPosition(),
                    dataInput.getPosition() + 16);

            DataInput variantInput = new DataInputImpl(((DataInputImpl) dataInput), dataInput.getPosition() + 16,
                    dataInput.getSize() - 17);

            return new DataInput[]{keyInput, variantInput};
        } else {
            return new DataInput[]{dataInput, null};
View Full Code Here

        int sepPos = dataInput.indexOf(VARIANT_SEPARATOR);

        if (sepPos == -1) {
            return new DataInput[]{dataInput, null};
        } else {
            DataInput keyInput =
                    new DataInputImpl(((DataInputImpl) dataInput), dataInput.getPosition(), sepPos - dataInput.getPosition());
            DataInput variantInput =
                    new DataInputImpl(((DataInputImpl) dataInput), sepPos + 1, dataInput.getSize() - (sepPos + 1));

            return new DataInput[]{keyInput, variantInput};
        }
    }
View Full Code Here

    }

    public String toString() {
        if (string == null) {
            if (uuid == null) {
                DataInput dataInput = new DataInputImpl(bytes);
                this.uuid = new UUID(dataInput.readLong(), dataInput.readLong());
            }
            this.string = uuid.toString();
        }
        return string;
    }
View Full Code Here

        DataOutput dataOutput = new DataOutputImpl();

        // Do a write and lets not get exceptions
        recordVT.write(createdRecord, dataOutput, new IdentityRecordStack());

        DataInput dataInput = new DataInputImpl(dataOutput.toByteArray());

        // Do a read and lets not get exceptions
        Record readRecord = recordVT.read(dataInput);

        assertEquals(createdRecord.getFields(), readRecord.getFields());
View Full Code Here

        for (int i = 0; i < 1000; i++) {
            String string = randomUnicodeString();
            DataOutput dataOutput = new DataOutputImpl();
            dataOutput.writeUTF(string);
            byte[] bytes = dataOutput.toByteArray();
            DataInput dataInput = new DataInputImpl(bytes);
            String result = dataInput.readUTF();
            Assert.assertEquals(string, result);
        }
    }
View Full Code Here

        for (int i = 0; i < 1000; i++) {
            String string = randomUnicodeString();
            DataOutput dataOutput = new DataOutputImpl();
            dataOutput.writeVUTF(string);
            byte[] bytes = dataOutput.toByteArray();
            DataInput dataInput = new DataInputImpl(bytes);
            String result = dataInput.readVUTF();
            Assert.assertEquals(string, result);
        }
    }
View Full Code Here

        dataOutput.writeUTF(name);
        return dataOutput.toByteArray();
    }

    public static QName decodeName(byte[] bytes) {
        DataInput dataInput = new DataInputImpl(bytes);
        String namespace = dataInput.readUTF();
        String name = dataInput.readUTF();
        return new QName(namespace, name);
    }
View Full Code Here

TOP

Related Classes of org.lilyproject.bytes.api.DataInput

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.