List of usage examples for java.io ObjectOutputStream ObjectOutputStream
public ObjectOutputStream(OutputStream out) throws IOException
From source file:SerialVersionUID.java
/** * Generate a mapping of the serial version UIDs for the serializable classes * under the jboss dist directory/*from ww w . j a v a 2 s . c o m*/ * * @param args - * [0] = jboss dist root directory * @throws Exception */ public static void main(String[] args) throws Exception { if (args.length != 1) { System.err.println("Usage: jboss-home | -rihome ri-home"); System.exit(1); } File distHome = new File(args[0]); Map classVersionMap = null; if (args.length == 2) classVersionMap = generateRISerialVersionUIDReport(distHome); else classVersionMap = generateJBossSerialVersionUIDReport(distHome); // Write the map out the object file log.info("Total classes with serialVersionUID != 0: " + classVersionMap.size()); FileOutputStream fos = new FileOutputStream("serialuid.ser"); ObjectOutputStream oos = new ObjectOutputStream(fos); oos.writeObject(classVersionMap); fos.close(); }
From source file:com.icesoft.faces.webapp.parser.TagToComponentMap.java
/** * Main method for when this class is run to build the serialized data from * a set of TLDS.//from w ww.jav a2 s . com * * @param args The runtime arguements. */ public static void main(String args[]) { /* arg[0] is "new" to create serialzed data or 'old' to read serialized data arg[1] is filename for serialized data; arg[2...] are tld's to process */ FileInputStream tldFile = null; TagToComponentMap map = new TagToComponentMap(); if (args[0].equals("new")) { // Build new component map from tlds and serialize it; for (int i = 2; i < args.length; i++) { try { tldFile = new FileInputStream(args[i]); map.addTagAttrib((InputStream) tldFile); } catch (IOException e) { e.printStackTrace(); return; } } try { FileOutputStream fos = new FileOutputStream(args[1]); ObjectOutputStream oos = new ObjectOutputStream(fos); oos.writeObject(map); oos.flush(); oos.close(); } catch (Exception e) { e.printStackTrace(); } } else if (args[0].equals("old")) { // Build component from serialized data; try { FileInputStream fis = new FileInputStream(args[1]); ObjectInputStream ois = new ObjectInputStream(fis); map = (TagToComponentMap) ois.readObject(); } catch (Exception e) { e.printStackTrace(); } } else if (args[0].equals("facelets")) { // Build new component map from tld, and use that to // generate a Facelets taglib.xml // args[0] is command // args[1] is output taglib.xml // args[2] is input tld try { FileWriter faceletsTaglibXmlWriter = new FileWriter(args[1]); String preamble = "<?xml version=\"1.0\"?>\n" + "<facelet-taglib xmlns=\"http://java.sun.com/xml/ns/javaee\"\n" + "xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"\n" + "xsi:schemaLocation=\"http://java.sun.com/xml/ns/javaee " + "http://java.sun.com/xml/ns/javaee/web-facelettaglibrary_2_0.xsd\"\n" + "version=\"2.0\">\n"; String trailer = "</facelet-taglib>\n"; faceletsTaglibXmlWriter.write(preamble); map.setFaceletsTaglibXmlWriter(faceletsTaglibXmlWriter); tldFile = new FileInputStream(args[2]); map.addTagAttrib((InputStream) tldFile); faceletsTaglibXmlWriter.write(trailer); faceletsTaglibXmlWriter.flush(); faceletsTaglibXmlWriter.close(); } catch (IOException e) { e.printStackTrace(); return; } } }
From source file:Main.java
static public byte[] getObjectBytes(Object o) throws IOException { ByteArrayOutputStream baos = new ByteArrayOutputStream(); ObjectOutputStream oos = new ObjectOutputStream(baos); oos.writeObject(o);/* w ww .java 2 s .c o m*/ oos.close(); return baos.toByteArray(); }
From source file:Main.java
public static Object cloneObject(Object obj) { try {/*from www. j a va 2s.c o m*/ ByteArrayOutputStream byteOut = new ByteArrayOutputStream(); ObjectOutputStream out = new ObjectOutputStream(byteOut); out.writeObject(obj); ByteArrayInputStream byteIn = new ByteArrayInputStream(byteOut.toByteArray()); ObjectInputStream in = new ObjectInputStream(byteIn); return in.readObject(); } catch (IOException | ClassNotFoundException e) { e.printStackTrace(); } return null; }
From source file:Main.java
public static void SerializeObject(Object object, String path) throws IOException { ObjectOutputStream oo = new ObjectOutputStream(new FileOutputStream(new File(path))); oo.writeObject(object);//from w w w. ja v a2s . c om oo.close(); }
From source file:Main.java
public static void serializar(String path, Object obj) throws Exception { FileOutputStream outFile = new FileOutputStream(path); ObjectOutputStream s = new ObjectOutputStream(outFile); s.writeObject(obj);/*from ww w. j av a 2 s. c o m*/ s.close(); }
From source file:Main.java
public static void writeObject(OutputStream o, Object obj) throws IOException { ObjectOutputStream oo = new ObjectOutputStream(o); try {//from www . ja va 2 s .c om oo.writeObject(obj); } finally { oo.close(); } }
From source file:Main.java
public static byte[] serialize(Object obj) { ByteArrayOutputStream out = new ByteArrayOutputStream(); ObjectOutputStream os;// w w w .j a v a2 s . c o m try { os = new ObjectOutputStream(out); os.writeObject(obj); return out.toByteArray(); } catch (Exception e) { e.printStackTrace(); } return null; }
From source file:Main.java
public static boolean writeSerialize(FileOutputStream outputStream, Serializable obj) { try (ObjectOutputStream out = new ObjectOutputStream(outputStream)) { out.writeObject(obj);/*from w ww .java2 s. co m*/ out.flush(); return true; } catch (IOException e) { return false; } }
From source file:Main.java
public static <T> byte[] serializeToByteArray(T object) { ByteArrayOutputStream baos = new ByteArrayOutputStream(); try {/* w w w . j ava2 s .c o m*/ ObjectOutputStream oos = new ObjectOutputStream(baos); oos.writeObject(object); } catch (Exception e) { e.printStackTrace(); return null; } return baos.toByteArray(); }