List of usage examples for java.io ObjectInputStream ObjectInputStream
public ObjectInputStream(InputStream in) throws IOException
From source file:edu.ucla.cs.scai.swim.qa.ontology.dbpedia.tipicality.Test.java
public static void main(String[] args) throws IOException, ClassNotFoundException { String path = DBpediaOntology.DBPEDIA_CSV_FOLDER; if (args != null && args.length > 0) { path = args[0];//from w ww.j av a2 s . c o m if (!path.endsWith("/")) { path = path + "/"; } } stopAttributes.add("http://www.w3.org/1999/02/22-rdf-syntax-ns#type"); stopAttributes.add("http://www.w3.org/2002/07/owl#sameAs"); stopAttributes.add("http://dbpedia.org/ontology/wikiPageRevisionID"); stopAttributes.add("http://dbpedia.org/ontology/wikiPageID"); stopAttributes.add("http://purl.org/dc/elements/1.1/description"); stopAttributes.add("http://dbpedia.org/ontology/thumbnail"); stopAttributes.add("http://dbpedia.org/ontology/type"); try (ObjectInputStream ois = new ObjectInputStream(new FileInputStream(path + "counts.bin"))) { categories = (HashSet<String>) ois.readObject(); attributes = (HashSet<String>) ois.readObject(); categoryCount = (HashMap<String, Integer>) ois.readObject(); attributeCount = (HashMap<String, Integer>) ois.readObject(); categoryAttributeCount = (HashMap<String, HashMap<String, Integer>>) ois.readObject(); attributeCategoryCount = (HashMap<String, HashMap<String, Integer>>) ois.readObject(); } System.out.println(categories.size() + " categories found"); System.out.println(attributes.size() + " attributes found"); n = 0; for (Map.Entry<String, Integer> e : categoryCount.entrySet()) { n += e.getValue(); } System.out.println(n); HashMap<String, ArrayList<Pair>> sortedCategoryAttributes = new HashMap<>(); for (String category : categories) { //System.out.println(category); //System.out.println("-----------"); ArrayList<Pair> attributesRank = new ArrayList<Pair>(); Integer c = categoryCount.get(category); if (c == null || c == 0) { continue; } HashMap<String, Integer> thisCategoryAttributeCount = categoryAttributeCount.get(category); for (Map.Entry<String, Integer> e : thisCategoryAttributeCount.entrySet()) { attributesRank.add(new Pair(e.getKey(), 1.0 * e.getValue() / c)); } Collections.sort(attributesRank); for (Pair p : attributesRank) { //System.out.println("A:" + p.getS() + "\t" + p.getP()); } //System.out.println("==============================="); sortedCategoryAttributes.put(category, attributesRank); } for (String attribute : attributes) { //System.out.println(attribute); //System.out.println("-----------"); ArrayList<Pair> categoriesRank = new ArrayList<>(); Integer a = attributeCount.get(attribute); if (a == null || a == 0) { continue; } HashMap<String, Integer> thisAttributeCategoryCount = attributeCategoryCount.get(attribute); for (Map.Entry<String, Integer> e : thisAttributeCategoryCount.entrySet()) { categoriesRank.add(new Pair(e.getKey(), 1.0 * e.getValue() / a)); } Collections.sort(categoriesRank); for (Pair p : categoriesRank) { //System.out.println("C:" + p.getS() + "\t" + p.getP()); } //System.out.println("==============================="); } HashMap<Integer, Integer> histogram = new HashMap<>(); histogram.put(0, 0); histogram.put(1, 0); histogram.put(2, 0); histogram.put(Integer.MAX_VALUE, 0); int nTest = 0; if (args != null && args.length > 0) { path = args[0]; if (!path.endsWith("/")) { path = path + "/"; } } for (File f : new File(path).listFiles()) { if (f.isFile() && f.getName().endsWith(".csv")) { String category = f.getName().replaceFirst("\\.csv", ""); System.out.println("Category: " + category); ArrayList<HashSet<String>> entities = extractEntities(f, 2); for (HashSet<String> attributesOfThisEntity : entities) { nTest++; ArrayList<String> rankedCategories = rankedCategories(attributesOfThisEntity); boolean found = false; for (int i = 0; i < rankedCategories.size() && !found; i++) { if (rankedCategories.get(i).equals(category)) { Integer count = histogram.get(i); if (count == null) { histogram.put(i, 1); } else { histogram.put(i, count + 1); } found = true; } } if (!found) { histogram.put(Integer.MAX_VALUE, histogram.get(Integer.MAX_VALUE) + 1); } } System.out.println("Tested entities: " + nTest); System.out.println("1: " + histogram.get(0)); System.out.println("2: " + histogram.get(1)); System.out.println("3: " + histogram.get(2)); System.out.println("+3: " + (nTest - histogram.get(2) - histogram.get(1) - histogram.get(0) - histogram.get(Integer.MAX_VALUE))); System.out.println("NF: " + histogram.get(Integer.MAX_VALUE)); } } }
From source file:com.artistech.tuio.mouse.ZeroMqMouse.java
/** * Main entry point for ZeroMQ integration. * * @param args//from w ww . j av a2s . com * @throws AWTException * @throws java.io.IOException */ public static void main(String[] args) throws AWTException, java.io.IOException { //read off the TUIO port from the command line String zeromq_port; Options options = new Options(); options.addOption("z", "zeromq-port", true, "ZeroMQ Server:Port to subscribe to. (-z localhost:5565)"); options.addOption("h", "help", false, "Show this message."); HelpFormatter formatter = new HelpFormatter(); try { CommandLineParser parser = new org.apache.commons.cli.BasicParser(); CommandLine cmd = parser.parse(options, args); if (cmd.hasOption("help")) { formatter.printHelp("tuio-mouse-driver", options); return; } else { if (cmd.hasOption("z") || cmd.hasOption("zeromq-port")) { zeromq_port = cmd.getOptionValue("z"); } else { System.err.println("The zeromq-port value must be specified."); formatter.printHelp("tuio-mouse-driver", options); return; } } } catch (ParseException ex) { System.err.println("Error Processing Command Options:"); formatter.printHelp("tuio-mouse-driver", options); return; } //load conversion services ServiceLoader<ProtoConverter> services = ServiceLoader.load(ProtoConverter.class); //create zeromq context ZMQ.Context context = ZMQ.context(1); // Connect our subscriber socket ZMQ.Socket subscriber = context.socket(ZMQ.SUB); subscriber.setIdentity(ZeroMqMouse.class.getName().getBytes()); //this could change I guess so we can get different data subscrptions. subscriber.subscribe("TuioCursor".getBytes()); // subscriber.subscribe("TuioTime".getBytes()); subscriber.connect("tcp://" + zeromq_port); System.out.println("Subscribed to " + zeromq_port + " for ZeroMQ messages."); // Get updates, expect random Ctrl-C death String msg = ""; MouseDriver md = new MouseDriver(); while (!msg.equalsIgnoreCase("END")) { boolean success = false; byte[] recv = subscriber.recv(); com.google.protobuf.GeneratedMessage message = null; TuioPoint pt = null; String type = recv.length > 0 ? new String(recv) : ""; recv = subscriber.recv(); switch (type) { case "TuioCursor.PROTOBUF": try { //it is a cursor? message = com.artistech.protobuf.TuioProtos.Cursor.parseFrom(recv); success = true; } catch (Exception ex) { } break; case "TuioTime.PROTOBUF": // try { // //it is a cursor? // message = com.artistech.protobuf.TuioProtos.Time.parseFrom(recv); // success = true; // } catch (Exception ex) { // } break; case "TuioObject.PROTOBUF": try { //it is a cursor? message = com.artistech.protobuf.TuioProtos.Object.parseFrom(recv); success = true; } catch (Exception ex) { } break; case "TuioBlob.PROTOBUF": try { //it is a cursor? message = com.artistech.protobuf.TuioProtos.Blob.parseFrom(recv); success = true; } catch (Exception ex) { } break; case "TuioCursor.JSON": try { //it is a cursor? pt = mapper.readValue(recv, TUIO.TuioCursor.class); success = true; } catch (Exception ex) { } break; case "TuioTime.JSON": // try { // //it is a cursor? // pt = mapper.readValue(recv, TUIO.TuioTime.class); // success = true; // } catch (Exception ex) { // } break; case "TuioObject.JSON": try { //it is a cursor? pt = mapper.readValue(recv, TUIO.TuioObject.class); success = true; } catch (Exception ex) { } break; case "TuioBlob.JSON": try { //it is a cursor? pt = mapper.readValue(recv, TUIO.TuioBlob.class); success = true; } catch (Exception ex) { } break; case "TuioTime.OBJECT": break; case "TuioCursor.OBJECT": case "TuioObject.OBJECT": case "TuioBlob.OBJECT": try { //Try reading the data as a serialized Java object: try (ByteArrayInputStream bis = new ByteArrayInputStream(recv)) { //Try reading the data as a serialized Java object: ObjectInput in = new ObjectInputStream(bis); Object o = in.readObject(); //if it is of type Point (Cursor, Object, Blob), process: if (TuioPoint.class.isAssignableFrom(o.getClass())) { pt = (TuioPoint) o; process(pt, md); } success = true; } } catch (java.io.IOException | ClassNotFoundException ex) { } finally { } break; default: success = false; break; } if (message != null && success) { //ok, so we have a message that is not null, so it was protobuf: Object o = null; //look for a converter that will suppor this objec type and convert: for (ProtoConverter converter : services) { if (converter.supportsConversion(message)) { o = converter.convertFromProtobuf(message); break; } } //if the type is of type Point (Cursor, Blob, Object), process: if (o != null && TuioPoint.class.isAssignableFrom(o.getClass())) { pt = (TuioPoint) o; } } if (pt != null) { process(pt, md); } } }
From source file:com.frostvoid.trekwar.server.TrekwarServer.java
public static void main(String[] args) { // load language try {//from www. j ava2 s. c om lang = new Language(Language.ENGLISH); } catch (IOException ioe) { System.err.println("FATAL ERROR: Unable to load language file!"); System.exit(1); } System.out.println(lang.get("trekwar_server") + " " + VERSION); System.out.println("==============================================".substring(0, lang.get("trekwar_server").length() + 1 + VERSION.length())); // Handle parameters Options options = new Options(); options.addOption(OptionBuilder.withArgName("file").withLongOpt("galaxy").hasArg() .withDescription("the galaxy file to load").create("g")); //"g", "galaxy", true, "the galaxy file to load"); options.addOption(OptionBuilder.withArgName("port number").withLongOpt("port").hasArg() .withDescription("the port number to bind to (default 8472)").create("p")); options.addOption(OptionBuilder.withArgName("number").withLongOpt("save-interval").hasArg() .withDescription("how often (in turns) to save the galaxy to disk (default: 5)").create("s")); options.addOption(OptionBuilder.withArgName("log level").withLongOpt("log").hasArg() .withDescription("sets the log level: ALL, FINEST, FINER, FINE, CONFIG, INFO, WARNING, SEVERE, OFF") .create("l")); options.addOption("h", "help", false, "prints this help message"); CommandLineParser cliParser = new BasicParser(); try { CommandLine cmd = cliParser.parse(options, args); String portStr = cmd.getOptionValue("p"); String galaxyFileStr = cmd.getOptionValue("g"); String saveIntervalStr = cmd.getOptionValue("s"); String logLevelStr = cmd.getOptionValue("l"); if (cmd.hasOption("h")) { HelpFormatter help = new HelpFormatter(); help.printHelp("TrekwarServer", options); System.exit(0); } if (cmd.hasOption("g") && galaxyFileStr != null) { galaxyFileName = galaxyFileStr; } else { throw new ParseException("galaxy file not specified"); } if (cmd.hasOption("p") && portStr != null) { port = Integer.parseInt(portStr); if (port < 1 || port > 65535) { throw new NumberFormatException(lang.get("port_number_out_of_range")); } } else { port = 8472; } if (cmd.hasOption("s") && saveIntervalStr != null) { saveInterval = Integer.parseInt(saveIntervalStr); if (saveInterval < 1 || saveInterval > 100) { throw new NumberFormatException("Save Interval out of range (1-100)"); } } else { saveInterval = 5; } if (cmd.hasOption("l") && logLevelStr != null) { if (logLevelStr.equalsIgnoreCase("finest")) { LOG.setLevel(Level.FINEST); } else if (logLevelStr.equalsIgnoreCase("finer")) { LOG.setLevel(Level.FINER); } else if (logLevelStr.equalsIgnoreCase("fine")) { LOG.setLevel(Level.FINE); } else if (logLevelStr.equalsIgnoreCase("config")) { LOG.setLevel(Level.CONFIG); } else if (logLevelStr.equalsIgnoreCase("info")) { LOG.setLevel(Level.INFO); } else if (logLevelStr.equalsIgnoreCase("warning")) { LOG.setLevel(Level.WARNING); } else if (logLevelStr.equalsIgnoreCase("severe")) { LOG.setLevel(Level.SEVERE); } else if (logLevelStr.equalsIgnoreCase("off")) { LOG.setLevel(Level.OFF); } else if (logLevelStr.equalsIgnoreCase("all")) { LOG.setLevel(Level.ALL); } else { System.err.println("ERROR: invalid log level: " + logLevelStr); System.err.println("Run again with -h flag to see valid log level values"); System.exit(1); } } else { LOG.setLevel(Level.INFO); } // INIT LOGGING try { LOG.setUseParentHandlers(false); initLogging(); } catch (IOException ex) { System.err.println("Unable to initialize logging to file"); System.err.println(ex); System.exit(1); } } catch (Exception ex) { System.err.println("ERROR: " + ex.getMessage()); System.err.println("use -h for help"); System.exit(1); } LOG.log(Level.INFO, "Trekwar2 server " + VERSION + " starting up"); // LOAD GALAXY File galaxyFile = new File(galaxyFileName); if (galaxyFile.exists()) { try { long timer = System.currentTimeMillis(); LOG.log(Level.INFO, "Loading galaxy file {0}", galaxyFileName); ObjectInputStream ois = new ObjectInputStream(new FileInputStream(galaxyFile)); galaxy = (Galaxy) ois.readObject(); timer = System.currentTimeMillis() - timer; LOG.log(Level.INFO, "Galaxy file loaded in {0} ms", timer); ois.close(); } catch (IOException ioe) { LOG.log(Level.SEVERE, "IO error while trying to load galaxy file", ioe); } catch (ClassNotFoundException cnfe) { LOG.log(Level.SEVERE, "Unable to find class while loading galaxy", cnfe); } } else { System.err.println("Error: file " + galaxyFileName + " not found"); System.exit(1); } // if turn == 0 (start of game), execute first turn to update fog of war. if (galaxy.getCurrentTurn() == 0) { TurnExecutor.executeTurn(galaxy); } LOG.log(Level.INFO, "Current turn : {0}", galaxy.getCurrentTurn()); LOG.log(Level.INFO, "Turn speed : {0} seconds", galaxy.getTurnSpeed() / 1000); LOG.log(Level.INFO, "Save Interval : {0}", saveInterval); LOG.log(Level.INFO, "Users / max : {0} / {1}", new Object[] { galaxy.getUserCount(), galaxy.getMaxUsers() }); // START SERVER try { server = new ServerSocket(port); LOG.log(Level.INFO, "Server listening on port {0}", port); } catch (BindException be) { LOG.log(Level.SEVERE, "Error: Unable to bind to port {0}", port); System.err.println(be); System.exit(1); } catch (IOException ioe) { LOG.log(Level.SEVERE, "Error: IO error while binding to port {0}", port); System.err.println(ioe); System.exit(1); } galaxy.startup(); Thread timerThread = new Thread(new Runnable() { @Override @SuppressWarnings("SleepWhileInLoop") public void run() { while (true) { try { Thread.sleep(1000); // && galaxy.getLoggedInUsers().size() > 0 will make server pause when nobody is logged in (TESTING) if (System.currentTimeMillis() > galaxy.nextTurnDate) { StringBuffer loggedInUsers = new StringBuffer(); for (User u : galaxy.getLoggedInUsers()) { loggedInUsers.append(u.getUsername()).append(", "); } long time = TurnExecutor.executeTurn(galaxy); LOG.log(Level.INFO, "Turn {0} executed in {1} ms", new Object[] { galaxy.getCurrentTurn(), time }); LOG.log(Level.INFO, "Logged in users: " + loggedInUsers.toString()); LOG.log(Level.INFO, "===================================================================================="); if (galaxy.getCurrentTurn() % saveInterval == 0) { saveGalaxy(); } galaxy.lastTurnDate = System.currentTimeMillis(); galaxy.nextTurnDate = galaxy.lastTurnDate + galaxy.turnSpeed; } } catch (InterruptedException e) { LOG.log(Level.SEVERE, "Error in main server loop, interrupted", e); } } } }); timerThread.start(); // ACCEPT CONNECTIONS AND DELEGATE TO CLIENT SESSIONS while (true) { Socket clientConnection; try { clientConnection = server.accept(); ClientSession c = new ClientSession(clientConnection, galaxy); Thread t = new Thread(c); t.start(); } catch (IOException ex) { LOG.log(Level.SEVERE, "IO Exception while trying to handle incoming client connection", ex); } } }
From source file:act.installer.pubchem.PubchemSynonymFinder.java
public static void main(String[] args) throws Exception { org.apache.commons.cli.Options opts = new org.apache.commons.cli.Options(); for (Option.Builder b : OPTION_BUILDERS) { opts.addOption(b.build());/*from w w w . jav a 2 s .c o m*/ } CommandLine cl = null; try { CommandLineParser parser = new DefaultParser(); cl = parser.parse(opts, args); } catch (ParseException e) { System.err.format("Argument parsing failed: %s\n", e.getMessage()); HELP_FORMATTER.printHelp(PubchemSynonymFinder.class.getCanonicalName(), HELP_MESSAGE, opts, null, true); System.exit(1); } if (cl.hasOption("help")) { HELP_FORMATTER.printHelp(PubchemSynonymFinder.class.getCanonicalName(), HELP_MESSAGE, opts, null, true); return; } File rocksDBFile = new File(cl.getOptionValue(OPTION_INDEX_PATH)); if (!rocksDBFile.isDirectory()) { System.err.format("Index directory does not exist or is not a directory at '%s'", rocksDBFile.getAbsolutePath()); HELP_FORMATTER.printHelp(PubchemSynonymFinder.class.getCanonicalName(), HELP_MESSAGE, opts, null, true); System.exit(1); } List<String> compoundIds = null; if (cl.hasOption(OPTION_PUBCHEM_COMPOUND_ID)) { compoundIds = Collections.singletonList(cl.getOptionValue(OPTION_PUBCHEM_COMPOUND_ID)); } else if (cl.hasOption(OPTION_IDS_FILE)) { File idsFile = new File(cl.getOptionValue(OPTION_IDS_FILE)); if (!idsFile.exists()) { System.err.format("Cannot find Pubchem CIDs file at %s", idsFile.getAbsolutePath()); HELP_FORMATTER.printHelp(PubchemSynonymFinder.class.getCanonicalName(), HELP_MESSAGE, opts, null, true); System.exit(1); } compoundIds = getCIDsFromFile(idsFile); if (compoundIds.size() == 0) { System.err.format("Found zero Pubchem CIDs to process in file at '%s', exiting", idsFile.getAbsolutePath()); HELP_FORMATTER.printHelp(PubchemSynonymFinder.class.getCanonicalName(), HELP_MESSAGE, opts, null, true); System.exit(1); } } else { System.err.format("Must specify one of '%s' or '%s'; index is too big to print all synonyms.", OPTION_PUBCHEM_COMPOUND_ID, OPTION_IDS_FILE); HELP_FORMATTER.printHelp(PubchemSynonymFinder.class.getCanonicalName(), HELP_MESSAGE, opts, null, true); System.exit(1); } // Run a quick check to warn users of malformed ids. compoundIds.forEach(x -> { if (!PC_CID_PATTERN.matcher(x).matches()) { // Use matches() for complete matching. LOGGER.warn("Specified compound id does not match expected format: %s", x); } }); LOGGER.info("Opening DB and searching for %d Pubchem CIDs", compoundIds.size()); Pair<RocksDB, Map<PubchemTTLMerger.COLUMN_FAMILIES, ColumnFamilyHandle>> dbAndHandles = null; Map<String, PubchemSynonyms> results = new LinkedHashMap<>(compoundIds.size()); try { dbAndHandles = PubchemTTLMerger.openExistingRocksDB(rocksDBFile); RocksDB db = dbAndHandles.getLeft(); ColumnFamilyHandle cidToSynonymsCfh = dbAndHandles.getRight() .get(PubchemTTLMerger.COLUMN_FAMILIES.CID_TO_SYNONYMS); for (String cid : compoundIds) { PubchemSynonyms synonyms = null; byte[] val = db.get(cidToSynonymsCfh, cid.getBytes(UTF8)); if (val != null) { ObjectInputStream oi = new ObjectInputStream(new ByteArrayInputStream(val)); // We're relying on our use of a one-value-type per index model here so we can skip the instanceof check. synonyms = (PubchemSynonyms) oi.readObject(); } else { LOGGER.warn("No synonyms available for compound id '%s'", cid); } results.put(cid, synonyms); } } finally { if (dbAndHandles != null) { dbAndHandles.getLeft().close(); } } try (OutputStream outputStream = cl.hasOption(OPTION_OUTPUT) ? new FileOutputStream(cl.getOptionValue(OPTION_OUTPUT)) : System.out) { OBJECT_MAPPER.writerWithDefaultPrettyPrinter().writeValue(outputStream, results); new OutputStreamWriter(outputStream).append('\n'); } LOGGER.info("Done searching for Pubchem synonyms"); }
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./*www . j av a2 s . co m*/ * * @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 Object setObjectBytes(byte[] b) throws IOException, ClassNotFoundException { ByteArrayInputStream baos = new ByteArrayInputStream(b); ObjectInputStream oos = new ObjectInputStream(baos); oos.close();//ww w.j av a 2s. co m return oos.readObject(); }
From source file:Main.java
public static Object byteToObject(byte[] bytes) throws Exception { ObjectInputStream ois = null; try {/*from ww w . j a v a 2 s . c o m*/ ois = new ObjectInputStream(new ByteArrayInputStream(bytes)); return ois.readObject(); } finally { if (ois != null) ois.close(); } }
From source file:Main.java
private static Object readFromFile(String filename) throws Exception { ObjectInputStream ois = new ObjectInputStream(new FileInputStream(new File(filename))); Object object = ois.readObject(); ois.close();//from www.j a v a 2s . c o m return object; }
From source file:Main.java
public static Object deserializar(String path) throws Exception { FileInputStream inFile = new FileInputStream(path); ObjectInputStream d = new ObjectInputStream(inFile); Object o = d.readObject();//from www . ja v a2 s. c om d.close(); return o; }
From source file:Main.java
public static Object deserialize(byte[] array) throws Exception { //System.err.println("neser#"+new String(array)); ObjectInputStream rin = new ObjectInputStream(new ByteArrayInputStream(array)); Object obj = rin.readObject(); rin.close();/* ww w. j a va 2s. c o m*/ //System.err.println("neser##"+obj); return obj; }