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:Main.java
public static byte[] getBodyBytes(String ip, String port, String key) throws NumberFormatException, IOException { String[] ipArr = ip.split("\\."); byte[] ipByte = new byte[4]; ipByte[0] = (byte) (Integer.parseInt(ipArr[0]) & 0xFF); ipByte[1] = (byte) (Integer.parseInt(ipArr[1]) & 0xFF); ipByte[2] = (byte) (Integer.parseInt(ipArr[2]) & 0xFF); ipByte[3] = (byte) (Integer.parseInt(ipArr[3]) & 0xFF); ByteArrayOutputStream baos = new ByteArrayOutputStream(); DataOutputStream dos = new DataOutputStream(baos); dos.write(ipByte);/* w w w .j a v a2 s.co m*/ dos.writeShort(Short.parseShort(port)); dos.writeByte(key.getBytes().length); dos.write(key.getBytes()); byte[] bs = baos.toByteArray(); baos.close(); dos.close(); return bs; }
From source file:com.opensoc.json.serialization.JSONEncoderHelper.java
public static void putNull(DataOutputStream data, Object value) throws IOException { // TODO Auto-generated method stub data.writeByte(JSONKafkaSerializer.NULLID); }
From source file:com.opensoc.json.serialization.JSONEncoderHelper.java
public static void putBoolean(DataOutputStream data, Boolean value) throws IOException { // TODO Auto-generated method stub data.writeByte(JSONKafkaSerializer.BooleanID); data.writeBoolean(value);//from ww w. j a v a 2 s .co m }
From source file:com.opensoc.json.serialization.JSONEncoderHelper.java
public static void putNumber(DataOutputStream data, Number value) throws IOException { // TODO Auto-generated method stub data.writeByte(JSONKafkaSerializer.NumberID); if (value instanceof Double) { data.writeByte(0);// w ww . j av a 2 s . c o m data.writeDouble((Double) value); return; } data.writeByte(1); data.writeLong((Long) value); }
From source file:org.globus.ftp.dc.EBlockImageDCWriter.java
public static void close(DataOutputStream myOutput) throws IOException { byte desc;//from ww w . ja v a 2 s.c o m // EOF and EOD have already been sent desc = WILL_CLOSE; myOutput.writeByte(desc); myOutput.writeLong(0); myOutput.writeLong(0); logger.debug("Wrote WILL_CLOSE, closing the socket"); // close the socket myOutput.close(); }
From source file:net.datenwerke.transloader.primitive.WrapperConverter.java
private static void write(Object wrapper, DataOutputStream dataStream) throws IOException { char typeCode = getTypeCode(wrapper); switch (typeCode) { case 'B': dataStream.writeByte(intValue(wrapper)); break;//from w ww . ja va 2 s .c om case 'C': dataStream.writeChar(charValue(wrapper)); break; case 'S': dataStream.writeShort(intValue(wrapper)); break; case 'I': dataStream.writeInt(intValue(wrapper)); break; case 'J': dataStream.writeLong(number(wrapper).longValue()); break; case 'F': dataStream.writeFloat(number(wrapper).floatValue()); break; case 'D': dataStream.writeDouble(number(wrapper).doubleValue()); break; case 'Z': dataStream.writeBoolean(booleanValue(wrapper)); } }
From source file:com.dbay.apns4j.tools.ApnsTools.java
@Deprecated public final static byte[] generateData(int id, int expire, byte[] token, byte[] payload) { ByteArrayOutputStream bos = new ByteArrayOutputStream(); DataOutputStream os = new DataOutputStream(bos); try {/*from w w w.j ava 2s . co m*/ os.writeByte(Command.SEND); os.writeInt(id); os.writeInt(expire); os.writeShort(token.length); os.write(token); os.writeShort(payload.length); os.write(payload); os.flush(); return bos.toByteArray(); } catch (IOException e) { e.printStackTrace(); } throw new RuntimeException(); }
From source file:Main.java
private static NdefRecord createText(String paramString1, String paramString2) { int i = 0;/*from w ww. j ava2 s .co m*/ try { ByteArrayOutputStream localByteArrayOutputStream = new ByteArrayOutputStream(); DataOutputStream localDataOutputStream = new DataOutputStream(localByteArrayOutputStream); byte[] arrayOfByte1 = paramString2.getBytes(Charset.forName("US-ASCII")); byte[] arrayOfByte2 = paramString1.getBytes(Charset.forName("UTF-8")); localDataOutputStream.writeByte((byte) (char) (i + arrayOfByte1.length)); localDataOutputStream.write(arrayOfByte1); localDataOutputStream.write(arrayOfByte2); NdefRecord localNdefRecord = new NdefRecord(NdefRecord.TNF_WELL_KNOWN, NdefRecord.RTD_TEXT, new byte[0], localByteArrayOutputStream.toByteArray()); return localNdefRecord; } catch (IOException localIOException) { throw new RuntimeException(localIOException); } }
From source file:truelauncher.client.auth.Type2.java
private static void writeVarInt(DataOutputStream dos, int varint) throws IOException { int part;//from w ww . j ava2 s .c om while (true) { part = varint & 0x7F; varint >>>= 7; if (varint != 0) { part |= 0x80; } dos.writeByte(part); if (varint == 0) { break; } } }
From source file:Main.java
protected static void serialiseLength(DataOutputStream os, int len, int max_length) throws IOException { if (len > max_length) { throw (new IOException("Invalid DHT data length: max=" + max_length + ",actual=" + len)); }/* w w w. j a v a 2 s . c om*/ if (max_length < 256) { os.writeByte(len); } else if (max_length < 65536) { os.writeShort(len); } else { os.writeInt(len); } }