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:IntSort.java
public void writeStream(String[] sData, boolean[] bData, int[] iData) { try {/*from www . j a va2 s. c o 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:com.igormaznitsa.jhexed.renders.svg.SVGImage.java
public void write(final OutputStream out, final boolean zipped) throws IOException { final DataOutputStream dout = out instanceof DataOutputStream ? (DataOutputStream) out : new DataOutputStream(out); if (zipped) { final byte[] packedImage = Utils.packByteArray(this.originalNonParsedImageData); dout.writeInt(packedImage.length); dout.write(packedImage);/* w w w .j a va 2s .c om*/ } else { dout.write(this.originalNonParsedImageData); } dout.writeBoolean(this.quality); }
From source file:ubic.basecode.io.ByteArrayConverter.java
/** * @param boolarray/* w ww. j a v a 2 s . c o m*/ * @return byte[] */ public byte[] booleanArrayToBytes(boolean[] boolarray) { if (boolarray == null) return null; ByteArrayOutputStream bos = new ByteArrayOutputStream(); DataOutputStream dos = new DataOutputStream(bos); try { for (boolean element : boolarray) { dos.writeBoolean(element); } } catch (IOException e) { // do nothing } return bos.toByteArray(); }
From source file:org.spout.engine.filesystem.WorldFiles.java
public static void writeColumn(OutputStream out, SpoutColumn column, AtomicInteger lowestY, BlockMaterial[][] topmostBlocks) { DataOutputStream dataStream = new DataOutputStream(out); try {/*from w ww .j av a 2 s .c o m*/ for (int x = 0; x < SpoutColumn.BLOCKS.SIZE; x++) { for (int z = 0; z < SpoutColumn.BLOCKS.SIZE; z++) { dataStream.writeInt(column.getAtomicInteger(x, z).get()); } } dataStream.writeInt(COLUMN_VERSION); dataStream.writeInt(lowestY.get()); StringMap global = ((SpoutEngine) Spout.getEngine()).getEngineItemMap(); StringMap itemMap; itemMap = column.getWorld().getItemMap(); for (int x = 0; x < SpoutColumn.BLOCKS.SIZE; x++) { for (int z = 0; z < SpoutColumn.BLOCKS.SIZE; z++) { Material m = topmostBlocks[x][z]; if (m == null) { dataStream.writeBoolean(false); continue; } else { dataStream.writeBoolean(true); } short blockId = m.getId(); short blockData = m.getData(); blockId = (short) global.convertTo(itemMap, blockId); dataStream.writeInt(BlockFullState.getPacked(blockId, blockData)); } } //Biome manager is serialized with: // - boolean, if a biome manager exists // - String, the class name // - int, the number of bytes of data to read // - byte[], size of the above int in length BiomeManager manager = column.getBiomeManager(); if (manager != null) { dataStream.writeBoolean(true); dataStream.writeUTF(manager.getClass().getName()); byte[] data = manager.serialize(); dataStream.writeInt(data.length); dataStream.write(data); } else { dataStream.writeBoolean(false); } dataStream.flush(); } catch (IOException e) { Spout.getLogger() .severe("Error writing column height-map for column" + column.getX() + ", " + column.getZ()); } }
From source file:org.apache.hadoop.io.TestArrayOutputStream.java
private void runComparison(ArrayOutputStream aos, DataOutputStream dos, ByteArrayOutputStream bos) throws IOException { Random r = new Random(); // byte/* w w w . j av a2s .c o m*/ int b = r.nextInt(128); aos.write(b); dos.write(b); // byte[] byte[] bytes = new byte[10]; r.nextBytes(bytes); aos.write(bytes, 0, 10); dos.write(bytes, 0, 10); // Byte aos.writeByte(b); dos.writeByte(b); // boolean boolean bool = r.nextBoolean(); aos.writeBoolean(bool); dos.writeBoolean(bool); // short short s = (short) r.nextInt(); aos.writeShort(s); dos.writeShort(s); // char int c = r.nextInt(); aos.writeChar(c); dos.writeChar(c); // int int i = r.nextInt(); aos.writeInt(i); dos.writeInt(i); // long long l = r.nextLong(); aos.writeLong(l); dos.writeLong(l); // float float f = r.nextFloat(); aos.writeFloat(f); dos.writeFloat(f); // double double d = r.nextDouble(); aos.writeDouble(d); dos.writeDouble(d); // strings String str = RandomStringUtils.random(20); aos.writeBytes(str); aos.writeChars(str); aos.writeUTF(str); dos.writeBytes(str); dos.writeChars(str); dos.writeUTF(str); byte[] expected = bos.toByteArray(); assertEquals(expected.length, aos.size()); byte[] actual = new byte[aos.size()]; System.arraycopy(aos.getBytes(), 0, actual, 0, actual.length); // serialized bytes should be the same assertTrue(Arrays.equals(expected, actual)); }
From source file:com.chaosinmotion.securechat.server.messages.NotificationSocket.java
/** * Internal method for sending a message to the specified device. This * encodes the message as a binary array and transmits it as a single * packet to the listening device. This allows users to receive messages * during chat as soon as we are able to, for (more or less) just in time * messaging.// ww w . j ava 2 s. c o m * * The packet returned here is similar to the packet returned by the * getmessages api, except we serialize as binary. * * @param messageid * @param senderid * @param sendername * @param ts * @param message * @throws IOException */ void sendMessage(int messageid, int senderid, String sendername, boolean toflag, Timestamp ts, byte[] message) throws IOException { ByteArrayOutputStream baos = new ByteArrayOutputStream(); DataOutputStream dos = new DataOutputStream(baos); /* * Encode. First byte is 0x20 */ String date; synchronized (format) { date = format.format(ts); } /* * Formulate packet in expected format */ dos.writeByte(0x20); // marker dos.writeBoolean(toflag); dos.writeInt(messageid); dos.writeInt(senderid); dos.writeUTF(date); dos.writeUTF(sendername); dos.writeInt(message.length); dos.write(message); /* * Flush and write packet to device. Our protocol does not depend on * the device actually receiving this message, as we wait until the * device deletes the messages by a separate command. */ dos.flush(); out.writeData(baos.toByteArray()); }
From source file:org.veronicadb.core.memorygraph.storage.SimpleLocalFileStorageSink.java
protected void writeVertexEdge(DataOutputStream stream, VVertex vertex) throws IOException { stream.writeInt(vertex.getEdges().size()); for (VEdge edge : vertex.getEdges()) { writeElementId(stream, edge);/* w w w .jav a 2 s .c o m*/ writeElementLabel(stream, edge); long otherVertex = edge.getOtherVertex(vertex.getId()); boolean direction = edge.isInV(otherVertex); stream.writeBoolean(direction); boolean sharedShard = edge.getOutVGraph().getShardId() == edge.getGraphShard().getShardId(); stream.writeBoolean(sharedShard); if (!sharedShard) { if (vertex.getGraphShard().getShardId() == edge.getGraphShard().getShardId()) { writeElementId(edge.getOutVGraph().getShardId(), stream); } else { writeElementId(edge.getGraphShard().getShardId(), stream); } } writeElementId(otherVertex, stream); } }
From source file:BugTracker.java
private void saveBugs() { // Save bugs to a file. DataOutputStream out = null; try {/* w ww . ja va 2 s. co m*/ File file = new File("bugs.dat"); out = new DataOutputStream(new FileOutputStream(file)); for (int i = 0; i < table.getItemCount(); i++) { TableItem item = table.getItem(i); out.writeUTF(item.getText(0)); out.writeUTF(item.getText(1)); out.writeUTF(item.getText(2)); out.writeBoolean(item.getText(3).equalsIgnoreCase("YES")); } } catch (IOException ioe) { // Ignore. } finally { try { if (out != null) out.close(); } catch (IOException e) { e.printStackTrace(); } } }
From source file:BugTrackerJFace.java
private void saveBugs(Vector v) { // Save bugs to a file. DataOutputStream out = null; try {/*www . j a va 2s .c om*/ File file = new File("bugs.dat"); out = new DataOutputStream(new FileOutputStream(file)); for (int i = 0; i < v.size(); i++) { Bug bug = (Bug) v.elementAt(i); out.writeUTF(bug.id); out.writeUTF(bug.summary); out.writeUTF(bug.assignedTo); out.writeBoolean(bug.isSolved); } } catch (IOException ioe) { // Ignore. } finally { try { if (out != null) out.close(); } catch (IOException e) { e.printStackTrace(); } } }
From source file:com.adito.notification.Notifier.java
void write(Message message) throws IOException { if (log.isDebugEnabled()) log.debug("Writing message " + message.getId() + " '" + message.getSubject() + "' to disk"); FileOutputStream fout = new FileOutputStream( new File(queueDirectory, String.valueOf(message.getId()) + ".msg")); try {//from w w w . j av a2 s . com DataOutputStream dout = new DataOutputStream(fout); dout.writeLong(message.getId()); dout.writeUTF(message.getSinkName()); dout.writeBoolean(message.isUrgent()); dout.writeUTF(message.getSubject()); for (Iterator i = message.getRecipients().iterator(); i.hasNext();) { Recipient r = (Recipient) i.next(); dout.writeInt(r.getRecipientType()); dout.writeUTF(r.getRecipientAlias() == null ? "" : r.getRecipientAlias()); dout.writeUTF(r.getRealmName() == null ? "" : r.getRealmName()); } dout.writeInt(0); for (Iterator i = message.getParameterNames(); i.hasNext();) { String key = (String) i.next(); dout.writeInt(1); dout.writeUTF(key); dout.writeUTF(message.getParameter(key)); } dout.writeInt(0); dout.writeUTF(message.getContent()); dout.writeUTF(message.getLastMessage()); } finally { fout.close(); } }