List of usage examples for java.io DataOutputStream writeInt
public final void writeInt(int v) throws IOException
int
to the underlying output stream as four bytes, high byte first. From source file:additionalpipes.inventory.components.PropertyIntArray.java
@Override public void writeData(DataOutputStream data) throws IOException { data.writeInt(value.length); for (int v : value) { data.writeInt(v);/* w ww . java2s.c o m*/ } }
From source file:org.openmrs.module.odkconnector.serialization.serializer.custom.SerializedFormSerializer.java
/** * Write the data to the output stream./* w w w . j av a 2 s . c o m*/ * * @param stream the output stream * @param data the data that need to be written to the output stream * @throws java.io.IOException thrown when the writing process encounter is failing */ @Override public void write(final OutputStream stream, final Object data) throws IOException { try { SerializedForm serializedForm = (SerializedForm) data; DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSZ"); DataOutputStream outputStream = new DataOutputStream(stream); outputStream.writeInt(serializedForm.getPatientId()); outputStream.writeUTF(ExtendedDefinition.DEFINITION_PROPERTY_FORM); outputStream.writeByte(TYPE_INT); outputStream.writeInt(serializedForm.getFormId()); outputStream.writeUTF(dateFormat.format(new Date())); } catch (IOException e) { log.info("Writing form information failed!", e); } }
From source file:com.microsoft.azure.management.TestContainerService.java
private String getSshKey() throws Exception { KeyPairGenerator keyPairGenerator = KeyPairGenerator.getInstance("RSA"); keyPairGenerator.initialize(2048);// w w w. j a v a 2s.c om KeyPair keyPair = keyPairGenerator.generateKeyPair(); RSAPublicKey publicKey = (RSAPublicKey) keyPair.getPublic(); ByteArrayOutputStream byteOs = new ByteArrayOutputStream(); DataOutputStream dos = new DataOutputStream(byteOs); dos.writeInt("ssh-rsa".getBytes().length); dos.write("ssh-rsa".getBytes()); dos.writeInt(publicKey.getPublicExponent().toByteArray().length); dos.write(publicKey.getPublicExponent().toByteArray()); dos.writeInt(publicKey.getModulus().toByteArray().length); dos.write(publicKey.getModulus().toByteArray()); String publicKeyEncoded = new String(Base64.encodeBase64(byteOs.toByteArray())); return "ssh-rsa " + publicKeyEncoded + " "; }
From source file:org.structr.core.graph.SyncCommand.java
/** * Serializes the given object into the given writer. The following format will * be used to serialize objects. The first two characters are the type index, see * typeMap above. After that, a single digit that indicates the length of the following * length field follows. After that, the length field is serialized, followed by the * string value of the given object and a space character for human readability. * * @param outputStream/*from www .j a va2 s .c o m*/ * @param obj */ public static void serializeData(DataOutputStream outputStream, byte[] data) throws IOException { outputStream.writeInt(data.length); outputStream.write(data); outputStream.flush(); }
From source file:com.bigdata.dastor.db.ReadResponse.java
public void serialize(ReadResponse rm, DataOutputStream dos) throws IOException { dos.writeInt(rm.digest().length); dos.write(rm.digest());//from www .ja v a 2s . co m dos.writeBoolean(rm.isDigestQuery()); if (!rm.isDigestQuery() && rm.row() != null) { Row.serializer().serialize(rm.row(), dos); } }
From source file:org.mule.transport.comm.protocols.LengthProtocol.java
protected void writeByteArray(OutputStream os, byte[] data) throws IOException { // Write the length and then the data. DataOutputStream dos = new DataOutputStream(os); dos.writeInt(data.length); dos.write(data);/*from w w w. jav a 2 s . c om*/ dos.flush(); }
From source file:org.mule.transport.tcp.protocols.LengthProtocol.java
@Override protected void writeByteArray(OutputStream os, byte[] data) throws IOException { // Write the length and then the data. DataOutputStream dos = new DataOutputStream(os); dos.writeInt(data.length); dos.write(data);/*from w ww.j av a 2 s .com*/ // DataOutputStream size is SIZE_INT + the byte length, due to the writeInt call // this should fix EE-1494 if (dos.size() != data.length + SIZE_INT) { // only flush if the sizes don't match up dos.flush(); } }
From source file:com.facebook.infrastructure.db.CommitLogEntry.java
public void serialize(CommitLogEntry logEntry, DataOutputStream dos) throws IOException { int length = logEntry.length(); dos.writeInt(length); dos.write(logEntry.value(), 0, length); }
From source file:org.apache.flink.runtime.metrics.dump.MetricDumpSerialization.java
private static void serializeMetricInfo(DataOutputStream dos, QueryScopeInfo info) throws IOException { serializeString(dos, info.scope);/*from ww w . j av a2 s . co m*/ dos.writeByte(info.getCategory()); switch (info.getCategory()) { case INFO_CATEGORY_JM: break; case INFO_CATEGORY_TM: String tmID = ((QueryScopeInfo.TaskManagerQueryScopeInfo) info).taskManagerID; serializeString(dos, tmID); break; case INFO_CATEGORY_JOB: QueryScopeInfo.JobQueryScopeInfo jobInfo = (QueryScopeInfo.JobQueryScopeInfo) info; serializeString(dos, jobInfo.jobID); break; case INFO_CATEGORY_TASK: QueryScopeInfo.TaskQueryScopeInfo taskInfo = (QueryScopeInfo.TaskQueryScopeInfo) info; serializeString(dos, taskInfo.jobID); serializeString(dos, taskInfo.vertexID); dos.writeInt(taskInfo.subtaskIndex); break; case INFO_CATEGORY_OPERATOR: QueryScopeInfo.OperatorQueryScopeInfo operatorInfo = (QueryScopeInfo.OperatorQueryScopeInfo) info; serializeString(dos, operatorInfo.jobID); serializeString(dos, operatorInfo.vertexID); dos.writeInt(operatorInfo.subtaskIndex); serializeString(dos, operatorInfo.operatorName); break; } }
From source file:org.getspout.spout.packet.PacketBlockData.java
public void writeData(DataOutputStream output) throws IOException { output.writeInt(data == null ? 0 : data.length); output.writeBoolean(compressed);// w w w. ja va 2 s.c o m if (data != null) { output.write(data); } }