Package org.lilyproject.bytes.impl

Examples of org.lilyproject.bytes.impl.DataInputImpl


            // there is no metadata
        } else if (metadataEncodingVersion == 1) {
            int metadataSize = Bytes.toInt(prefixedValue, prefixedValue.length - Bytes.SIZEOF_INT, Bytes.SIZEOF_INT);
            metadataSpace = metadataSize + Bytes.SIZEOF_INT;
            metadata = MetadataSerDeser.read(
                    new DataInputImpl(prefixedValue, prefixedValue.length - metadataSpace, metadataSize));
        } else {
            throw new RuntimeException("Unsupported field metadata encoding version: " + metadataEncodingVersion);
        }

        Object value = valueType.read(new DataInputImpl(prefixedValue, FieldFlags.SIZE_OF_FIELD_FLAGS,
                prefixedValue.length - FieldFlags.SIZE_OF_FIELD_FLAGS - metadataSpace));

        return new ExtractedField(fieldType, value, metadata);
    }
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

        chars[i++] = (char) nextInt(0xe000, 0xffff);
        String string = new String(chars);
        DataOutputImpl dataOutputImpl = new DataOutputImpl();
        dataOutputImpl.writeUTF(string);
        byte[] data = dataOutputImpl.toByteArray();
        DataInputImpl dataInputImpl = new DataInputImpl(data);
        String readUTF = dataInputImpl.readUTF();
        Assert.assertEquals(string, readUTF);
    }
View Full Code Here

        DataOutputImpl dataOutputImpl = new DataOutputImpl();
        String string =
                "Mary Shelley (30 August 1797 – 1 February 1851) was a British novelist"; // Note, the hyphen is not just a minus sign
        dataOutputImpl.writeUTF(string);
        byte[] data = dataOutputImpl.toByteArray();
        DataInputImpl dataInputImpl = new DataInputImpl(data);
        String readUTF = dataInputImpl.readUTF();
        Assert.assertEquals(string, readUTF);
    }
View Full Code Here

    public void testRussian() {
        DataOutputImpl dataOutputImpl = new DataOutputImpl();
        String string = "ТЕСТ"; // Note, these are russian characters
        dataOutputImpl.writeUTF(string);
        byte[] data = dataOutputImpl.toByteArray();
        DataInputImpl dataInputImpl = new DataInputImpl(data);
        String readUTF = dataInputImpl.readUTF();
        Assert.assertEquals(string, readUTF);
    }
View Full Code Here

        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

        Assert.assertEquals(Math.abs(l), dataInput.readVLong());
    }

    public void testIndexOf() {
        byte[] source = {0x09, 0x08, 0x07, 0x06, 0x00, 0x05, 0x04, 0x03, 0x02, 0x01};
        Assert.assertEquals(4, new DataInputImpl(source, 0, 10).indexOf((byte) 0x00));
        Assert.assertEquals(2, new DataInputImpl(source, 2, 8).indexOf((byte) 0x00));
        Assert.assertEquals(-1, new DataInputImpl(source, 7, 3).indexOf((byte) 0x00));
    }
View Full Code Here

     *                   existing bytes can be reused.
     */
    private synchronized void decode(boolean clearBytes) {
        if (delegate == null) {
            try {
                delegate = (IdRecord)recordValueType.read(new DataInputImpl(bytes));
            } catch (RepositoryException e) {
                throw new RuntimeException("Failed to decode record ");
            } catch (InterruptedException e) {
                Thread.currentThread().interrupt();
            }
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

TOP

Related Classes of org.lilyproject.bytes.impl.DataInputImpl

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.