List of usage examples for java.io ObjectInput readObject
public Object readObject() throws ClassNotFoundException, IOException;
From source file:com.github.steveash.jg2p.align.ProbTable.java
@Override public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { this.xyProb = (Table<String, String, Double>) in.readObject(); }
From source file:org.jfree.chart.demo.SerializationTest1.java
/** * Constructs a new demonstration application. * * @param title the frame title.//from ww w . j a v a2 s. c om */ 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.apache.stratos.mock.iaas.persistence.RegistryManager.java
/** * Deserialize a byte array and retrieve the object. * * @param bytes bytes to be deserialized * @return the deserialized {@link Object} * @throws Exception if the deserialization is failed. *//* w w w .j a v a 2s.c om*/ private Object deserializeFromByteArray(byte[] bytes) throws Exception { ByteArrayInputStream bis = new ByteArrayInputStream(bytes); ObjectInput in = null; try { in = new ObjectInputStream(bis); return in.readObject(); } finally { bis.close(); if (in != null) { in.close(); } } }
From source file:org.jaqpot.algorithms.resource.Standarization.java
@POST @Path("prediction") public Response prediction(PredictionRequest request) { try {/*from w w w. j a v a 2 s . co m*/ if (request.getDataset().getDataEntry().isEmpty() || request.getDataset().getDataEntry().get(0).getValues().isEmpty()) { return Response.status(Response.Status.BAD_REQUEST) .entity("Dataset is empty. Cannot make predictions on empty dataset.").build(); } List<String> features = request.getDataset().getDataEntry().stream().findFirst().get().getValues() .keySet().stream().collect(Collectors.toList()); String base64Model = (String) request.getRawModel(); byte[] modelBytes = Base64.getDecoder().decode(base64Model); ByteArrayInputStream bais = new ByteArrayInputStream(modelBytes); ObjectInput in = new ObjectInputStream(bais); ScalingModel model = (ScalingModel) in.readObject(); in.close(); bais.close(); List<LinkedHashMap<String, Object>> predictions = new ArrayList<>(); for (DataEntry dataEntry : request.getDataset().getDataEntry()) { LinkedHashMap<String, Object> data = new LinkedHashMap<>(); for (String feature : features) { Double stdev = model.getMaxValues().get(feature); Double mean = model.getMinValues().get(feature); Double value = Double.parseDouble(dataEntry.getValues().get(feature).toString()); if (stdev != null && stdev != 0.0 && mean != null) { value = (value - mean) / stdev; } else { value = 1.0; } data.put("Standarized " + feature, value); } predictions.add(data); } PredictionResponse response = new PredictionResponse(); response.setPredictions(predictions); return Response.ok(response).build(); } catch (Exception ex) { LOG.log(Level.SEVERE, null, ex); return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(ex.getMessage()).build(); } }
From source file:org.jfree.data.xy.junit.MatrixSeriesCollectionTest.java
/** * Serialize an instance, restore it, and check for equality. *//*from www .j a v a 2 s . co m*/ public void testSerialization() { MatrixSeries s1 = new MatrixSeries("Series", 2, 3); s1.update(0, 0, 1.1); MatrixSeriesCollection c1 = new MatrixSeriesCollection(); c1.addSeries(s1); MatrixSeriesCollection c2 = null; try { ByteArrayOutputStream buffer = new ByteArrayOutputStream(); ObjectOutput out = new ObjectOutputStream(buffer); out.writeObject(c1); out.close(); ObjectInput in = new ObjectInputStream(new ByteArrayInputStream(buffer.toByteArray())); c2 = (MatrixSeriesCollection) in.readObject(); in.close(); } catch (Exception e) { e.printStackTrace(); } assertEquals(c1, c2); }
From source file:com.splicemachine.derby.stream.spark.SparkExportDataSetWriter.java
@SuppressWarnings("unchecked") public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { directory = in.readUTF();/* ww w. j av a2s . c o m*/ exportFunction = (SpliceFunction2) in.readObject(); rdd = (JavaRDD) in.readObject(); }
From source file:org.jfree.data.xy.junit.XYBarDatasetTest.java
/** * Serialize an instance, restore it, and check for equality. *///from w ww .j a v a 2s. c o m public void testSerialization() { DefaultXYDataset d1 = new DefaultXYDataset(); double[] x1 = new double[] { 1.0, 2.0, 3.0 }; double[] y1 = new double[] { 4.0, 5.0, 6.0 }; double[][] data1 = new double[][] { x1, y1 }; d1.addSeries("S1", data1); XYBarDataset bd1 = new XYBarDataset(d1, 5.0); XYBarDataset bd2 = null; try { ByteArrayOutputStream buffer = new ByteArrayOutputStream(); ObjectOutput out = new ObjectOutputStream(buffer); out.writeObject(bd1); out.close(); ObjectInput in = new ObjectInputStream(new ByteArrayInputStream(buffer.toByteArray())); bd2 = (XYBarDataset) in.readObject(); in.close(); } catch (Exception e) { e.printStackTrace(); } assertEquals(bd1, bd2); }
From source file:com.aol.advertising.qiao.util.cache.PersistentValueWrapper.java
@Override public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { super.readExternal(in); this.expirationTime = in.readLong(); this.key = (K) in.readObject(); //System.out.println("<readExternal> " + toString()); //TODO: remove }
From source file:org.jaqpot.algorithm.resource.Standarization.java
@POST @Path("prediction") public Response prediction(PredictionRequest request) { try {/*from www .ja v a 2s. co m*/ if (request.getDataset().getDataEntry().isEmpty() || request.getDataset().getDataEntry().get(0).getValues().isEmpty()) { return Response .status(Response.Status.BAD_REQUEST).entity(ErrorReportFactory .badRequest("Dataset is empty", "Cannot make predictions on empty dataset")) .build(); } List<String> features = request.getDataset().getDataEntry().stream().findFirst().get().getValues() .keySet().stream().collect(Collectors.toList()); String base64Model = (String) request.getRawModel(); byte[] modelBytes = Base64.getDecoder().decode(base64Model); ByteArrayInputStream bais = new ByteArrayInputStream(modelBytes); ObjectInput in = new ObjectInputStream(bais); ScalingModel model = (ScalingModel) in.readObject(); in.close(); bais.close(); List<LinkedHashMap<String, Object>> predictions = new ArrayList<>(); for (DataEntry dataEntry : request.getDataset().getDataEntry()) { LinkedHashMap<String, Object> data = new LinkedHashMap<>(); for (String feature : features) { Double stdev = model.getMaxValues().get(feature); Double mean = model.getMinValues().get(feature); Double value = Double.parseDouble(dataEntry.getValues().get(feature).toString()); if (stdev != null && stdev != 0.0 && mean != null) { value = (value - mean) / stdev; } else { value = 1.0; } data.put("Standarized " + feature, value); } predictions.add(data); } PredictionResponse response = new PredictionResponse(); response.setPredictions(predictions); return Response.ok(response).build(); } catch (Exception ex) { LOG.log(Level.SEVERE, null, ex); return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(ex.getMessage()).build(); } }
From source file:com.splicemachine.derby.stream.spark.SparkScanSetBuilder.java
@Override public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { super.readExternal(in); this.tableName = in.readUTF(); this.dsp = (SparkDataSetProcessor) in.readObject(); }