List of usage examples for java.io DataOutputStream writeShort
public final void writeShort(int v) throws IOException
short
to the underlying output stream as two bytes, high byte first. From source file:dualcontrol.CryptoClientDemo.java
private void call(Properties properties, MockableConsole console, String hostAddress, int port, byte[] data) throws Exception { Socket socket = SSLContexts.create(false, "cryptoclient.ssl", properties, console).getSocketFactory() .createSocket(hostAddress, port); DataOutputStream dos = new DataOutputStream(socket.getOutputStream()); dos.writeShort(data.length); dos.write(data);//from w w w . ja v a2 s .c o m dos.flush(); DataInputStream dis = new DataInputStream(socket.getInputStream()); byte[] ivBytes = new byte[dis.readShort()]; dis.readFully(ivBytes); byte[] bytes = new byte[dis.readShort()]; dis.readFully(bytes); if (new String(data).contains("DECRYPT")) { System.err.printf("INFO CryptoClientDemo decrypted %s\n", new String(bytes)); } else { System.out.printf("%s:%s\n", Base64.encodeBase64String(ivBytes), Base64.encodeBase64String(bytes)); } socket.close(); }
From source file:org.apache.fontbox.ttf.TTFSubFont.java
/** * @param dos The data output stream.//from ww w . j av a 2 s .com * @param nTables The number of table. * @return The file offset of the first TTF table to write. * @throws IOException Upon errors. */ private static long writeFileHeader(DataOutputStream dos, int nTables) throws IOException { dos.writeInt(0x00010000); dos.writeShort(nTables); int mask = Integer.highestOneBit(nTables); int searchRange = mask * 16; dos.writeShort(searchRange); int entrySelector = log2i(mask); dos.writeShort(entrySelector); // numTables * 16 - searchRange int last = 16 * nTables - searchRange; dos.writeShort(last); return 0x00010000L + buildUint32(nTables, searchRange) + buildUint32(entrySelector, last); }
From source file:org.apache.fontbox.ttf.TTFSubFont.java
private static void writeFixed(DataOutputStream dos, double f) throws IOException { double ip = Math.floor(f); double fp = (f - ip) * 65536.0; dos.writeShort((int) ip); dos.writeShort((int) fp); }
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 {/*from ww w. j a v a2 s .c o 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:org.apache.hadoop.dfs.TestBlockReplacement.java
private boolean replaceBlock(Block block, DatanodeInfo source, DatanodeInfo sourceProxy, DatanodeInfo destination) throws IOException { Socket sock = new Socket(); sock.connect(NetUtils.createSocketAddr(sourceProxy.getName()), FSConstants.READ_TIMEOUT); sock.setKeepAlive(true);//from w w w .ja va 2 s. com // sendRequest DataOutputStream out = new DataOutputStream(sock.getOutputStream()); out.writeShort(FSConstants.DATA_TRANSFER_VERSION); out.writeByte(FSConstants.OP_COPY_BLOCK); out.writeLong(block.getBlockId()); out.writeLong(block.getGenerationStamp()); Text.writeString(out, source.getStorageID()); destination.write(out); out.flush(); // receiveResponse DataInputStream reply = new DataInputStream(sock.getInputStream()); short status = reply.readShort(); if (status == FSConstants.OP_STATUS_SUCCESS) { return true; } return false; }
From source file:org.apache.hadoop.hdfs.server.datanode.TestBlockReplacement.java
private boolean replaceBlock(Block block, DatanodeInfo source, DatanodeInfo sourceProxy, DatanodeInfo destination) throws IOException { Socket sock = new Socket(); sock.connect(NetUtils.createSocketAddr(destination.getName()), HdfsConstants.READ_TIMEOUT); sock.setKeepAlive(true);/*from w ww. j a v a 2 s. c o m*/ // sendRequest DataOutputStream out = new DataOutputStream(sock.getOutputStream()); out.writeShort(DataTransferProtocol.DATA_TRANSFER_VERSION); out.writeByte(DataTransferProtocol.OP_REPLACE_BLOCK); out.writeLong(block.getBlockId()); out.writeLong(block.getGenerationStamp()); Text.writeString(out, source.getStorageID()); sourceProxy.write(out); BlockTokenSecretManager.DUMMY_TOKEN.write(out); out.flush(); // receiveResponse DataInputStream reply = new DataInputStream(sock.getInputStream()); short status = reply.readShort(); if (status == DataTransferProtocol.OP_STATUS_SUCCESS) { return true; } return false; }
From source file:com.igormaznitsa.jhexed.swing.editor.filecontainer.FileContainer.java
public void write(final OutputStream out) throws IOException { final DataOutputStream dout = out instanceof DataOutputStream ? (DataOutputStream) out : new DataOutputStream(out); dout.writeInt(MAGIC);/*from ww w . j av a2 s .c o m*/ dout.writeShort(FORMAT_VERSION); dout.writeShort(this.sections.size()); for (final FileContainerSection s : this.sections) { s.write(dout); } dout.writeInt(MAGIC); dout.flush(); }
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 w w . ja v a 2s .co 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:com.github.terma.m.server.Repo.java
public void storeMetricCodes(final Map<String, Short> metricCodes) throws IOException { DataOutputStream dos = null; try {/*from w ww . j a v a2 s. co m*/ dos = new DataOutputStream(new FileOutputStream(eventCodesFile)); for (Map.Entry<String, Short> metricCode : metricCodes.entrySet()) { dos.writeUTF(metricCode.getKey()); dos.writeShort(metricCode.getValue()); } } finally { IOUtils.closeQuietly(dos); } }
From source file:org.structr.core.graph.SyncCommand.java
private static void writeObject(final DataOutputStream outputStream, final byte type, final Object value) throws IOException { switch (type) { case 0:/*w w w. j a v a 2 s .c o m*/ case 1: outputStream.writeByte((byte) value); break; case 2: case 3: outputStream.writeShort((short) value); break; case 4: case 5: outputStream.writeInt((int) value); break; case 6: case 7: outputStream.writeLong((long) value); break; case 8: case 9: outputStream.writeFloat((float) value); break; case 10: case 11: outputStream.writeDouble((double) value); break; case 12: case 13: outputStream.writeChar((char) value); break; case 14: case 15: serializeData(outputStream, ((String) value).getBytes("UTF-8")); // this doesn't work with very long strings //outputStream.writeUTF((String)value); break; case 16: case 17: outputStream.writeBoolean((boolean) value); break; } }