Example usage for java.io DataOutput writeLong

List of usage examples for java.io DataOutput writeLong

Introduction

In this page you can find the example usage for java.io DataOutput writeLong.

Prototype

void writeLong(long v) throws IOException;

Source Link

Document

Writes a long value, which is comprised of eight bytes, to the output stream.

Usage

From source file:net.geertvos.theater.core.util.UUIDGen.java

/** writes a uuid to an output stream. */
public static void write(UUID uuid, DataOutput dos) throws IOException {
    dos.writeLong(uuid.getMostSignificantBits());
    dos.writeLong(uuid.getLeastSignificantBits());
}

From source file:org.apache.hadoop.hdfs.server.namenode.FSImageSerialization.java

/**
 * Serialize a {@link INodeSymlink} node
 * @param node The node to write// www .j  a v  a 2  s .com
 * @param out The {@link DataOutput} where the fields are written
 */
private static void writeINodeSymlink(INodeSymlink node, DataOutput out) throws IOException {
    writeLocalName(node, out);
    out.writeLong(node.getId());
    out.writeShort(0); // replication
    out.writeLong(0); // modification time
    out.writeLong(0); // access time
    out.writeLong(0); // preferred block size
    out.writeInt(-2); // # of blocks

    Text.writeString(out, node.getSymlinkString());
    writePermissionStatus(node, out);
    out.writeLong(0); // access count IDecider
    out.writeInt(0); // is cached flag IDecider
}

From source file:org.apache.hadoop.hdfs.server.namenode.FSImageSerialization.java

/**
 * Serialize a {@link INodeDirectory}//from  ww w .j  ava 2 s  .c  o m
 * @param node The node to write
 * @param out The {@link DataOutput} where the fields are written 
 */
public static void writeINodeDirectory(INodeDirectory node, DataOutput out) throws IOException {
    writeLocalName(node, out);
    out.writeLong(node.getId());
    out.writeShort(0); // replication
    out.writeLong(node.getModificationTime());
    out.writeLong(0); // access time
    out.writeLong(0); // preferred block size
    out.writeInt(-1); // # of blocks

    out.writeLong(node.getNsQuota());
    out.writeLong(node.getDsQuota());
    if (node instanceof INodeDirectorySnapshottable) {
        out.writeBoolean(true);
    } else {
        out.writeBoolean(false);
        out.writeBoolean(node instanceof INodeDirectoryWithSnapshot);
    }

    writePermissionStatus(node, out);
    /*out.writeLong(0);   access count IDecider
    out.writeInt(0);   is cached flag IDecider*/
}

From source file:org.apache.hadoop.hdfs.server.namenode.FSImageSerialization.java

/**
 * Serialize a {@link INodeDirectory}//w w w .j a  va2  s .  c  om
 * @param a The node to write
 * @param out The {@link DataOutput} where the fields are written 
 */
public static void writeINodeDirectoryAttributes(INodeDirectoryAttributes a, DataOutput out)
        throws IOException {
    writeLocalName(a, out);
    writePermissionStatus(a, out);
    out.writeLong(a.getModificationTime());

    out.writeLong(a.getNsQuota());
    out.writeLong(a.getDsQuota());
}

From source file:org.apache.hadoop.hdfs.server.namenode.FSImageSerialization.java

/** Serialize a {@link INodeReference} node */
private static void writeINodeReference(INodeReference ref, DataOutput out, boolean writeUnderConstruction,
        ReferenceMap referenceMap) throws IOException {
    writeLocalName(ref, out);/*from  w w  w .  j  a v a  2 s .c om*/
    out.writeLong(ref.getId());
    out.writeShort(0); // replication
    out.writeLong(0); // modification time
    out.writeLong(0); // access time
    out.writeLong(0); // preferred block size
    out.writeInt(-3); // # of blocks

    final boolean isWithName = ref instanceof INodeReference.WithName;
    out.writeBoolean(isWithName);

    if (!isWithName) {
        Preconditions.checkState(ref instanceof INodeReference.DstReference);
        // dst snapshot id
        out.writeInt(((INodeReference.DstReference) ref).getDstSnapshotId());
    } else {
        out.writeInt(((INodeReference.WithName) ref).getLastSnapshotId());
    }

    final INodeReference.WithCount withCount = (INodeReference.WithCount) ref.getReferredINode();
    referenceMap.writeINodeReferenceWithCount(withCount, out, writeUnderConstruction);
    out.writeLong(0); // access count IDecider
    out.writeInt(0); // is cached flag IDecider
}

From source file:org.apache.marmotta.kiwi.io.KiWiIO.java

/**
 * Efficiently serialize a KiWiTriple to a DataOutput destination.
 *
 * @param output the destination//from  ww  w  .  jav a 2  s .  com
 * @param triple the KiWiTriple to serialize
 * @throws IOException
 */
public static void writeTriple(DataOutput output, KiWiTriple triple) throws IOException {
    output.writeLong(triple.getId());

    // in case subject and object are both uris we use a special prefix-compressed mode
    if (triple.getSubject().isUriResource() && triple.getObject().isUriResource()) {
        String sUri = triple.getSubject().stringValue();
        String oUri = triple.getObject().stringValue();

        String prefix = StringUtils.getCommonPrefix(sUri, oUri);

        output.writeByte(MODE_PREFIX);
        DataIO.writeString(output, prefix);

        output.writeLong(triple.getSubject().getId());
        DataIO.writeString(output, sUri.substring(prefix.length()));
        output.writeLong(triple.getSubject().getCreated().getTime());

        writeURI(output, triple.getPredicate());

        output.writeLong(triple.getObject().getId());
        DataIO.writeString(output, oUri.substring(prefix.length()));
        output.writeLong(triple.getObject().getCreated().getTime());
    } else {
        output.writeByte(MODE_DEFAULT);

        writeNode(output, triple.getSubject());
        writeURI(output, triple.getPredicate());
        writeNode(output, triple.getObject());

    }

    writeNode(output, triple.getContext());
    writeNode(output, triple.getCreator());
    output.writeBoolean(triple.isDeleted());
    output.writeBoolean(triple.isInferred());
    output.writeBoolean(triple.isNewTriple());
    output.writeLong(triple.getCreated().getTime());
    if (triple.getDeletedAt() != null) {
        output.writeLong(triple.getDeletedAt().getTime());
    } else {
        output.writeLong(0);
    }
}

From source file:org.apache.marmotta.kiwi.io.KiWiIO.java

/**
 * Efficiently serialize a KiWiAnonResource to a DataOutput destination.
 *
 * @param out the destination//w  ww .  j  av  a2  s  .com
 * @param bnode the KiWiAnonResource to serialize
 * @throws IOException
 */
public static void writeBNode(DataOutput out, KiWiAnonResource bnode) throws IOException {
    if (bnode == null) {
        out.writeLong(-1L);
    } else {
        out.writeLong(bnode.getId());
        DataIO.writeString(out, bnode.stringValue());
        out.writeLong(bnode.getCreated().getTime());
    }
}

From source file:org.apache.marmotta.kiwi.io.KiWiIO.java

/**
 * Efficiently serialize a KiWiIntLiteral to a DataOutput destination.
 *
 * @param out the destination/*from   w ww  .j a  v a  2  s . co m*/
 * @param literal the KiWiIntLiteral to serialize
 * @throws IOException
 */
public static void writeIntLiteral(DataOutput out, KiWiIntLiteral literal) throws IOException {
    if (literal == null) {
        out.writeLong(-1L);
    } else {
        out.writeLong(literal.getId());
        out.writeLong(literal.getIntContent());
        writeURI(out, literal.getType());
        out.writeLong(literal.getCreated().getTime());
    }
}

From source file:org.apache.marmotta.kiwi.io.KiWiIO.java

/**
 * Efficiently serialize a KiWiDateLiteral to a DataOutput destination.
 *
 * @param out the destination//from w  ww  .  ja  va 2  s  . co m
 * @param literal the KiWiDateLiteral to serialize
 * @throws IOException
 */
public static void writeDateLiteral(DataOutput out, KiWiDateLiteral literal) throws IOException {
    if (literal == null) {
        out.writeLong(-1L);
    } else {
        out.writeLong(literal.getId());
        out.writeLong(literal.getDateContent().getMillis());
        out.writeInt(literal.getDateContent().getZone().getOffset(literal.getDateContent()));
        writeURI(out, literal.getType());
        out.writeLong(literal.getCreated().getTime());
    }
}

From source file:org.apache.marmotta.kiwi.io.KiWiIO.java

/**
 * Efficiently serialize a KiWiDoubleLiteral to a DataOutput destination.
 *
 * @param out the destination//  w  w w  .jav  a2s.c  o  m
 * @param literal the KiWiDoubleLiteral to serialize
 * @throws IOException
 */
public static void writeDoubleLiteral(DataOutput out, KiWiDoubleLiteral literal) throws IOException {
    if (literal == null) {
        out.writeLong(-1L);
    } else {
        out.writeLong(literal.getId());
        out.writeDouble(literal.getDoubleContent());
        writeURI(out, literal.getType());
        out.writeLong(literal.getCreated().getTime());
    }
}