Package org.lilyproject.bytes.impl

Examples of org.lilyproject.bytes.impl.DataOutputImpl





    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

        // 3
        chars[i++] = (char) nextInt(0x800, 0xd7ff);
        // 4
        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

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

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

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

    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

        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

TOP

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

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.