List of usage examples for java.io DataOutputStream writeInt
public final void writeInt(int v) throws IOException
int
to the underlying output stream as four bytes, high byte first. From source file:Main.java
public static void main(String args[]) throws IOException { int howMany = 20; ByteArrayOutputStream bout = new ByteArrayOutputStream(howMany * 4); DataOutputStream dout = new DataOutputStream(bout); for (int i = 0; i <= 20; i++) { dout.writeInt(i); }//from ww w.jav a2 s .c om FileOutputStream fout = new FileOutputStream("fibonacci.dat"); try { bout.writeTo(fout); fout.flush(); } finally { fout.close(); } }
From source file:MainClass.java
public static void main(String args[]) throws IOException { int howMany = 20; // To avoid resizing the buffer, calculate the size of the // byte array in advance. ByteArrayOutputStream bout = new ByteArrayOutputStream(howMany * 4); DataOutputStream dout = new DataOutputStream(bout); for (int i = 0; i <= 20; i++) { dout.writeInt(i); }/* w ww .j a v a2s . co m*/ FileOutputStream fout = new FileOutputStream("fibonacci.dat"); try { bout.writeTo(fout); fout.flush(); } finally { fout.close(); } }
From source file:PrimeWriter.java
public static void main(String[] arguments) { int[] primes = new int[400]; int numPrimes = 0; int candidate = 2; while (numPrimes < 400) { primes[numPrimes] = candidate;//w w w . j a va 2 s.c o m numPrimes++; candidate++; } try { FileOutputStream file = new FileOutputStream("p.dat"); BufferedOutputStream buff = new BufferedOutputStream(file); DataOutputStream data = new DataOutputStream(buff); for (int i = 0; i < 400; i++) data.writeInt(primes[i]); data.close(); } catch (IOException e) { System.out.println("Error - " + e.toString()); } }
From source file:Main.java
public static void main(String[] argv) throws Exception { double data[] = { 1.1, 2.2, 3.3, 4.4, 5.5, 6.6 }; DataOutputStream fout = new DataOutputStream(new DeflaterOutputStream(new FileOutputStream("data.dat"))); fout.writeInt(data.length); for (double d : data) fout.writeDouble(d);/* ww w. j a v a 2s . c o m*/ DataInputStream fin = new DataInputStream(new InflaterInputStream(new FileInputStream("data.dat"))); int num = fin.readInt(); double avg = 0.0; double d; for (int i = 0; i < num; i++) { d = fin.readDouble(); avg += d; System.out.print(d + " "); } fin.close(); fout.close(); }
From source file:Main.java
public static void main(String[] args) throws Exception { FileOutputStream fos = new FileOutputStream("C:/WriteLong.txt"); DataOutputStream dos = new DataOutputStream(fos); long l = 65;//from w w w .j av a 2 s .c om dos.writeLong(l); for (int i = 0; i < 10; i++) dos.writeInt(i); dos.close(); }
From source file:MainClass.java
public static void main(String[] args) throws IOException { DataOutputStream dos = new DataOutputStream( new BufferedOutputStream(new FileOutputStream(new File("temp.tmp")))); for (int i = 0; i < 10; i++) dos.writeInt(i); dos.close();//from w ww .j a v a2s .c o m }
From source file:Main.java
public static void main(String[] args) throws Exception { ByteArrayOutputStream baos = new ByteArrayOutputStream(); DataOutputStream dos = new DataOutputStream(baos); MessageDigest md = MessageDigest.getInstance("MD5"); SomeObject testObject = new SomeObject(); dos.writeInt(testObject.count); dos.writeLong(testObject.product);//from w ww .j av a 2 s. c o m dos.writeDouble(testObject.stdDev); dos.writeUTF(testObject.name); dos.writeChar(testObject.delimiter); dos.flush(); byte[] hashBytes = md.digest(baos.toByteArray()); BigInteger testObjectHash = new BigInteger(hashBytes); System.out.println("Hash " + testObjectHash); dos.close(); }
From source file:MainClass.java
public static void main(String args[]) { try {/*from w w w . java 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.payne.test.StringTest.java
public static void main(String[] args) throws IOException { // String a = "160504185452148809-1"; // a = a.split("-")[0]; // System.out.println(a); // Random r = new Random(); // long a = 0l; // for(int i=0;i<10000;i++){ // a = r.nextInt(5001) + 5000; // if(a==5000){ // System.out.println(a); // } // }/*from w ww . j a v a 2s. c o m*/ /** * ???? */ // List<Integer> numberList = new ArrayList<>(); // numberList.add(1); // numberList.add(2); // Integer[] numbers = numberList.toArray(new Integer[numberList.size()]); //// int[] numbers = new int[]{1,2}; // // System.out.println(new Integer[]{}.length==0?0:1); // // Student s = new Student(); // s.sumUp(new Integer[]{}.length==0?numbers:new Integer[]{1}); // s.sumUp(numbers); // Parent p = null; // Parent p2 = new Parent(new Student(5)); // // Student s = new Student(); // p = s.print(p); // System.out.println(p==null?0:1); // System.out.println(p.getAge()); // System.out.println(p.getStudent().getAge()); // int ai = 0; // for(int i=0;i<2;i++){ // int b = 0; // int b_grow = 0; // for(int j=0;j<5;j++){ // b += new Random().nextInt(5); // } // // } // // // System.out.println(UUID.randomUUID().toString()); // int a = 1; // a = doAdd(a); // System.out.println(a); Pattern p = Pattern.compile("^\\d{1,9}(.\\d{1,2})?$"); Matcher m = p.matcher("666666541.13"); boolean b = m.matches(); System.out.println(b); // System.out.println(-2>>4); // BigDecimal b = new BigDecimal(100.50); // System.out.println(b.toString()); // indexOf ?? // String a = "?"; // // String[] split = a.split("?"); // if(a.indexOf("?")>-1){ // System.out.println("111"); // } // for(String s: split){ // System.out.println(s); // } // MapTestObject mto = new MapTestObject(); // mto.setOrderType(OrderType.TWO); // // String str = "\":\""; // System.out.println(str); // String a = ","; //// // String[] splits = a.split("."); // List<String> asList = Arrays.asList(splits); // String last = ""; // String last = ""; // String last = ""; // if (!asList.isEmpty()) { // if (asList.indexOf(last) > -1) { // int indexOf = asList.indexOf(last); // if (indexOf + 1 >= asList.size()) { // System.out.println("?"); // }else{ // String next = asList.get(indexOf + 1); // if (OTHERStringUtils.isEmpty(next)) { // System.out.println("?"); // } else { // System.out.println("?" + next); // } // } // } else { // System.out.println("?"); // } // } else { // System.out.println("??"); // } // System.out.println("?\",\""); // String a ="1123"; // a = StringUtils.substring(a, 0, a.length()-1); // System.out.println("a="+a); // int a = 0x12345678; ByteArrayOutputStream baos = new ByteArrayOutputStream(); DataOutputStream dos = new DataOutputStream(baos); dos.writeInt(a); System.out.println(Integer.toHexString(a)); byte[] c = baos.toByteArray(); for (int i = 0; i < 4; i++) { System.out.println(Integer.toHexString(c[i])); } }
From source file:com.tc.simple.apn.quicktests.Test.java
/** * @param args//from w ww. j a v a 2s . c om */ 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(); } } }