List of usage examples for java.io ObjectInputStream ObjectInputStream
public ObjectInputStream(InputStream in) throws IOException
From source file:jade.content.onto.SerializableOntology.java
/** */// ww w. j a v a 2 s .com protected Object toObject(AbsObject abs, String lcType, Ontology globalOnto) throws UnknownSchemaException, UngroundedException, OntologyException { if (SERIALIZABLE.equals(abs.getTypeName())) { try { AbsPrimitive absValue = (AbsPrimitive) abs.getAbsObject(SERIALIZABLE_VALUE); String stringValue = absValue.getString(); byte[] value = Base64.decodeBase64(stringValue.getBytes("US-ASCII")); ObjectInput in = new ObjectInputStream(new ByteArrayInputStream(value)) { protected Class resolveClass(ObjectStreamClass v) throws IOException, ClassNotFoundException { if (myClassLoader != null) { // FIXME: Manage primitive class fields. Refactor with AgentMobilityService return Class.forName(v.getName(), true, myClassLoader); } else { return super.resolveClass(v); } } }; return in.readObject(); } catch (Throwable t) { throw new OntologyException("Error in object deserialization.", t); } } else { throw new OntologyException("Abs-object " + abs + " is not serializable"); } }
From source file:jhttpp2.Jhttpp2Launcher.java
@SuppressWarnings("unchecked") public void restoreSettings()// throws Exception { if (server.getServerProperties() == null) { log.warn("server propertie where not set will not save them"); return;//from ww w .j av a2 s . co m } try { // Restore the WildcardDioctionary and the URLActions with the // ObjectInputStream (settings.dat)... ObjectInputStream obj_in; File file = new File(DATA_FILE); if (!file.exists()) { if (!file.createNewFile() || !file.canWrite()) { log.warn("Can't create or write to file " + file.toString()); } else saveServerSettings(); } obj_in = new ObjectInputStream(new FileInputStream(file)); server.setWildcardDictionary((WildcardDictionary) obj_in.readObject()); server.setURLActions((List<OnURLAction>) obj_in.readObject()); obj_in.close(); } catch (IOException e) { log.warn("restoreSettings(): " + e.getMessage()); } catch (ClassNotFoundException e_class_not_found) { } }
From source file:com.parallax.server.blocklyprop.db.dao.impl.SessionDaoImpl.java
private void printSessionInfo(String action, SessionRecord session) { if (configuration.getBoolean("debug.session", false)) { try {//from w w w.java 2 s. c o m if (session == null || session.getAttributes() == null) { System.out.println(action + ": NO SESSION AVAILABLE"); } else { ByteArrayInputStream bis = new ByteArrayInputStream(session.getAttributes()); ObjectInput in = new ObjectInputStream(bis); HashMap attributes = (HashMap) in.readObject(); System.out.println(action + ": " + attributes); } } catch (IOException ex) { Logger.getLogger(SessionDaoImpl.class.getName()).log(Level.SEVERE, null, ex); } catch (ClassNotFoundException cnfe) { Logger.getLogger(SessionDaoImpl.class.getName()).log(Level.SEVERE, null, cnfe); } } }
From source file:ch.ethz.bsse.quasirecomb.model.hmm.EM.java
private void blackbox(Read[] reads, int N, int L, int K, int n) { Globals.getINSTANCE().setLOG(new StringBuilder()); Globals.getINSTANCE().setMAX_LLH(-1); Globals.getINSTANCE().setMIN_BIC(Double.MAX_VALUE); String pathOptimum = null;//from ww w. j a v a 2s .c o m if (K == 1 || Globals.getINSTANCE().isFORCE_NO_RECOMB()) { Globals.getINSTANCE().setNO_RECOMB(true); } else { Globals.getINSTANCE().setNO_RECOMB(false); } if (Globals.getINSTANCE().getOPTIMUM() == null) { double maxLLH = Double.NEGATIVE_INFINITY; bics = new Double[Globals.getINSTANCE().getREPEATS()]; double[] bics_local = new double[Globals.getINSTANCE().getREPEATS()]; for (int i = 0; i < Globals.getINSTANCE().getREPEATS(); i++) { SingleEM sem = new SingleEM(N, K, L, n, reads, Globals.getINSTANCE().getDELTA_LLH(), i); bics_local[i] = sem.getOptimalResult().getBIC(); bics[i] = sem.getOptimalResult().getBIC(); this.maxBIC = Math.max(this.maxBIC, sem.getOptimalResult().getBIC()); if (sem.getLoglikelihood() > maxLLH) { maxLLH = sem.getLoglikelihood(); pathOptimum = sem.getOptimumPath(); } } medianBIC = new Median().evaluate(bics_local); lowerBoundBIC = medianBIC - new StandardDeviation().evaluate(bics_local) * Math.sqrt(1 + 1d / bics_local.length); } else { pathOptimum = Globals.getINSTANCE().getOPTIMUM(); } if (Globals.getINSTANCE().isMODELSELECTION()) { try { FileInputStream fis = new FileInputStream(pathOptimum); try (ObjectInputStream in = new ObjectInputStream(fis)) { or = (OptimalResult) in.readObject(); } } catch (IOException | ClassNotFoundException ex) { System.err.println(ex); } StatusUpdate.getINSTANCE().printBIC(K, (int) or.getBIC()); } else { try { FileInputStream fis = new FileInputStream(pathOptimum); try (ObjectInputStream in = new ObjectInputStream(fis)) { or = (OptimalResult) in.readObject(); } } catch (IOException | ClassNotFoundException ex) { System.err.println(ex); } StatusUpdate.getINSTANCE().printBIC(K, (int) or.getBIC()); System.out.print("\n"); if (!Globals.getINSTANCE().isSUBSAMPLE()) { // Globals.getINSTANCE().setREFINEMENT(true); if (!Globals.getINSTANCE().isANNEALING()) { SingleEM bestEM = new SingleEM(or, Globals.getINSTANCE().getDELTA_REFINE_LLH(), reads); this.or = bestEM.getOptimalResult(); } StatusUpdate.getINSTANCE().printBIC(K, 100, (int) this.or.getBIC()); if (Globals.getINSTANCE().isLOGGING()) { Utils.saveFile(Globals.getINSTANCE().getSAVEPATH() + "support" + File.separator + "log_K" + K, Globals.getINSTANCE().getLOG().toString()); } } } }
From source file:com.conwet.silbops.model.AdvertiseTest.java
@Test public void shouldExternalize() throws Exception { ByteArrayOutputStream baos = new ByteArrayOutputStream(); ObjectOutput output = new ObjectOutputStream(baos); output.writeObject(advertise);// w w w. j av a 2s . co m output.close(); ObjectInput input = new ObjectInputStream(new ByteArrayInputStream(baos.toByteArray())); assertThat((Advertise) input.readObject()).isEqualTo(advertise); }
From source file:com.projity.exchange.LocalFileImporter.java
public static Job getImportFileJob(final FileImporter importer) { final Job job = new Job(importer.getJobQueue(), "importFile", //$NON-NLS-1$ Messages.getString("LocalFileImporter.Importing"), true); //$NON-NLS-1$ job.addRunnable(new JobRunnable("Import", 1.0f) { //$NON-NLS-1$ public Object run() throws Exception { DataUtil serializer = new DataUtil(); log.debug("Loading : " + new File(importer.getFileName()).getCanonicalPath()); long t1 = System.currentTimeMillis(); ObjectInputStream in = new ObjectInputStream(new FileInputStream(importer.getFileName())); Object obj = in.readObject(); if (obj instanceof String) obj = in.readObject(); //check version in the future DocumentData projectData = (DocumentData) obj; projectData.setMaster(true); projectData.setLocal(true);/*w ww. jav a 2 s. c o m*/ long t2 = System.currentTimeMillis(); log.debug("Loading...Done in " + (t2 - t1) + " ms"); t1 = System.currentTimeMillis(); // project=serializer.deserializeProject(projectData,false,true,resourceMap); importer.setProject(serializer.deserializeLocalDocument(projectData)); t2 = System.currentTimeMillis(); log.debug("Deserializing...Done in " + (t2 - t1) + " ms"); setProgress(1.0f); return null; } }); return job; }
From source file:org.jfree.chart.demo.ChartPanelSerializationTest.java
/** * A demonstration application showing how to create a simple time series chart. This * example uses monthly data.//from w w w . ja v a2s. com * * @param title the frame title. */ public ChartPanelSerializationTest(final String title) { super(title); final XYDataset dataset = createDataset(); final JFreeChart chart = createChart(dataset); final ChartPanel chartPanel1 = new ChartPanel(chart); chartPanel1.setPreferredSize(new java.awt.Dimension(500, 270)); chartPanel1.setMouseZoomable(true, false); ChartPanel chartPanel2 = null; try { ByteArrayOutputStream buffer = new ByteArrayOutputStream(); ObjectOutput out = new ObjectOutputStream(buffer); out.writeObject(chartPanel1); out.close(); ObjectInput in = new ObjectInputStream(new ByteArrayInputStream(buffer.toByteArray())); chartPanel2 = (ChartPanel) in.readObject(); in.close(); } catch (Exception e) { e.printStackTrace(); } setContentPane(chartPanel2); }
From source file:org.jfree.chart.demo.SerializationTest1.java
/** * Constructs a new demonstration application. * * @param title the frame title.// w w w . j av a2s. c o m */ public SerializationTest1(final String title) { super(title); this.series = new TimeSeries("Random Data", Millisecond.class); TimeSeriesCollection dataset = new TimeSeriesCollection(this.series); JFreeChart chart = createChart(dataset); // SERIALIZE - DESERIALIZE for testing purposes JFreeChart deserializedChart = null; try { final ByteArrayOutputStream buffer = new ByteArrayOutputStream(); final ObjectOutput out = new ObjectOutputStream(buffer); out.writeObject(chart); out.close(); chart = null; dataset = null; this.series = null; System.gc(); final ObjectInput in = new ObjectInputStream(new ByteArrayInputStream(buffer.toByteArray())); deserializedChart = (JFreeChart) in.readObject(); in.close(); } catch (Exception e) { e.printStackTrace(); } final TimeSeriesCollection c = (TimeSeriesCollection) deserializedChart.getXYPlot().getDataset(); this.series = c.getSeries(0); // FINISHED TEST final ChartPanel chartPanel = new ChartPanel(deserializedChart); final JButton button = new JButton("Add New Data Item"); button.setActionCommand("ADD_DATA"); button.addActionListener(this); final JPanel content = new JPanel(new BorderLayout()); content.add(chartPanel); content.add(button, BorderLayout.SOUTH); chartPanel.setPreferredSize(new java.awt.Dimension(500, 270)); setContentPane(content); }
From source file:org.nebulaframework.util.io.IOSupport.java
/** * Deserializes an object instance from the given byte[] * of serial data./*from w w w. j a v a2 s. c o m*/ * * @param bytes Byte[] containing serialized data * * @return Deserialized object * * @throws IOException if thrown during serialization */ @SuppressWarnings("unchecked") // Ignore type casting Warnings public static <T extends Serializable> T deserializeFromBytes(byte[] bytes) throws IOException, ClassNotFoundException { Assert.notNull(bytes); ObjectInputStream ois = new ObjectInputStream(new ByteArrayInputStream(bytes)); return (T) ois.readObject(); }
From source file:com.dragome.callbackevictor.serverside.utils.ReflectionUtils.java
public static Object cast(Object o) throws IOException, ClassNotFoundException { final ByteArrayOutputStream buffer = new ByteArrayOutputStream(); final ObjectOutputStream oos = new ObjectOutputStream(buffer); oos.writeObject(o);//from w w w . j a va2 s . co m oos.flush(); final ObjectInputStream ois = new ObjectInputStream(new ByteArrayInputStream(buffer.toByteArray())); return ois.readObject(); }