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.marmotta.kiwi.io.KiWiIO.java

/**
 * Efficiently serialize a KiWiBooleanLiteral to a DataOutput destination.
 *
 * @param out the destination//from   w ww  . j  a  va 2s . c om
 * @param literal the KiWiBooleanLiteral to serialize
 * @throws IOException
 */
public static void writeBooleanLiteral(DataOutput out, KiWiBooleanLiteral literal) throws IOException {
    if (literal == null) {
        out.writeLong(-1L);
    } else {
        out.writeLong(literal.getId());
        out.writeBoolean(literal.booleanValue());
        writeURI(out, literal.getType());
        out.writeLong(literal.getCreated().getTime());
    }
}

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

/**
 * Efficiently serialize a KiWiTriple to a DataOutput destination.
 *
 * @param output the destination//from   w  ww  .ja  v a2  s  .c o m
 * @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.nutch.crawl.CrawlDatum.java

public void write(DataOutput out) throws IOException {
    out.writeByte(CUR_VERSION); // store current version
    out.writeByte(status);/*w  w  w.ja  va  2s.  c  o m*/
    out.writeLong(fetchTime);
    out.writeByte(retries);
    out.writeInt(fetchInterval);
    out.writeFloat(score);
    out.writeLong(modifiedTime);
    if (signature == null) {
        out.writeByte(0);
    } else {
        out.writeByte(signature.length);
        out.write(signature);
    }
    if (metaData != null && metaData.size() > 0) {
        out.writeBoolean(true);
        metaData.write(out);
    } else {
        out.writeBoolean(false);
    }
}

From source file:org.apache.oozie.coord.input.dependency.AbstractCoordInputDependency.java

@Override
public void write(DataOutput out) throws IOException {
    WritableUtils.writeStringAsBytes(out, INTERNAL_VERSION_ID);
    out.writeBoolean(isDependencyMet);
    WritableUtils.writeMapWithList(out, dependencyMap);
}

From source file:org.apache.oozie.coord.input.dependency.CoordUnResolvedInputDependency.java

@Override
public void write(DataOutput out) throws IOException {
    out.writeBoolean(isResolved);
    WritableUtils.writeStringList(out, dependency);
    WritableUtils.writeStringList(out, resolvedList);
}

From source file:org.apache.pig.data.DataReaderWriter.java

@SuppressWarnings("unchecked")
public static void writeDatum(DataOutput out, Object val) throws IOException {
    // Read the data type
    byte type = DataType.findType(val);
    switch (type) {
    case DataType.TUPLE:
        // Because tuples are written directly by hadoop, the
        // tuple's write method needs to write the indicator byte.
        // So don't write the indicator byte here as it is for
        // everyone else.
        ((Tuple) val).write(out);
        break;//from   w  ww .  j  ava 2s  . c om

    case DataType.BAG:
        out.writeByte(DataType.BAG);
        ((DataBag) val).write(out);
        break;

    case DataType.MAP: {
        out.writeByte(DataType.MAP);
        Map<String, Object> m = (Map<String, Object>) val;
        out.writeInt(m.size());
        Iterator<Map.Entry<String, Object>> i = m.entrySet().iterator();
        while (i.hasNext()) {
            Map.Entry<String, Object> entry = i.next();
            writeDatum(out, entry.getKey());
            writeDatum(out, entry.getValue());
        }
        break;
    }

    case DataType.INTERNALMAP: {
        out.writeByte(DataType.INTERNALMAP);
        Map<Object, Object> m = (Map<Object, Object>) val;
        out.writeInt(m.size());
        Iterator<Map.Entry<Object, Object>> i = m.entrySet().iterator();
        while (i.hasNext()) {
            Map.Entry<Object, Object> entry = i.next();
            writeDatum(out, entry.getKey());
            writeDatum(out, entry.getValue());
        }
        break;
    }

    case DataType.INTEGER:
        out.writeByte(DataType.INTEGER);
        out.writeInt((Integer) val);
        break;

    case DataType.LONG:
        out.writeByte(DataType.LONG);
        out.writeLong((Long) val);
        break;

    case DataType.FLOAT:
        out.writeByte(DataType.FLOAT);
        out.writeFloat((Float) val);
        break;

    case DataType.DOUBLE:
        out.writeByte(DataType.DOUBLE);
        out.writeDouble((Double) val);
        break;

    case DataType.BOOLEAN:
        out.writeByte(DataType.BOOLEAN);
        out.writeBoolean((Boolean) val);
        break;

    case DataType.BYTE:
        out.writeByte(DataType.BYTE);
        out.writeByte((Byte) val);
        break;

    case DataType.BYTEARRAY: {
        out.writeByte(DataType.BYTEARRAY);
        DataByteArray bytes = (DataByteArray) val;
        out.writeInt(bytes.size());
        out.write(bytes.mData);
        break;
    }

    case DataType.CHARARRAY: {
        String s = (String) val;
        byte[] utfBytes = s.getBytes(DataReaderWriter.UTF8);
        int length = utfBytes.length;

        if (length < DataReaderWriter.UNSIGNED_SHORT_MAX) {
            out.writeByte(DataType.CHARARRAY);
            out.writeShort(length);
            out.write(utfBytes);
        } else {
            out.writeByte(DataType.BIGCHARARRAY);
            out.writeInt(length);
            out.write(utfBytes);
        }
        break;
    }
    case DataType.GENERIC_WRITABLECOMPARABLE:
        out.writeByte(DataType.GENERIC_WRITABLECOMPARABLE);
        //store the class name, so we know the class to create on read
        writeDatum(out, val.getClass().getName());
        Writable writable = (Writable) val;
        writable.write(out);
        break;

    case DataType.NULL:
        out.writeByte(DataType.NULL);
        break;

    default:
        throw new RuntimeException("Unexpected data type " + type + " found in stream.");
    }
}

From source file:org.apache.rya.accumulo.mr.RyaStatementWritable.java

/**
 * Serializes this RyaStatementWritable.
 * @param   dataOutput  An output stream for serialized statement data.
 * @throws  IOException if the RyaStatement is null or otherwise can't be
 *          serialized.//  w ww  .j a va  2 s.c  om
 */
@Override
public void write(DataOutput dataOutput) throws IOException {
    if (ryaStatement == null) {
        throw new IOException("Rya Statement is null");
    }
    try {
        Map<RdfCloudTripleStoreConstants.TABLE_LAYOUT, TripleRow> map = ryaContext
                .serializeTriple(ryaStatement);
        TripleRow tripleRow = map.get(RdfCloudTripleStoreConstants.TABLE_LAYOUT.SPO);
        byte[] row = tripleRow.getRow();
        byte[] columnFamily = tripleRow.getColumnFamily();
        byte[] columnQualifier = tripleRow.getColumnQualifier();
        write(dataOutput, row);
        write(dataOutput, columnFamily);
        write(dataOutput, columnQualifier);
        write(dataOutput, ryaStatement.getColumnVisibility());
        write(dataOutput, ryaStatement.getValue());
        Long timestamp = ryaStatement.getTimestamp();
        boolean b = timestamp != null;
        dataOutput.writeBoolean(b);
        if (b) {
            dataOutput.writeLong(timestamp);
        }
    } catch (TripleRowResolverException e) {
        throw new IOException(e);
    }
}

From source file:org.apache.rya.accumulo.mr.RyaStatementWritable.java

/**
 * Write part of a statement to an output stream.
 * @param dataOutput Stream for writing serialized statements.
 * @param row   Individual field to write, as a byte array.
 * @throws IOException if writing to the stream fails.
 *//*w  ww  .jav a 2  s.  c  om*/
protected void write(DataOutput dataOutput, byte[] row) throws IOException {
    boolean b = row != null;
    dataOutput.writeBoolean(b);
    if (b) {
        dataOutput.writeInt(row.length);
        dataOutput.write(row);
    }
}

From source file:org.apache.sysml.runtime.compress.CompressedMatrixBlock.java

@Override
public void write(DataOutput out) throws IOException {
    out.writeBoolean(isCompressed());

    //serialize uncompressed block
    if (!isCompressed()) {
        super.write(out);
        return;// w  w  w.  j a va 2 s . com
    }

    //serialize compressed matrix block
    out.writeInt(rlen);
    out.writeInt(clen);
    out.writeLong(nonZeros);
    out.writeInt(_colGroups.size());

    for (ColGroup grp : _colGroups) {
        out.writeByte(grp.getCompType().ordinal());
        grp.write(out); //delegate serialization
    }
}

From source file:org.apache.sysml.runtime.matrix.data.FrameBlock.java

@Override
public void write(DataOutput out) throws IOException {
    boolean isDefaultMeta = isColNamesDefault() && isColumnMetadataDefault();
    //write header (rows, cols, default)
    out.writeInt(getNumRows());//from w  w w.  ja v  a 2 s  .co m
    out.writeInt(getNumColumns());
    out.writeBoolean(isDefaultMeta);
    //write columns (value type, data)
    for (int j = 0; j < getNumColumns(); j++) {
        out.writeByte(_schema[j].ordinal());
        if (!isDefaultMeta) {
            out.writeUTF(getColumnName(j));
            out.writeLong(_colmeta[j].getNumDistinct());
            out.writeUTF((_colmeta[j].getMvValue() != null) ? _colmeta[j].getMvValue() : "");
        }
        _coldata[j].write(out);
    }
}