Example usage for java.io DataOutput writeBoolean

List of usage examples for java.io DataOutput writeBoolean

Introduction

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

Prototype

void writeBoolean(boolean v) throws IOException;

Source Link

Document

Writes a boolean value to this output stream.

Usage

From source file:org.apache.hadoop.mapred.Task.java

public void write(DataOutput out) throws IOException {
    Text.writeString(out, jobFile);
    taskId.write(out);//  ww w. ja va2 s  .c  om
    out.writeInt(partition);
    out.writeInt(numSlotsRequired);
    taskStatus.write(out);
    skipRanges.write(out);
    out.writeBoolean(skipping);
    out.writeBoolean(jobCleanup);
    if (jobCleanup) {
        WritableUtils.writeEnum(out, jobRunStateForCleanup);
    }
    out.writeBoolean(jobSetup);
    out.writeBoolean(writeSkipRecs);
    out.writeBoolean(taskCleanup);
    Text.writeString(out, user);
}

From source file:org.apache.hadoop.mapred.TaskStatus.java

public void write(DataOutput out) throws IOException {
    taskid.write(out);/*from  w ww  .java 2 s  .co  m*/
    out.writeFloat(progress);
    out.writeInt(numSlots);
    WritableUtils.writeEnum(out, runState);
    Text.writeString(out, diagnosticInfo);
    Text.writeString(out, stateString);
    WritableUtils.writeEnum(out, phase);
    out.writeLong(startTime);
    out.writeLong(finishTime);
    out.writeBoolean(includeCounters);
    out.writeLong(outputSize);
    if (includeCounters) {
        counters.write(out);
    }
    nextRecordRange.write(out);
}

From source file:org.apache.hadoop.mapred.TaskStatus.java

static void writeTaskStatus(DataOutput out, TaskStatus taskStatus) throws IOException {
    out.writeBoolean(taskStatus.getIsMap());
    taskStatus.write(out);//from   ww w.j  a v  a 2  s  .  co m
}

From source file:org.apache.hadoop.tools.DistTool.java

protected static void writeString(DataOutput out, String s) throws IOException {
    boolean b = s != null;
    out.writeBoolean(b);
    if (b) {/* w  w w.  j  a v a 2  s.  com*/
        Text.writeString(out, s);
    }
}

From source file:org.apache.hama.bsp.BSPTask.java

@Override
public final void write(DataOutput out) throws IOException {
    super.write(out);
    if (split != null) {
        out.writeBoolean(true);
        Text.writeString(out, splitClass);
        split.write(out);/*from   ww w  .  j av  a2  s. com*/
        split = null;
    } else {
        out.writeBoolean(false);
    }
}

From source file:org.apache.hama.graph.GraphJobMessage.java

@Override
public void write(DataOutput out) throws IOException {
    out.writeByte(this.flag);
    if (isVertexMessage()) {
        // we don't need to write the classes because the other side has the
        // same//from   w  w  w .  ja va 2s . c  om
        // classes for the two entities.
        vertexId.write(out);
        vertexValue.write(out);
    } else if (isMapMessage()) {
        map.write(out);
    } else if (isPartitioningMessage()) {
        //LOG.info("????????????????");
        //LOG.info("vertex.getVertexID() : "+ vertex.getVertexID().toString());
        vertex.getVertexID().write(out);
        //LOG.info("vertex.getValue() : " + vertex.getValue());
        if (vertex.getValue() != null) {
            //LOG.info("vertexvalue");
            out.writeBoolean(true);
            vertex.getValue().write(out);
        } else {
            out.writeBoolean(false);
        }
        List<?> outEdges = vertex.getEdges();
        out.writeInt(outEdges.size());
        //LOG.info("?: " + outEdges.size());
        for (Object e : outEdges) {
            Edge<?, ?> edge = (Edge<?, ?>) e;
            //LOG.info(" : " + edge);
            edge.getDestinationVertexID().write(out);
            if (edge.getValue() != null) {
                out.writeBoolean(true);
                edge.getValue().write(out);
            } else {
                //LOG.info(",?dge.getValue()==null");
                out.writeBoolean(false);
            }
        }
    } else if (isVerticesSizeMessage()) {
        vertices_size.write(out);
    } else if (isBoundaryVertexSizeMessage()) {
        boundaryVertex_size.write(out);
    } else {
        vertexId.write(out);
    }

}

From source file:org.apache.hama.graph.Vertex.java

@Override
public void write(DataOutput out) throws IOException {
    if (vertexID == null) {
        out.writeBoolean(false);
    } else {/*from  ww  w .  ja va 2s.  com*/
        out.writeBoolean(true);
        vertexID.write(out);
    }

    if (value == null) {
        out.writeBoolean(false);
    } else {
        out.writeBoolean(true);
        value.write(out);
    }
    if (this.edges == null) {
        out.writeBoolean(false);
    } else {
        out.writeBoolean(true);
        out.writeInt(this.edges.size());
        for (Edge<V, E> edge : this.edges) {
            edge.getDestinationVertexID().write(out);
            if (edge.getValue() == null) {
                out.writeBoolean(false);
            } else {
                out.writeBoolean(true);
                edge.getValue().write(out);
            }
        }
    }
    out.writeBoolean(votedToHalt);
    writeState(out);

}

From source file:org.apache.hawq.pxf.service.io.GPDBWritable.java

@Override
public void write(DataOutput out) throws IOException {
    int numCol = colType.length;
    boolean[] nullBits = new boolean[numCol];
    int[] colLength = new int[numCol];
    byte[] enumType = new byte[numCol];
    int[] padLength = new int[numCol];
    byte[] padbytes = new byte[8];

    /**/*from   www . j  a  va2s  .co m*/
     * Compute the total payload and header length
     * header = total length (4 byte), Version (2 byte), Error (1 byte), #col (2 byte)
     * col type array = #col * 1 byte
     * null bit array = ceil(#col/8)
     */
    int datlen = 4 + 2 + 1 + 2;
    datlen += numCol;
    datlen += getNullByteArraySize(numCol);

    for (int i = 0; i < numCol; i++) {
        /* Get the enum type */
        DBType coldbtype;
        switch (DataType.get(colType[i])) {
        case BIGINT:
            coldbtype = DBType.BIGINT;
            break;
        case BOOLEAN:
            coldbtype = DBType.BOOLEAN;
            break;
        case FLOAT8:
            coldbtype = DBType.FLOAT8;
            break;
        case INTEGER:
            coldbtype = DBType.INTEGER;
            break;
        case REAL:
            coldbtype = DBType.REAL;
            break;
        case SMALLINT:
            coldbtype = DBType.SMALLINT;
            break;
        case BYTEA:
            coldbtype = DBType.BYTEA;
            break;
        default:
            coldbtype = DBType.TEXT;
        }
        enumType[i] = (byte) (coldbtype.ordinal());

        /* Get the actual value, and set the null bit */
        if (colValue[i] == null) {
            nullBits[i] = true;
            colLength[i] = 0;
        } else {
            nullBits[i] = false;

            /*
                 * For fixed length type, we get the fixed length.
             * For var len binary format, the length is in the col value.
             * For text format, we must convert encoding first.
             */
            if (!coldbtype.isVarLength()) {
                colLength[i] = coldbtype.getTypeLength();
            } else if (!isTextForm(colType[i])) {
                colLength[i] = ((byte[]) colValue[i]).length;
            } else {
                colLength[i] = ((String) colValue[i]).getBytes(CHARSET).length;
            }

            /* calculate and add the type alignment padding */
            padLength[i] = roundUpAlignment(datlen, coldbtype.getAlignment()) - datlen;
            datlen += padLength[i];

            /* for variable length type, we add a 4 byte length header */
            if (coldbtype.isVarLength()) {
                datlen += 4;
            }
        }
        datlen += colLength[i];
    }

    /*
     * Add the final alignment padding for the next record
     */
    int endpadding = roundUpAlignment(datlen, 8) - datlen;
    datlen += endpadding;

    /* Construct the packet header */
    out.writeInt(datlen);
    out.writeShort(VERSION);
    out.writeByte(errorFlag);
    out.writeShort(numCol);

    /* Write col type */
    for (int i = 0; i < numCol; i++) {
        out.writeByte(enumType[i]);
    }

    /* Nullness */
    byte[] nullBytes = boolArrayToByteArray(nullBits);
    out.write(nullBytes);

    /* Column Value */
    for (int i = 0; i < numCol; i++) {
        if (!nullBits[i]) {
            /* Pad the alignment byte first */
            if (padLength[i] > 0) {
                out.write(padbytes, 0, padLength[i]);
            }

            /* Now, write the actual column value */
            switch (DataType.get(colType[i])) {
            case BIGINT:
                out.writeLong(((Long) colValue[i]));
                break;
            case BOOLEAN:
                out.writeBoolean(((Boolean) colValue[i]));
                break;
            case FLOAT8:
                out.writeDouble(((Double) colValue[i]));
                break;
            case INTEGER:
                out.writeInt(((Integer) colValue[i]));
                break;
            case REAL:
                out.writeFloat(((Float) colValue[i]));
                break;
            case SMALLINT:
                out.writeShort(((Short) colValue[i]));
                break;

            /* For BYTEA format, add 4byte length header at the beginning  */
            case BYTEA:
                out.writeInt(colLength[i]);
                out.write((byte[]) colValue[i]);
                break;

            /* For text format, add 4byte length header. string is already '\0' terminated */
            default: {
                out.writeInt(colLength[i]);
                byte[] data = ((String) colValue[i]).getBytes(CHARSET);
                out.write(data);
                break;
            }
            }
        }
    }

    /* End padding */
    out.write(padbytes, 0, endpadding);
}

From source file:org.apache.horn.core.RecurrentLayeredNeuralNetwork.java

@Override
public void write(DataOutput output) throws IOException {
    super.write(output);
    output.writeInt(finalLayerIdx);//from  w  ww .  j av  a 2  s . co  m
    output.writeFloat(dropRate);

    // write neuron classes
    output.writeInt(this.neuronClassList.size());
    for (Class<? extends Neuron> clazz : this.neuronClassList) {
        output.writeUTF(clazz.getName());
    }

    // write squashing functions
    output.writeInt(this.squashingFunctionList.size());
    for (FloatFunction aSquashingFunctionList : this.squashingFunctionList) {
        WritableUtils.writeString(output, aSquashingFunctionList.getFunctionName());
    }

    // write recurrent step size
    output.writeInt(this.recurrentStepSize);

    // write recurrent step size
    output.writeInt(this.numOutCells);

    // write recurrent layer list
    output.writeInt(this.recurrentLayerList.size());
    for (Boolean isReccurentLayer : recurrentLayerList) {
        output.writeBoolean(isReccurentLayer);
    }

    // write weight matrices
    output.writeInt(this.getSizeOfWeightmatrix());
    for (List<FloatMatrix> aWeightMatrixLists : this.weightMatrixLists) {
        for (FloatMatrix aWeightMatrixList : aWeightMatrixLists) {
            FloatMatrixWritable.write(aWeightMatrixList, output);
        }
    }

    // DO NOT WRITE WEIGHT UPDATE
}

From source file:org.apache.jxtadoop.ipc.ConnectionHeader.java

public void write(DataOutput out) throws IOException {
    Text.writeString(out, (protocol == null) ? "" : protocol);
    if (ugi != null) {
        out.writeBoolean(true);
        ugi.write(out);//  w w  w. ja  v  a 2  s.  c  o  m
    } else {
        out.writeBoolean(false);
    }
}