List of usage examples for java.io DataOutputStream writeBoolean
public final void writeBoolean(boolean v) throws IOException
boolean
to the underlying output stream as a 1-byte value. From source file:J2MEMixedRecordEnumerationExample.java
public void commandAction(Command command, Displayable displayable) { if (command == exit) { destroyApp(true);/* ww w . j a v a 2s . co m*/ notifyDestroyed(); } else if (command == start) { try { recordstore = RecordStore.openRecordStore("myRecordStore", true); byte[] outputRecord; String outputString[] = { "First Record", "Second Record", "Third Record" }; int outputInteger[] = { 15, 10, 5 }; boolean outputBoolean[] = { true, false, true }; ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); DataOutputStream outputDataStream = new DataOutputStream(outputStream); for (int x = 0; x < 3; x++) { outputDataStream.writeUTF(outputString[x]); outputDataStream.writeBoolean(outputBoolean[x]); outputDataStream.writeInt(outputInteger[x]); outputDataStream.flush(); outputRecord = outputStream.toByteArray(); recordstore.addRecord(outputRecord, 0, outputRecord.length); } outputStream.reset(); outputStream.close(); outputDataStream.close(); StringBuffer buffer = new StringBuffer(); byte[] byteInputData = new byte[300]; ByteArrayInputStream inputStream = new ByteArrayInputStream(byteInputData); DataInputStream inputDataStream = new DataInputStream(inputStream); recordEnumeration = recordstore.enumerateRecords(null, null, false); while (recordEnumeration.hasNextElement()) { recordstore.getRecord(recordEnumeration.nextRecordId(), byteInputData, 0); buffer.append(inputDataStream.readUTF()); buffer.append("\n"); buffer.append(inputDataStream.readBoolean()); buffer.append("\n"); buffer.append(inputDataStream.readInt()); buffer.append("\n"); alert = new Alert("Reading", buffer.toString(), null, AlertType.WARNING); alert.setTimeout(Alert.FOREVER); display.setCurrent(alert); } inputStream.close(); recordstore.closeRecordStore(); if (RecordStore.listRecordStores() != null) { RecordStore.deleteRecordStore("myRecordStore"); recordEnumeration.destroy(); } } catch (Exception error) { alert = new Alert("Error Removing", error.toString(), null, AlertType.WARNING); alert.setTimeout(Alert.FOREVER); display.setCurrent(alert); } } }
From source file:org.getspout.spout.packet.PacketAddonData.java
public void writeData(DataOutputStream output) throws IOException { PacketUtil.writeString(output, (AddonPacket.getPacketId(packet.getClass()))); output.writeInt(data.length);/* ww w. j a v a 2s .co m*/ output.writeBoolean(compressed); output.write(data); }
From source file:org.spoutcraft.client.packet.PacketEntityInformation.java
public void writeData(DataOutputStream output) throws IOException { if (data != null) { output.writeInt(data.length);/*ww w . ja v a 2 s. c om*/ output.write(data); } else { output.writeInt(0); } output.writeBoolean(compressed); }
From source file:org.slc.sli.dal.encrypt.AesCipher.java
@Override public String encrypt(Object data) { if (data instanceof String) { return "ESTRING:" + encryptFromBytes(StringUtils.getBytesUtf8((String) data)); } else {//from w w w .ja v a 2 s . com ByteArrayOutputStream byteOutputStream = new ByteArrayOutputStream(); DataOutputStream dos = new DataOutputStream(byteOutputStream); String type; try { if (data instanceof Boolean) { dos.writeBoolean((Boolean) data); type = "EBOOL:"; } else if (data instanceof Integer) { dos.writeInt((Integer) data); type = "EINT:"; } else if (data instanceof Long) { dos.writeLong((Long) data); type = "ELONG:"; } else if (data instanceof Double) { dos.writeDouble((Double) data); type = "EDOUBLE:"; } else { throw new RuntimeException("Unsupported type: " + data.getClass().getCanonicalName()); } dos.flush(); dos.close(); } catch (IOException e) { throw new RuntimeException(e); } byte[] bytes = byteOutputStream.toByteArray(); return type + encryptFromBytes(bytes); } }
From source file:MixedRecordEnumerationExample.java
public void commandAction(Command command, Displayable displayable) { if (command == exit) { destroyApp(true);//from w ww .ja v a2 s .c o m notifyDestroyed(); } else if (command == start) { try { recordstore = RecordStore.openRecordStore("myRecordStore", true); } catch (Exception error) { alert = new Alert("Error Creating", error.toString(), null, AlertType.WARNING); alert.setTimeout(Alert.FOREVER); display.setCurrent(alert); } try { byte[] outputRecord; String outputString[] = { "First Record", "Second Record", "Third Record" }; int outputInteger[] = { 15, 10, 5 }; boolean outputBoolean[] = { true, false, true }; ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); DataOutputStream outputDataStream = new DataOutputStream(outputStream); for (int x = 0; x < 3; x++) { outputDataStream.writeUTF(outputString[x]); outputDataStream.writeBoolean(outputBoolean[x]); outputDataStream.writeInt(outputInteger[x]); outputDataStream.flush(); outputRecord = outputStream.toByteArray(); recordstore.addRecord(outputRecord, 0, outputRecord.length); } outputStream.reset(); outputStream.close(); outputDataStream.close(); } catch (Exception error) { alert = new Alert("Error Writing", error.toString(), null, AlertType.WARNING); alert.setTimeout(Alert.FOREVER); display.setCurrent(alert); } try { StringBuffer buffer = new StringBuffer(); byte[] byteInputData = new byte[300]; ByteArrayInputStream inputStream = new ByteArrayInputStream(byteInputData); DataInputStream inputDataStream = new DataInputStream(inputStream); recordEnumeration = recordstore.enumerateRecords(null, null, false); while (recordEnumeration.hasNextElement()) { recordstore.getRecord(recordEnumeration.nextRecordId(), byteInputData, 0); buffer.append(inputDataStream.readUTF()); buffer.append("\n"); buffer.append(inputDataStream.readBoolean()); buffer.append("\n"); buffer.append(inputDataStream.readInt()); buffer.append("\n"); alert = new Alert("Reading", buffer.toString(), null, AlertType.WARNING); alert.setTimeout(Alert.FOREVER); display.setCurrent(alert); } inputStream.close(); } catch (Exception error) { alert = new Alert("Error Reading", error.toString(), null, AlertType.WARNING); alert.setTimeout(Alert.FOREVER); display.setCurrent(alert); } try { recordstore.closeRecordStore(); } catch (Exception error) { alert = new Alert("Error Closing", error.toString(), null, AlertType.WARNING); alert.setTimeout(Alert.FOREVER); display.setCurrent(alert); } if (RecordStore.listRecordStores() != null) { try { RecordStore.deleteRecordStore("myRecordStore"); recordEnumeration.destroy(); } catch (Exception error) { alert = new Alert("Error Removing", error.toString(), null, AlertType.WARNING); alert.setTimeout(Alert.FOREVER); display.setCurrent(alert); } } } }
From source file:org.openmrs.module.odkconnector.serialization.web.PatientWebConnectorTest.java
@Test public void serialize_shouldDisplayAllPatientInformation() throws Exception { // compose url URL u = new URL(SERVER_URL + "/module/odkconnector/download/patients.form"); // setup http url connection HttpURLConnection connection = (HttpURLConnection) u.openConnection(); connection.setDoOutput(true);// ww w. j ava 2s . c om connection.setRequestMethod("POST"); connection.setConnectTimeout(10000); connection.setReadTimeout(10000); connection.addRequestProperty("Content-type", "application/octet-stream"); // write auth details to connection DataOutputStream outputStream = new DataOutputStream(new GZIPOutputStream(connection.getOutputStream())); outputStream.writeUTF("admin"); outputStream.writeUTF("test"); outputStream.writeBoolean(true); outputStream.writeInt(2); outputStream.writeInt(1); outputStream.close(); DataInputStream inputStream = new DataInputStream(new GZIPInputStream(connection.getInputStream())); Integer responseStatus = inputStream.readInt(); ByteArrayOutputStream arrayOutputStream = new ByteArrayOutputStream(); int count = 0; byte[] buffer = new byte[1024]; while ((count = inputStream.read(buffer)) > 0) { arrayOutputStream.write(buffer, 0, count); } arrayOutputStream.close(); inputStream.close(); File file = new File("/home/nribeka/connector.data"); FileOutputStream fos = new FileOutputStream(file); fos.write(arrayOutputStream.toByteArray()); fos.close(); inputStream = new DataInputStream(new FileInputStream(file)); if (responseStatus == HttpURLConnection.HTTP_OK) { // total number of patients Integer patientCounter = inputStream.readInt(); System.out.println("Patient Counter: " + patientCounter); for (int j = 0; j < patientCounter; j++) { System.out.println("=================Patient====================="); System.out.println("Patient Id: " + inputStream.readInt()); System.out.println("Family Name: " + inputStream.readUTF()); System.out.println("Middle Name: " + inputStream.readUTF()); System.out.println("Last Name: " + inputStream.readUTF()); System.out.println("Gender: " + inputStream.readUTF()); System.out.println("Birth Date: " + inputStream.readUTF()); System.out.println("Identifier: " + inputStream.readUTF()); System.out.println("Patients: " + j + " out of " + patientCounter); } Integer obsCounter = inputStream.readInt(); System.out.println("Observation Counter: " + obsCounter); for (int j = 0; j < obsCounter; j++) { System.out.println("==================Observation================="); System.out.println("Patient Id: " + inputStream.readInt()); System.out.println("Concept Name: " + inputStream.readUTF()); byte type = inputStream.readByte(); if (type == ObsSerializer.TYPE_STRING) System.out.println("Value: " + inputStream.readUTF()); else if (type == ObsSerializer.TYPE_INT) System.out.println("Value: " + inputStream.readInt()); else if (type == ObsSerializer.TYPE_DOUBLE) System.out.println("Value: " + inputStream.readDouble()); else if (type == ObsSerializer.TYPE_DATE) System.out.println("Value: " + inputStream.readUTF()); System.out.println("Time: " + inputStream.readUTF()); System.out.println("Obs: " + j + " out of: " + obsCounter); } Integer formCounter = inputStream.readInt(); System.out.println("Form Counter: " + formCounter); for (int j = 0; j < formCounter; j++) { System.out.println("==================Observation================="); System.out.println("Patient Id: " + inputStream.readInt()); System.out.println("Concept Name: " + inputStream.readUTF()); byte type = inputStream.readByte(); if (type == ObsSerializer.TYPE_STRING) System.out.println("Value: " + inputStream.readUTF()); else if (type == ObsSerializer.TYPE_INT) System.out.println("Value: " + inputStream.readInt()); else if (type == ObsSerializer.TYPE_DOUBLE) System.out.println("Value: " + inputStream.readDouble()); else if (type == ObsSerializer.TYPE_DATE) System.out.println("Value: " + inputStream.readUTF()); System.out.println("Time: " + inputStream.readUTF()); System.out.println("Form: " + j + " out of: " + formCounter); } } inputStream.close(); }
From source file:ReadWriteStreams.java
public void writeStream(String[] sData, boolean[] bData, int[] iData) { try {//from ww w . jav a2s . co m // Write data into an internal byte array ByteArrayOutputStream strmBytes = new ByteArrayOutputStream(); // Write Java data types into the above byte array DataOutputStream strmDataType = new DataOutputStream(strmBytes); byte[] record; for (int i = 0; i < sData.length; i++) { // Write Java data types strmDataType.writeUTF(sData[i]); strmDataType.writeBoolean(bData[i]); strmDataType.writeInt(iData[i]); // Clear any buffered data strmDataType.flush(); // Get stream data into byte array and write record record = strmBytes.toByteArray(); rs.addRecord(record, 0, record.length); // Toss any data in the internal array so writes // starts at beginning (of the internal array) strmBytes.reset(); } strmBytes.close(); strmDataType.close(); } catch (Exception e) { db(e.toString()); } }
From source file:org.apache.cassandra.db.ReadCommand.java
public void serialize(ReadCommand rm, DataOutputStream dos) throws IOException { dos.writeUTF(rm.table);/*from ww w. java2 s.c o m*/ dos.writeUTF(rm.key); dos.writeUTF(rm.columnFamilyColumn); dos.writeInt(rm.start); dos.writeInt(rm.count); dos.writeLong(rm.sinceTimestamp); dos.writeBoolean(rm.isDigestQuery()); dos.writeInt(rm.columnNames.size()); if (rm.columnNames.size() > 0) { for (String cName : rm.columnNames) { dos.writeInt(cName.getBytes().length); dos.write(cName.getBytes()); } } }
From source file:com.atilika.kuromoji.trie.DoubleArrayTrie.java
public void write(OutputStream output) throws IOException { baseBuffer.rewind();// ww w. j a v a 2 s .c o m checkBuffer.rewind(); tailBuffer.rewind(); int baseCheckSize = Math.min(maxBaseCheckIndex + 64, baseBuffer.capacity()); int tailSize = Math.min(tailIndex - TAIL_OFFSET + 64, tailBuffer.capacity()); DataOutputStream dataOutput = new DataOutputStream(new BufferedOutputStream(output)); dataOutput.writeBoolean(compact); dataOutput.writeInt(baseCheckSize); dataOutput.writeInt(tailSize); WritableByteChannel channel = Channels.newChannel(dataOutput); ByteBuffer tmpBuffer = ByteBuffer.allocate(baseCheckSize * 4); IntBuffer tmpIntBuffer = tmpBuffer.asIntBuffer(); tmpIntBuffer.put(baseBuffer.array(), 0, baseCheckSize); tmpBuffer.rewind(); channel.write(tmpBuffer); tmpBuffer = ByteBuffer.allocate(baseCheckSize * 4); tmpIntBuffer = tmpBuffer.asIntBuffer(); tmpIntBuffer.put(checkBuffer.array(), 0, baseCheckSize); tmpBuffer.rewind(); channel.write(tmpBuffer); tmpBuffer = ByteBuffer.allocate(tailSize * 2); CharBuffer tmpCharBuffer = tmpBuffer.asCharBuffer(); tmpCharBuffer.put(tailBuffer.array(), 0, tailSize); tmpBuffer.rewind(); channel.write(tmpBuffer); dataOutput.flush(); }
From source file:com.ryan.ryanreader.cache.PersistentCookieStore.java
public synchronized byte[] toByteArray() { final ByteArrayOutputStream baos = new ByteArrayOutputStream(); final DataOutputStream dos = new DataOutputStream(baos); try {//ww w . j ava 2s . co m dos.writeInt(cookies.size()); for (final Cookie cookie : cookies) { dos.writeUTF(cookie.getName()); dos.writeUTF(cookie.getValue()); dos.writeUTF(cookie.getDomain()); dos.writeUTF(cookie.getPath()); dos.writeBoolean(cookie.isSecure()); } dos.flush(); dos.close(); } catch (IOException e) { throw new RuntimeException(e); } return baos.toByteArray(); }