Package org.lilyproject.bytes.impl

Examples of org.lilyproject.bytes.impl.DataOutputImpl


        RecordId recordId = idGenerator.newRecordId("123");

        Link link = Link.newBuilder().recordId(recordId).copyAll(false).copy("branch").set("x", "1").create();
        assertEquals("USER.123.!*,+branch,x=1", link.toString());
        assertEquals(link, Link.fromString(link.toString(), idGenerator));
        DataOutput dataOutput = new DataOutputImpl();
        link.write(dataOutput);
        assertEquals(link, Link.read(new DataInputImpl(dataOutput.toByteArray()), idGenerator));


        Map<String, String> ctxVarProps = new HashMap<String, String>();
        ctxVarProps.put("lang", "en");
        ctxVarProps.put("branch", "dev");
View Full Code Here


                .recordType(new QName(ns, "rt2"))
                .field(new QName(ns,"field1"), "def")
                .create();


        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

            byte[] bytes = ((RecordRvtImpl)value).getBytes();
            if (bytes != null) {
                return bytes;
            }
        }
        DataOutput dataOutput = new DataOutputImpl();
        encodeData(value, dataOutput, parentRecords);
        return dataOutput.toByteArray();
    }
View Full Code Here

    }

    @Override
    public byte[] toBytes(Object value, IdentityRecordStack parentRecords) throws RepositoryException,
            InterruptedException {
        DataOutput dataOutput = new DataOutputImpl();
        write(value, dataOutput, parentRecords);
        return dataOutput.toByteArray();
    }
View Full Code Here

                .value("boolean", Boolean.TRUE)
                .value("bytes", new ByteArray("foobar".getBytes()))
                .value("date", time)
                .build();

        DataOutput output = new DataOutputImpl();
        MetadataSerDeser.write(metadata, output);
        byte[] metadataBytes = output.toByteArray();

        Metadata readMetadata = MetadataSerDeser.read(new DataInputImpl(metadataBytes));
        assertEquals("value", readMetadata.get("string"));
        assertEquals(5, (int)readMetadata.getInt("int", null));
        assertEquals(99999999999L, (long)readMetadata.getLong("long", null));
View Full Code Here

     *
     * @param dependencies list of dependencies to serialize
     * @return byte array with the serialized format
     */
    byte[] serializeDependenciesForward(Collection<DependencyEntry> dependencies) throws IOException {
        final DataOutputImpl dataOutput = new DataOutputImpl();

        // total number of dependencies
        dataOutput.writeInt(dependencies.size());

        for (DependencyEntry dependencyEntry : dependencies) {
            // we store the master record id, because that is how they are stored in the backward table
            final byte[] masterTableBytes = Bytes.toBytes(dependencyEntry.getDependency().getTable());
            final byte[] masterBytes = dependencyEntry.getDependency().getRecordId().getMaster().toBytes();
            dataOutput.writeInt(masterTableBytes.length);
            dataOutput.writeBytes(masterTableBytes);
            dataOutput.writeInt(masterBytes.length);
            dataOutput.writeBytes(masterBytes);

            final byte[] variantPropertiesBytes = serializeVariantPropertiesPattern(createVariantPropertiesPattern(
                    dependencyEntry.getDependency().getRecordId().getVariantProperties(),
                    dependencyEntry.getMoreDimensionedVariants()));
            dataOutput.writeBytes(variantPropertiesBytes);
        }

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

     * @param variantPropertiesPattern pattern to serialize
     * @return serialized pattern
     */
    byte[] serializeVariantPropertiesPattern(DerefMapVariantPropertiesPattern variantPropertiesPattern)
            throws IOException {
        final DataOutput dataOutput = new DataOutputImpl();

        // total number of entries
        dataOutput.writeInt(variantPropertiesPattern.pattern.size());

        for (Map.Entry<String, String> patternEntry : variantPropertiesPattern.pattern.entrySet()) {
            // name
            final String name = patternEntry.getKey();
            dataOutput.writeUTF(name);

            // value (potentially null)
            final String value = patternEntry.getValue();
            dataOutput.writeUTF(value);
        }

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

    public static byte[] encodeName(QName qname) {
        String name = qname.getName();
        String namespace = qname.getNamespace();

        int sizeEstimate = (((name == null) ? 1 : (name.length() * 2)) + ((namespace == null) ? 1 : (namespace.length() * 2)));
        DataOutput dataOutput = new DataOutputImpl(sizeEstimate);

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

    public static byte[] encodeValueType(ValueType valueType) {
        return encodeValueType(valueType.getName());
    }

    public static byte[] encodeValueType(String valueTypeName) {
        DataOutput dataOutput = new DataOutputImpl();
        dataOutput.writeByte(valueTypeEncodingVersion);
        dataOutput.writeUTF(valueTypeName);
        return dataOutput.toByteArray();
    }
View Full Code Here

        for (QName fieldName : record.getFields().keySet()) {
            FieldType fieldType = typeManager.getFieldTypeByName(fieldName);
            Metadata metadata = record.getMetadata(fieldName);
            boolean hasMetadata = metadata != null && !metadata.getMap().isEmpty();

            DataOutput output = new DataOutputImpl();

            output.writeByte(hasMetadata ? FieldFlags.METADATA_V1 : FieldFlags.DEFAULT);
            output.writeBytes(fieldType.getValueType().toBytes(record.getField(fieldName), new IdentityRecordStack()));
            if (hasMetadata) {
                HBaseRepository.writeMetadataWithLengthSuffix(metadata, output);
            }

            event.addUpdatedField(fieldType.getId());

            kvs.add(new KeyValue(rowKey, family,
                    Bytes.add(new byte[]{LilyHBaseSchema.RecordColumn.DATA_PREFIX}, fieldType.getId().getBytes()),
                    output.toByteArray()));
        }
       
        // fields to delete, should we add these too?
        kvs.add(new KeyValue(rowKey, family, LilyHBaseSchema.RecordColumn.PAYLOAD.bytes, event.toJsonBytes()));
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.