List of usage examples for java.io DataOutput writeLong
void writeLong(long v) throws IOException;
long
value, which is comprised of eight bytes, to the output stream. From source file:org.apache.pig.data.BinInterSedes.java
@Override @SuppressWarnings("unchecked") public void writeDatum(DataOutput out, Object val, byte type) throws IOException { switch (type) { case DataType.TUPLE: writeTuple(out, (Tuple) val); break;/* w w w. j a v a 2s . c o m*/ case DataType.BAG: writeBag(out, (DataBag) val); break; case DataType.MAP: { writeMap(out, (Map<String, Object>) val); break; } case DataType.INTERNALMAP: { out.writeByte(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: int i = (Integer) val; if (i == 0) { out.writeByte(INTEGER_0); } else if (i == 1) { out.writeByte(INTEGER_1); } else if (Byte.MIN_VALUE <= i && i <= Byte.MAX_VALUE) { out.writeByte(INTEGER_INBYTE); out.writeByte(i); } else if (Short.MIN_VALUE <= i && i <= Short.MAX_VALUE) { out.writeByte(INTEGER_INSHORT); out.writeShort(i); } else { out.writeByte(INTEGER); out.writeInt(i); } break; case DataType.LONG: long lng = (Long) val; if (lng == 0) { out.writeByte(LONG_0); } else if (lng == 1) { out.writeByte(LONG_1); } else if (Byte.MIN_VALUE <= lng && lng <= Byte.MAX_VALUE) { out.writeByte(LONG_INBYTE); out.writeByte((int) lng); } else if (Short.MIN_VALUE <= lng && lng <= Short.MAX_VALUE) { out.writeByte(LONG_INSHORT); out.writeShort((int) lng); } else if (Integer.MIN_VALUE <= lng && lng <= Integer.MAX_VALUE) { out.writeByte(LONG_ININT); out.writeInt((int) lng); } else { out.writeByte(LONG); out.writeLong(lng); } break; case DataType.DATETIME: out.writeByte(DATETIME); out.writeLong(((DateTime) val).getMillis()); out.writeShort(((DateTime) val).getZone().getOffset((DateTime) val) / ONE_MINUTE); break; case DataType.FLOAT: out.writeByte(FLOAT); out.writeFloat((Float) val); break; case DataType.BIGINTEGER: out.writeByte(BIGINTEGER); writeBigInteger(out, (BigInteger) val); break; case DataType.BIGDECIMAL: out.writeByte(BIGDECIMAL); writeBigDecimal(out, (BigDecimal) val); break; case DataType.DOUBLE: out.writeByte(DOUBLE); out.writeDouble((Double) val); break; case DataType.BOOLEAN: if ((Boolean) val) out.writeByte(BOOLEAN_TRUE); else out.writeByte(BOOLEAN_FALSE); break; case DataType.BYTE: out.writeByte(BYTE); out.writeByte((Byte) val); break; case DataType.BYTEARRAY: { DataByteArray bytes = (DataByteArray) val; SedesHelper.writeBytes(out, bytes.mData); break; } case DataType.CHARARRAY: { SedesHelper.writeChararray(out, (String) val); break; } case DataType.GENERIC_WRITABLECOMPARABLE: out.writeByte(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(NULL); break; default: throw new RuntimeException("Unexpected data type " + val.getClass().getName() + " found in stream. " + "Note only standard Pig type is supported when you output from UDF/LoadFunc"); } }
From source file:com.fiorano.openesb.application.aps.ServiceInstance.java
/** * This method tests whether this object of <code>ServiceInstance</code> * has the required(mandatory) fields set, before inserting values in to * the database./*from w w w. j a va2s. c om*/ * * @param out DataOutput object * @param versionNo * @exception IOException if the object is not valid * @since Tifosi2.0 */ public void toStream(DataOutput out, int versionNo) throws IOException { super.toStream(out, versionNo); out.writeBoolean(m_isManualLaunch); out.writeBoolean(m_isStateful); out.writeBoolean(m_isDelayedLaunch); UTFReaderWriter.writeUTF(out, m_delayedPortName); out.writeBoolean(m_isTransacted); out.writeBoolean(m_isErrorHandlingEnabled); out.writeBoolean(m_isVersionLocked); out.writeBoolean(m_isEndOfWorkflow); out.writeBoolean(m_isInMemoryLaunch); out.writeBoolean(m_isTransportLPC); out.writeBoolean(m_bPreferLaunchOnHigherLevelNode); out.writeBoolean(m_bIsDurableSubscription); out.writeBoolean(m_bIsDurableConnection); out.writeBoolean(m_bKillPrimaryOnSecondaryLaunch); out.writeBoolean(m_bIsDebugMode); out.writeInt(m_iDebugPort); out.writeInt(m_maxRetries); if (m_version != null) UTFReaderWriter.writeUTF(out, m_version); else UTFReaderWriter.writeUTF(out, ""); out.writeLong(m_dBufferSizePerPort); if (m_servInstName != null) UTFReaderWriter.writeUTF(out, m_servInstName); else UTFReaderWriter.writeUTF(out, ""); if (m_servGUID != null) UTFReaderWriter.writeUTF(out, m_servGUID); else UTFReaderWriter.writeUTF(out, ""); if (m_longDescription != null) UTFReaderWriter.writeUTF(out, m_longDescription); else UTFReaderWriter.writeUTF(out, ""); if (m_shortDescription != null) UTFReaderWriter.writeUTF(out, m_shortDescription); else UTFReaderWriter.writeUTF(out, ""); // Service Dependency if (m_runtimeDependencies != null && m_runtimeDependencies.size() > 0) { int num = m_runtimeDependencies.size(); out.writeInt(num); for (int i = 0; i < num; ++i) { RuntimeDependency serv = (RuntimeDependency) m_runtimeDependencies.elementAt(i); serv.toStream(out, versionNo); } } else { out.writeInt(0); } if (m_runtimeArgs != null) { out.writeInt(1); m_runtimeArgs.toStream(out, versionNo); } else out.writeInt(0); if (m_portInstDescriptor != null) { out.writeInt(1); m_portInstDescriptor.toStream(out, versionNo); } else out.writeInt(0); if (m_params != null) { int length = m_params.size(); out.writeInt(length); Enumeration params = m_params.elements(); while (params.hasMoreElements()) { Param param = (Param) params.nextElement(); param.toStream(out, versionNo); } } else out.writeInt(0); if (m_statusTracking != null) { out.writeInt(1); m_statusTracking.toStream(out, versionNo); } else out.writeInt(0); if (m_vecEndStates != null) { int size = m_vecEndStates.size(); out.writeInt(size); for (int i = 0; i < size; i++) { ((EndState) m_vecEndStates.get(i)).toStream(out, versionNo); } } else out.writeInt(0); if (m_nodes != null) { int size = m_nodes.size(); out.writeInt(size); Enumeration keys = m_nodes.keys(); Enumeration values = m_nodes.elements(); while (keys.hasMoreElements()) { UTFReaderWriter.writeUTF(out, (String) keys.nextElement()); UTFReaderWriter.writeUTF(out, (String) values.nextElement()); } } else out.writeInt(0); if (m_monitor != null) { out.writeInt(1); m_monitor.toStream(out, versionNo); } else out.writeInt(0); if (m_logModules != null) { out.writeInt(1); m_logModules.toStream(out, versionNo); } else out.writeInt(0); // Log Manager and log params writeUTF(out, m_logManager); writeUTF(out, m_profile); if (m_logParams != null) { int length = m_logParams.size(); out.writeInt(length); Enumeration logParams = m_logParams.elements(); while (logParams.hasMoreElements()) { Param logParam = (Param) logParams.nextElement(); logParam.toStream(out, versionNo); } } else out.writeInt(0); // Event Parameters. writeUTF(out, m_eventDeliveryMode); out.writeLong(m_eventExpiryTime); out.writeInt(m_eventHandler); }
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]; /**// w ww. java 2 s. com * 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.sysml.runtime.matrix.data.MatrixBlock.java
private void writeNnzInfo(DataOutput out, boolean ultrasparse) throws IOException { //note: if ultrasparse, int always sufficient because nnz<rlen // where rlen is limited to integer long lrlen = (long) rlen; long lclen = (long) clen; //write long if required, otherwise int if (lrlen * lclen > Integer.MAX_VALUE && !ultrasparse) { out.writeLong(nonZeros); } else {/*ww w . j a v a 2 s. c o m*/ out.writeInt((int) nonZeros); } }
From source file:com.ibm.bi.dml.runtime.matrix.data.MatrixBlock.java
/** * //from www. j av a 2 s .c o m * @param out * @throws IOException */ private void writeNnzInfo(DataOutput out, boolean ultrasparse) throws IOException { //note: if ultrasparse, int always sufficient because nnz<rlen // where rlen is limited to integer long lrlen = (long) rlen; long lclen = (long) clen; //write long if required, otherwise int if (lrlen * lclen > Integer.MAX_VALUE && !ultrasparse) { out.writeLong(nonZeros); } else { out.writeInt((int) nonZeros); } }