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 void main(String[] args) throws Exception { FileOutputStream fos = new FileOutputStream("C:/WriteByte.txt"); DataOutputStream dos = new DataOutputStream(fos); int i = 1;/*from w ww . j a v a 2 s . co m*/ dos.writeByte(i); dos.close(); }
From source file:Main.java
public static void main(String[] args) throws IOException { byte[] buf = { 12, 15, 18, 20, 22, 24 }; ByteArrayOutputStream baos = new ByteArrayOutputStream(); DataOutputStream dos = new DataOutputStream(baos); for (byte b : buf) { dos.writeByte(b); }//from w w w. j av a 2 s .co m dos.flush(); for (byte b : baos.toByteArray()) { System.out.print(b); } }
From source file:Main.java
public static void main(String[] args) throws IOException { byte[] b = { 1, 2, 3, 4, 5, 6, 7, 8, 9 }; FileOutputStream fos = new FileOutputStream("c:\\test.txt"); DataOutputStream dos = new DataOutputStream(fos); for (byte j : b) { dos.writeByte(j); }//from w w w. jav a 2 s . c om dos.flush(); InputStream is = new FileInputStream("c:\\test.txt"); DataInputStream dis = new DataInputStream(is); while (dis.available() > 0) { int k = dis.read(); System.out.print(k); dis.skipBytes(1); } }
From source file:Main.java
public static void main(String[] args) throws IOException { byte[] b = { -123, 4 }; FileOutputStream fos = new FileOutputStream("c:\\test.txt"); DataOutputStream dos = new DataOutputStream(fos); for (byte j : b) { dos.writeByte(j); }/*w ww. j ava 2s . c o m*/ dos.flush(); InputStream is = new FileInputStream("c:\\test.txt"); DataInputStream dis = new DataInputStream(is); while (dis.available() > 0) { int k = dis.readUnsignedByte(); System.out.print(k); } }
From source file:MainClass.java
public static void main(String args[]) { try {//from www . jav a 2 s. c om FileOutputStream fos = new FileOutputStream(args[0]); DataOutputStream dos = new DataOutputStream(fos); dos.writeBoolean(false); dos.writeByte(Byte.MAX_VALUE); dos.writeChar('A'); dos.writeDouble(Double.MAX_VALUE); dos.writeFloat(Float.MAX_VALUE); dos.writeInt(Integer.MAX_VALUE); dos.writeLong(Long.MAX_VALUE); dos.writeShort(Short.MAX_VALUE); fos.close(); } catch (Exception e) { System.out.println("Exception: " + e); } }
From source file:com.tc.simple.apn.quicktests.Test.java
/** * @param args/*from w w w. j ava 2s. com*/ */ public static void main(String[] args) { SSLSocket socket = null; try { String host = "gateway.sandbox.push.apple.com"; int port = 2195; String token = "de7f197546e41a76684f8e2d89f397ed165298d7772f4bd9b0f39c674b185b0f"; System.out.println(token.toCharArray().length); //String token = "8cebc7c08f79fa62f0994eb4298387ff930857ff8d14a50de431559cf476b223"; KeyStore keyStore = KeyStore.getInstance("PKCS12"); keyStore.load(Test.class.getResourceAsStream("egram-dev-apn.p12"), "xxxxxxxxx".toCharArray()); KeyManagerFactory keyMgrFactory = KeyManagerFactory .getInstance(KeyManagerFactory.getDefaultAlgorithm()); keyMgrFactory.init(keyStore, "xxxxxxxxx".toCharArray()); SSLContext sslContext = SSLContext.getInstance("TLS"); sslContext.init(keyMgrFactory.getKeyManagers(), null, null); SSLSocketFactory socketFactory = sslContext.getSocketFactory(); socket = (SSLSocket) socketFactory.createSocket(host, port); String[] cipherSuites = socket.getSupportedCipherSuites(); socket.setEnabledCipherSuites(cipherSuites); socket.startHandshake(); char[] t = token.toCharArray(); byte[] b = Hex.decodeHex(t); OutputStream outputstream = socket.getOutputStream(); String payload = "{\"aps\":{\"alert\":\"yabadabadooo\"}}"; int expiry = (int) ((System.currentTimeMillis() / 1000L) + 7200); ByteArrayOutputStream bout = new ByteArrayOutputStream(); DataOutputStream dos = new DataOutputStream(bout); //command dos.writeByte(1); //id dos.writeInt(900); //expiry dos.writeInt(expiry); //token length. dos.writeShort(b.length); //token dos.write(b); //payload length dos.writeShort(payload.length()); //payload. dos.write(payload.getBytes()); byte[] byteMe = bout.toByteArray(); socket.getOutputStream().write(byteMe); socket.setSoTimeout(900); InputStream in = socket.getInputStream(); System.out.println(APNErrors.getError(in.read())); in.close(); outputstream.close(); } catch (Exception e) { e.printStackTrace(); } finally { try { socket.close(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } }
From source file:SecurityManagerTest.java
public static void main(String[] args) throws Exception { try {/* w w w .j a va 2 s. c o m*/ System.setSecurityManager(new PasswordSecurityManager("Booga Booga")); } catch (SecurityException se) { System.err.println("SecurityManager already set!"); } DataInputStream in = new DataInputStream(new FileInputStream("inputtext.txt")); DataOutputStream out = new DataOutputStream(new FileOutputStream("outputtext.txt")); String inputString; while ((inputString = in.readLine()) != null) { out.writeBytes(inputString); out.writeByte('\n'); } in.close(); out.close(); }
From source file:Main.java
public static void writeByteArray(byte[] bytes, DataOutputStream dos) throws Exception { for (int i = 0; i < bytes.length; dos.writeByte(bytes[i]), i++) ;//from w w w . j a v a 2 s.c o m }
From source file:com.opensoc.json.serialization.JSONEncoderHelper.java
public static void putString(DataOutputStream data, String str) throws IOException { // String ID is 1 data.writeByte(JSONKafkaSerializer.StringID); data.writeInt(str.length());/* w w w .j a va 2 s .c o m*/ data.write(str.getBytes()); }
From source file:Main.java
public static void writeBin(String fileName, byte[] data) { try {/*from w w w . jav a 2s. co m*/ DataOutputStream out = new DataOutputStream(new BufferedOutputStream(new FileOutputStream(fileName))); for (byte b : data) { out.writeByte(b); } out.close(); } catch (Exception e) { e.printStackTrace(); } }