List of usage examples for java.io DataOutputStream writeByte
public final void writeByte(int v) throws IOException
byte
to the underlying output stream as a 1-byte value. From source file:tachyon.master.ImageWriter.java
/** * Write an ImageElement to the specified DataOutputStream. Use the specified ObjectWriter. * /*w ww. j a v a 2 s . co m*/ * @param objWriter The used object writer * @param dos The target data output stream * @param ele The image element to be written */ protected void writeElement(ObjectWriter objWriter, DataOutputStream dos, ImageElement ele) { try { objWriter.writeValue(dos, ele); dos.writeByte('\n'); } catch (IOException e) { throw Throwables.propagate(e); } }
From source file:net.sheehantech.cherry.ProtocolTest.java
private byte[] expected(byte command, byte[] token, byte[] payload) { ByteArrayOutputStream byteStream = new ByteArrayOutputStream(); DataOutputStream dataStream = new DataOutputStream(byteStream); try {// w ww. ja v a 2s. co m dataStream.writeByte(command); dataStream.writeShort(token.length); dataStream.write(token); dataStream.writeShort(payload.length); dataStream.write(payload); return (byteStream.toByteArray()); } catch (final IOException e) { throw new AssertionError(); } }
From source file:net.sheehantech.cherry.ProtocolTest.java
private byte[] expectedEnhanced(byte command, int identifier, int expiryTime, byte[] deviceToken, byte[] payload) { ByteArrayOutputStream byteStream = new ByteArrayOutputStream(); DataOutputStream dataStream = new DataOutputStream(byteStream); try {/*w ww .j av a2 s .c o m*/ dataStream.writeByte(command); dataStream.writeInt(identifier); dataStream.writeInt(expiryTime); dataStream.writeShort(deviceToken.length); dataStream.write(deviceToken); dataStream.writeShort(payload.length); dataStream.write(payload); return byteStream.toByteArray(); } catch (final IOException e) { throw new AssertionError(); } }
From source file:org.openxdata.server.servlet.DataImportServletTest.java
@Test @Ignore("this is an integration test for localhost") public void integrationTest() throws Exception { final String urlString = "http://localhost:8888/org.openxdata.server.admin.OpenXDataServerAdmin/dataimport?msisdn=2222222"; final String userName = "dagmar"; final String password = "dagmar"; // open url connection URL url = new URL(urlString); HttpURLConnection con = (HttpURLConnection) url.openConnection(); con.setRequestMethod("GET"); con.setDoOutput(true);/*from www .jav a 2 s . co m*/ con.setDoInput(true); con.setChunkedStreamingMode(1024); // stuff the Authorization request header byte[] encodedPassword = (userName + ":" + password).getBytes(); con.setRequestProperty("Authorization", "Basic " + new String(Base64.encodeBase64(encodedPassword))); // put the form data on the output stream DataOutputStream out = new DataOutputStream(con.getOutputStream()); out.writeByte(new Integer(1)); String data = "<?xml version='1.0' encoding='UTF-8' ?><cmt_lesotho_tlpp_session_report_v1 formKey=\"cmt_lesotho_tlpp_session_report_v1\" id=\"2\" name=\"Treatment literacy programme_v1\" xmlns:xf=\"http://www.w3.org/2002/xforms\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\"> <name>TEEHEE</name> <session_type>treatment_literacy_session</session_type> <session_date>2010-04-15</session_date> <district>berea</district> <session_location>secondary_school</session_location> <session_location_other/> <session_place_name>dsds</session_place_name> <participant_number_male>1</participant_number_male> <participant_number_female>2</participant_number_female> <session_start_time>10:22:00</session_start_time> <session_finish_time>01:22:00</session_finish_time> <session_topic>children_HIV_incl_ARVs</session_topic> <session_topic_other/> <support_group>false</support_group> <one_on_one_session>false</one_on_one_session> <CMT_AV_kit>false</CMT_AV_kit> <CMT_DVD>false</CMT_DVD> <CMT_co_facilitator>false</CMT_co_facilitator> <co_facilitator_name/> <clinic_hospital_department/> <clinic_hospital_department_other/> <clinic_hospital_TV/> <school_grade>12</school_grade> <school_CMT_materials>true</school_CMT_materials> <session_confirmed>true</session_confirmed></cmt_lesotho_tlpp_session_report_v1>"; out.writeUTF(data); out.flush(); // pull the information back from the URL InputStream is = con.getInputStream(); StringBuffer buf = new StringBuffer(); int c; while ((c = is.read()) != -1) { buf.append((char) c); } con.disconnect(); // output the information System.out.println(buf); }
From source file:com.codefollower.lealone.omid.tso.TimestampOracle.java
/** * Must be called holding an exclusive lock * //from ww w. j a v a2 s . co m * return the next timestamp */ public long next(DataOutputStream toWal) throws IOException { last++; if (last == maxTimestamp) { maxTimestamp += TIMESTAMP_BATCH; toWal.writeByte(LoggerProtocol.TIMESTAMP_ORACLE); toWal.writeLong(maxTimestamp); } return last; }
From source file:org.openxdata.server.serializer.JavaRosaXformSerializer.java
@SuppressWarnings("unchecked") public void serializeUsers(OutputStream os, Object data) { List<Object[]> users = (List<Object[]>) data; DataOutputStream dos = new DataOutputStream(os); try {// ww w .j a v a 2 s . c o m dos.writeByte(users.size()); for (Object[] user : users) { dos.writeInt((Integer) user[0]); dos.writeUTF((String) user[1]); dos.writeUTF((String) user[2]); dos.writeUTF((String) user[3]); } } catch (IOException e) { throw new UnexpectedException(e); } }
From source file:SafeUTF.java
public void safeWriteUTF(DataOutputStream out, String str) throws IOException { if (str == null) { out.writeByte(NULL); } else {/*from w w w . jav a2 s . c o m*/ int len = str.length(); short numChunks; if (len == 0) { numChunks = 0; } else { numChunks = (short) (((len - 1) / chunkSize) + 1); } out.writeByte(NOT_NULL); out.writeShort(numChunks); int i = 0; while (len > 0) { int beginCopy = i * chunkSize; int endCopy = len <= chunkSize ? beginCopy + len : beginCopy + chunkSize; String theChunk = str.substring(beginCopy, endCopy); out.writeUTF(theChunk); len -= chunkSize; i++; } } }
From source file:com.opensoc.json.serialization.JSONKafkaSerializer.java
public void putArray(DataOutputStream data, JSONArray array) throws IOException { data.writeByte(JSONKafkaSerializer.JSONArrayID); data.writeInt(array.size());/*w w w. j a v a 2s. c o m*/ for (Object o : array) putObject(data, o); }
From source file:com.yahoo.omid.tso.TimestampOracle.java
/** * Must be called holding an exclusive lock * /*from ww w . ja va 2 s . com*/ * return the next timestamp */ public long next(DataOutputStream toWal) throws IOException { last++; if (last == maxTimestamp) { maxTimestamp += TIMESTAMP_BATCH; toWal.writeByte(LoggerProtocol.TIMESTAMPORACLE); toWal.writeLong(maxTimestamp); if (LOG.isTraceEnabled()) { LOG.trace("Logging TimestampOracle " + maxTimestamp); } } if (LOG.isTraceEnabled()) { LOG.trace("Next timestamp: " + last); } return last; }
From source file:org.openmrs.module.odkconnector.serialization.serializer.custom.SerializedFormSerializer.java
/** * Write the data to the output stream./*w ww . j ava 2s.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); } }