Example usage for java.io DataOutput writeInt

List of usage examples for java.io DataOutput writeInt

Introduction

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

Prototype

void writeInt(int v) throws IOException;

Source Link

Document

Writes an int value, which is comprised of four bytes, to the output stream.

Usage

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

/**
 * Serialize a {@link INodeSymlink} node
 * @param node The node to write//  ww  w  .  j  a v a2  s  .co m
 * @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}/*ww w.jav  a  2 s.com*/
 * @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:com.fiorano.openesb.application.DmiObject.java

/**
 * Utility method to write a DmiObject to output stream
 * @param dmi dmi object//from   w  w  w .  j  av a2  s . c o  m
 * @param out output stream
 * @param versionNo version
 * @throws IOException IOException
 */
public static void toStream(DmiObject dmi, DataOutput out, int versionNo) throws IOException {
    if (dmi != null) {
        out.writeInt(1);
        dmi.toStream(out, versionNo);
    } else
        out.writeInt(0);
}

From source file:com.fiorano.openesb.application.DmiObject.java

/**
 * Utility method to write a list to output stream
 * @param list list// w w w  .  ja va 2s .co  m
 * @param out output stream
 * @param versionNo version
 * @throws IOException
 */
public static void toStream(List list, DataOutput out, int versionNo) throws IOException {
    try {
        if (list != null) {
            out.writeInt(list.size());
            for (Object aList : list) {
                DmiObject dmi = (DmiObject) aList;
                dmi.toStream(out, versionNo);
            }
        } else
            out.writeInt(0);
    } finally {
        // Not clearing this will lead to invalid objects in memory
        MapThreadLocale.getInstance().getMap().clear();
    }
}

From source file:org.apache.hadoop.hbase.KeyValueUtil.java

/**
 * Write out a KeyValue in the manner in which we used to when KeyValue was a
 * Writable.//from w ww .  jav  a 2 s . c  o m
 *
 * @param kv
 * @param out
 * @return Length written on stream
 * @throws IOException
 * @see #create(DataInput) for the inverse function
 */
public static long write(final KeyValue kv, final DataOutput out) throws IOException {
    // This is how the old Writables write used to serialize KVs. Need to figure
    // way to make it
    // work for all implementations.
    int length = kv.getLength();
    out.writeInt(length);
    out.write(kv.getBuffer(), kv.getOffset(), length);
    return (long) length + Bytes.SIZEOF_INT;
}

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  ww  w .  ja v  a2 s. c o  m
    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 KiWiDateLiteral to a DataOutput destination.
 *
 * @param out the destination/*from w w w .ja  v  a 2  s.  c  o 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:edu.iu.lda.TopicCountList.java

@Override
public void write(DataOutput out) throws IOException {
    out.writeInt(topicCount.size());
    for (int i = 0; i < topicCount.size(); i++) {
        out.writeLong(topicCount.getLong(i));
    }//  w  w  w.  ja  v  a  2  s.c  o m
}

From source file:org.apache.sqoop.mapreduce.netezza.NetezzaExternalTableInputSplit.java

@Override
public void write(DataOutput output) throws IOException {
    output.writeInt(dataSliceId);
}

From source file:edu.iu.lda.TopicCount.java

@Override
public void write(DataOutput out) throws IOException {
    out.writeInt(topicCount.size());
    ObjectIterator<Int2IntMap.Entry> iterator = topicCount.int2IntEntrySet().fastIterator();
    while (iterator.hasNext()) {
        Int2IntMap.Entry entry = iterator.next();
        out.writeInt(entry.getIntKey());
        out.writeInt(entry.getIntValue());
    }//from  www  .  j a  v a2 s  .c o m
}