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.cassandra.io.LazilyCompactedRow.java

public void write(DataOutput out) throws IOException {
    if (rows.size() == 1 && !shouldPurge && !controller.needDeserialize()) {
        SSTableIdentityIterator row = rows.get(0);
        assert row.dataSize > 0;
        out.writeLong(row.dataSize);//from w w  w  . j a v a  2  s  . c  o  m
        row.echoData(out);
        return;
    }

    DataOutputBuffer clockOut = new DataOutputBuffer();
    ColumnFamily.serializer().serializeCFInfo(emptyColumnFamily, clockOut);

    long dataSize = headerBuffer.getLength() + clockOut.getLength() + columnSerializedSize;
    assert dataSize > 0;
    out.writeLong(dataSize);
    out.write(headerBuffer.getData(), 0, headerBuffer.getLength());
    out.write(clockOut.getData(), 0, clockOut.getLength());
    out.writeInt(columnCount);

    Iterator<IColumn> iter = iterator();
    while (iter.hasNext()) {
        IColumn column = iter.next();
        emptyColumnFamily.getColumnSerializer().serialize(column, out);
    }
}

From source file:org.apache.geode.pdx.internal.PdxInstanceImpl.java

public void sendTo(DataOutput out) throws IOException {
    PdxReaderImpl ur = getUnmodifiableReader();
    if (ur.getPdxType().getHasDeletedField()) {
        PdxWriterImpl writer = convertToTypeWithNoDeletedFields(ur);
        writer.sendTo(out);/*from w w w. j av  a2 s .  co m*/
    } else {
        out.write(DSCODE.PDX);
        out.writeInt(ur.basicSize());
        out.writeInt(ur.getPdxType().getTypeId());
        ur.basicSendTo(out);
    }
}

From source file:com.mapr.hbase.support.objects.MHRegionInfo090x.java

@Override
public void write(DataOutput out) throws IOException {
    super.write(out);
    Bytes.writeByteArray(out, endKey);//from   w  w  w.jav a2  s  . c  o  m
    out.writeBoolean(offLine);
    out.writeLong(regionId);
    Bytes.writeByteArray(out, regionName);
    out.writeBoolean(split);
    Bytes.writeByteArray(out, startKey);
    tableDesc.write(out);
    out.writeInt(hashCode);
}

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

/**
 *  This method writes the string specified by the <code>str</code> argument
 *  to the output stream specified by the <code>os</code> argument.
 *
 * @param os output stream//  w  w  w  .j  av  a  2  s. co m
 * @param str string to be written
 * @exception IOException IOException
 */
protected void writeUTF(DataOutput os, String str) throws IOException {
    if (str == null) {
        os.writeInt(-1);
    } else {
        byte[] bytes = str.getBytes("UTF-8");

        os.writeInt(bytes.length);
        os.write(bytes);
    }
}

From source file:edu.umn.cs.spatialHadoop.visualization.FrequencyMap.java

@Override
public void write(DataOutput out) throws IOException {
    super.write(out);
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    GZIPOutputStream gzos = new GZIPOutputStream(baos);
    ByteBuffer bbuffer = ByteBuffer.allocate(getHeight() * 4 + 8);
    bbuffer.putInt(getWidth());//from w  ww  . java2s .  co  m
    bbuffer.putInt(getHeight());
    gzos.write(bbuffer.array(), 0, bbuffer.position());
    for (int x = 0; x < getWidth(); x++) {
        bbuffer.clear();
        for (int y = 0; y < getHeight(); y++) {
            bbuffer.putFloat(frequencies[x][y]);
        }
        gzos.write(bbuffer.array(), 0, bbuffer.position());
    }
    gzos.close();

    byte[] serializedData = baos.toByteArray();
    out.writeInt(serializedData.length);
    out.write(serializedData);
}

From source file:org.apache.hadoop.hbase.io.HbaseObjectWritable.java

/**
 * Write a {@link Writable}, {@link String}, primitive type, or an array of
 * the preceding./*from   w  w w .jav a 2 s  . com*/
 * @param out
 * @param instance
 * @param declaredClass
 * @param conf
 * @throws IOException
 */
@SuppressWarnings("unchecked")
public static void writeObject(DataOutput out, Object instance, Class declaredClass, Configuration conf)
        throws IOException {

    Object instanceObj = instance;
    Class declClass = declaredClass;

    if (instanceObj == null) { // null
        instanceObj = new NullInstance(declClass, conf);
        declClass = Writable.class;
    }
    writeClassCode(out, declClass);
    if (declClass.isArray()) { // array
        // If bytearray, just dump it out -- avoid the recursion and
        // byte-at-a-time we were previously doing.
        if (declClass.equals(byte[].class)) {
            Bytes.writeByteArray(out, (byte[]) instanceObj);
        } else if (declClass.equals(Result[].class)) {
            Result.writeArray(out, (Result[]) instanceObj);
        } else {
            //if it is a Generic array, write the element's type
            if (getClassCode(declaredClass) == GENERIC_ARRAY_CODE) {
                Class<?> componentType = declaredClass.getComponentType();
                writeClass(out, componentType);
            }

            int length = Array.getLength(instanceObj);
            out.writeInt(length);
            for (int i = 0; i < length; i++) {
                Object item = Array.get(instanceObj, i);
                writeObject(out, item, item.getClass(), conf);
            }
        }
    } else if (List.class.isAssignableFrom(declClass)) {
        List list = (List) instanceObj;
        int length = list.size();
        out.writeInt(length);
        for (int i = 0; i < length; i++) {
            Object elem = list.get(i);
            writeObject(out, elem, elem == null ? Writable.class : elem.getClass(), conf);
        }
    } else if (declClass == String.class) { // String
        Text.writeString(out, (String) instanceObj);
    } else if (declClass.isPrimitive()) { // primitive type
        if (declClass == Boolean.TYPE) { // boolean
            out.writeBoolean(((Boolean) instanceObj).booleanValue());
        } else if (declClass == Character.TYPE) { // char
            out.writeChar(((Character) instanceObj).charValue());
        } else if (declClass == Byte.TYPE) { // byte
            out.writeByte(((Byte) instanceObj).byteValue());
        } else if (declClass == Short.TYPE) { // short
            out.writeShort(((Short) instanceObj).shortValue());
        } else if (declClass == Integer.TYPE) { // int
            out.writeInt(((Integer) instanceObj).intValue());
        } else if (declClass == Long.TYPE) { // long
            out.writeLong(((Long) instanceObj).longValue());
        } else if (declClass == Float.TYPE) { // float
            out.writeFloat(((Float) instanceObj).floatValue());
        } else if (declClass == Double.TYPE) { // double
            out.writeDouble(((Double) instanceObj).doubleValue());
        } else if (declClass == Void.TYPE) { // void
        } else {
            throw new IllegalArgumentException("Not a primitive: " + declClass);
        }
    } else if (declClass.isEnum()) { // enum
        Text.writeString(out, ((Enum) instanceObj).name());
    } else if (Message.class.isAssignableFrom(declaredClass)) {
        Text.writeString(out, instanceObj.getClass().getName());
        ((Message) instance).writeDelimitedTo(DataOutputOutputStream.constructOutputStream(out));
    } else if (Writable.class.isAssignableFrom(declClass)) { // Writable
        Class<?> c = instanceObj.getClass();
        Integer code = CLASS_TO_CODE.get(c);
        if (code == null) {
            out.writeByte(NOT_ENCODED);
            Text.writeString(out, c.getName());
        } else {
            writeClassCode(out, c);
        }
        ((Writable) instanceObj).write(out);
    } else if (Serializable.class.isAssignableFrom(declClass)) {
        Class<?> c = instanceObj.getClass();
        Integer code = CLASS_TO_CODE.get(c);
        if (code == null) {
            out.writeByte(NOT_ENCODED);
            Text.writeString(out, c.getName());
        } else {
            writeClassCode(out, c);
        }
        ByteArrayOutputStream bos = null;
        ObjectOutputStream oos = null;
        try {
            bos = new ByteArrayOutputStream();
            oos = new ObjectOutputStream(bos);
            oos.writeObject(instanceObj);
            byte[] value = bos.toByteArray();
            out.writeInt(value.length);
            out.write(value);
        } finally {
            if (bos != null)
                bos.close();
            if (oos != null)
                oos.close();
        }
    } else {
        throw new IOException("Can't write: " + instanceObj + " as " + declClass);
    }
}

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

@Override
public void write(DataOutput output) throws IOException {
    super.write(output);
    output.writeInt(finalLayerIdx);
    output.writeFloat(dropRate);//from www.j  a v a2  s. c  o m

    // 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:com.fiorano.openesb.application.aps.OutPortInst.java

/**
 *  This method is called to write this object of <code>OutPortInst</code>
 *  to the specified output stream object.
 *
 * @param out DataOutput object/*ww  w .j  av  a 2 s  .c  om*/
 * @param versionNo Description of the Parameter
 * @exception IOException if an error occurs while converting data and
 *      writing it to a binary stream.
 * @since Tifosi2.0
 */
public void toStream(DataOutput out, int versionNo) throws IOException {
    super.toStream(out, versionNo);

    writeUTF(out, m_strPortName);
    writeUTF(out, m_strDscription);
    writeUTF(out, m_strXSD);
    writeUTF(out, m_strContextXSL);
    writeUTF(out, m_strContextInfo);

    writeUTF(out, m_transformerType);
    writeUTF(out, m_strJavaClass);
    out.writeBoolean(m_bIsSyncRequestType);
    out.writeBoolean(m_bisDisabled);

    if (m_params != null && m_params.size() > 0) {
        int num = m_params.size();

        out.writeInt(num);
        for (int i = 0; i < num; ++i) {
            Param param = (Param) m_params.elementAt(i);

            param.toStream(out, versionNo);
        }
    } else {
        out.writeInt(0);
    }
}

From source file:org.mhisoft.wallet.service.AttachmentService.java

/**
 * Write the file content to the dataout, which is the attachment store.
 * @param content//from   w  w w .j  ava  2 s .co  m
 * @param encryptor
 * @param dataOut
 * @param pos
 * @return
 * @throws IOException
 */
//return pos
private long writeEncryptedContent(byte[] content, final PBEEncryptor encryptor, DataOutput dataOut, long pos)
        throws IOException {

    logger.fine("writeEncryptedContent");
    PBEEncryptor.EncryptionResult ret = encryptor.encrypt(content);
    byte[] _byteEncrypted = ret.getEncryptedData();

    /*  cipherParameters size 4 bytes*/
    byte[] cipherParameters = ret.getCipherParameters();
    dataOut.writeInt(cipherParameters.length); //length is 100 bytes
    //logger.fine("\t cipherParameters length: " + cipherParameters.length);
    pos += 4;

    /* cipherParameters body*/
    dataOut.write(cipherParameters);
    pos += cipherParameters.length;

    /*  size of the  content*/
    logger.fine("\t size of the content: " + _byteEncrypted.length);
    dataOut.writeInt(_byteEncrypted.length);
    pos += 4;

    /*   content */
    dataOut.write(_byteEncrypted);
    pos += _byteEncrypted.length;

    return pos;

}

From source file:edu.umn.cs.spatialHadoop.nasa.HDFRasterLayer.java

@Override
public void write(DataOutput out) throws IOException {
    super.write(out);
    out.writeLong(timestamp);//w ww.j  a  va  2s  .co m
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    GZIPOutputStream gzos = new GZIPOutputStream(baos);
    ByteBuffer bbuffer = ByteBuffer.allocate(getHeight() * 2 * 8 + 8);
    bbuffer.putInt(getWidth());
    bbuffer.putInt(getHeight());
    gzos.write(bbuffer.array(), 0, bbuffer.position());
    for (int x = 0; x < getWidth(); x++) {
        bbuffer.clear();
        for (int y = 0; y < getHeight(); y++) {
            bbuffer.putLong(sum[x][y]);
            bbuffer.putLong(count[x][y]);
        }
        gzos.write(bbuffer.array(), 0, bbuffer.position());
    }
    gzos.close();

    byte[] serializedData = baos.toByteArray();
    out.writeInt(serializedData.length);
    out.write(serializedData);
}