Package org.lilyproject.bytes.api

Examples of org.lilyproject.bytes.api.DataOutput





    public static void writeMetadataWithLengthSuffix(Metadata metadata, DataOutput output) {
        DataOutput tmp = new DataOutputImpl();
        MetadataSerDeser.write(metadata, tmp);
        byte[] metadataBytes = tmp.toByteArray();
        output.writeBytes(metadataBytes);
        output.writeInt(metadataBytes.length);
    }
View Full Code Here


    }

    public void testRandomString() {
        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

    }

    public void testRandomVString() {
        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

        String readUTF = dataInputImpl.readUTF();
        Assert.assertEquals(string, readUTF);
    }

    public void testAllTypes() {
        DataOutput dataOutput = new DataOutputImpl();
        boolean b = random.nextBoolean();
        dataOutput.writeBoolean(b);
        byte[] bytes = new byte[10];
        random.nextBytes(bytes);
        dataOutput.writeByte(bytes[0]);
        dataOutput.writeBytes(bytes);
        double d = random.nextDouble();
        dataOutput.writeDouble(d);
        float f = random.nextFloat();
        dataOutput.writeFloat(f);
        int i = random.nextInt();
        dataOutput.writeInt(i);
        long l = random.nextLong();
        dataOutput.writeLong(l);
        short s = (short) 4;
        dataOutput.writeShort(s);
        String string = randomUnicodeString();
        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);
View Full Code Here

                throw new RepositoryException(String.format("Incorrect type of value provided for field %s. "
                        + "Expected instance of %s but got %s.", fieldType.getName(), valueType.getType().getName(),
                        fieldValue.getClass().getName()));
            }

            DataOutput dataOutput = new DataOutputImpl();
            boolean hasMetadata = metadata != null && !metadata.getMap().isEmpty();

            dataOutput.writeByte(hasMetadata ? FieldFlags.METADATA_V1 : FieldFlags.DEFAULT);
            try {
                valueType.write(fieldValue, dataOutput, new IdentityRecordStack(parentRecord));
            } catch (InterruptedException e) {
                throw e;
            } catch (Exception e) {
                // wrap the exception so that it is known what field causes the problem
                throw new RepositoryException("Error serializing value for field " + fieldType.getName(), e);
            }

            if (hasMetadata) {
                if (fieldType.getScope() == Scope.VERSIONED_MUTABLE) {
                    throw new RuntimeException("Field metadata is currently not supported for versioned-mutable fields.");
                }
                if (fieldType.getValueType().getDeepestValueType().getBaseName().equals("BLOB")) {
                    throw new RuntimeException("Field metadata is currently not supported for BLOB fields.");
                }
                writeMetadataWithLengthSuffix(metadata, dataOutput);
            }

            return dataOutput.toByteArray();
        }
View Full Code Here

        if (compareOp != CompareOp.EQUAL && compareOp != CompareOp.NOT_EQUAL) {
            throw new IllegalArgumentException("FieldValueFilter does not support this compare operator: " + compareOp);
        }

        FieldType fieldType = repository.getTypeManager().getFieldTypeByName(filter.getField());
        DataOutput dataOutput = new DataOutputImpl();
        fieldType.getValueType().write(filter.getFieldValue(), dataOutput, new IdentityRecordStack());
        byte[] fieldValue = dataOutput.toByteArray();

        LilyFieldSingleColumnValueFilter hbaseFilter = new LilyFieldSingleColumnValueFilter(RecordCf.DATA.bytes,
                ((FieldTypeImpl)fieldType).getQualifier(), HBaseRecordFilterUtil.translateCompareOp(compareOp), fieldValue);
        hbaseFilter.setFilterIfMissing(filter.getFilterIfMissing());
View Full Code Here

    private RecordAsBytesConverter() {
    }

    public static final byte[] write(Record record, LRepository repository)
            throws RepositoryException, InterruptedException {
        DataOutput output = new DataOutputImpl();
        write(record, output, repository);
        return output.toByteArray();
    }
View Full Code Here

        return record;
    }

    public static final byte[] writeIdRecord(IdRecord record, LRepository repository)
            throws RepositoryException, InterruptedException {
        DataOutput output = new DataOutputImpl();
        writeIdRecord(record, output, repository);
        return output.toByteArray();
    }
View Full Code Here

    }

    @Override
    public byte[] toBytes() {
        if (recordIdBytes == null) {
            DataOutput dataOutput = new DataOutputImpl();
            writeBytes(dataOutput);
            recordIdBytes = dataOutput.toByteArray();
        }
        return recordIdBytes;
    }
View Full Code Here

    }

    @Override
    public byte[] toBytes() {
        if (uuidBytes == null) {
            DataOutput dataOutput = new DataOutputImpl(17);
            writeBytes(dataOutput);
            uuidBytes = dataOutput.toByteArray();
        }
        return uuidBytes;
    }
View Full Code Here

TOP

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

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.