Java Code Examples for java.io.ObjectOutput.close()

The following are Jave code examples for showing how to use close() of the java.io.ObjectOutput class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
Example 1
Project: parabuild-ci   File: VectorTests.java   Source Code and License Vote up 6 votes
/**
 * Serialize an instance, restore it, and check for equality.
 */
public void testSerialization() {
    Vector v1 = new Vector(1.0, 2.0);
    Vector v2 = null;
    try {
        ByteArrayOutputStream buffer = new ByteArrayOutputStream();
        ObjectOutput out = new ObjectOutputStream(buffer);
        out.writeObject(v1);
        out.close();

        ObjectInput in = new ObjectInputStream(
                new ByteArrayInputStream(buffer.toByteArray()));
        v2 = (Vector) in.readObject();
        in.close();
    }
    catch (Exception e) {
        e.printStackTrace();
    }
    assertEquals(v1, v2);
}
 
Example 2
Project: parabuild-ci   File: DialPlotTests.java   Source Code and License Vote up 6 votes
/**
 * Serialize an instance, restore it, and check for equality.
 */
public void testSerialization() {
    DialPlot p1 = new DialPlot();
    DialPlot p2 = null;

    try {
        ByteArrayOutputStream buffer = new ByteArrayOutputStream();
        ObjectOutput out = new ObjectOutputStream(buffer);
        out.writeObject(p1);
        out.close();

        ObjectInput in = new ObjectInputStream(
                new ByteArrayInputStream(buffer.toByteArray()));
        p2 = (DialPlot) in.readObject();
        in.close();
    }
    catch (Exception e) {
        e.printStackTrace();
    }
    assertEquals(p1, p2);
}
 
Example 3
Project: jaer   File: HotPixelFilter.java   Source Code and License Vote up 6 votes
void storePrefs() {
	try {
		// Serialize to a byte array
		final ByteArrayOutputStream bos = new ByteArrayOutputStream();
		final ObjectOutput oos = new ObjectOutputStream(bos);
		final Object[] hps = this.toArray();
		oos.writeObject(hps);
		oos.close();
		// Get the bytes of the serialized object
		final byte[] buf = bos.toByteArray();
		getPrefs().putByteArray("HotPixelFilter.HotPixelSet", buf);
	}
	catch (final Exception e) {
		e.printStackTrace();
	}

}
 
Example 4
Project: parabuild-ci   File: VectorSeriesTests.java   Source Code and License Vote up 6 votes
/**
 * Serialize an instance, restore it, and check for equality.
 */
public void testSerialization() {
    VectorSeries s1 = new VectorSeries("s1");
    s1.add(1.0, 0.5, 1.5, 2.0);
    VectorSeries s2 = null;        
    try {
        ByteArrayOutputStream buffer = new ByteArrayOutputStream();
        ObjectOutput out = new ObjectOutputStream(buffer);
        out.writeObject(s1);
        out.close();

        ObjectInput in = new ObjectInputStream(
                new ByteArrayInputStream(buffer.toByteArray()));
        s2 = (VectorSeries) in.readObject();
        in.close();
    }
    catch (Exception e) {
        e.printStackTrace();
    }
    assertEquals(s1, s2);

}
 
Example 5
Project: jaer   File: AEViewer.java   Source Code and License Vote up 6 votes
private void putChipClassPrefs() {
    try {
        // Serialize to a byte array
        ByteArrayOutputStream bos = new ByteArrayOutputStream();
        ObjectOutput out = new ObjectOutputStream(bos);
        out.writeObject(chipClassNames);
        out.close();

        // Get the bytes of the serialized object
        byte[] buf = bos.toByteArray();
        prefs.putByteArray("chipClassNames", buf);
    } catch (IOException e) {
        e.printStackTrace();
    } catch (IllegalArgumentException e2) {
        log.warning("too many classes in Preferences, " + chipClassNames.size() + " class names");
    }
}
 
Example 6
Project: parabuild-ci   File: StandardDialFrameTests.java   Source Code and License Vote up 6 votes
/**
 * Serialize an instance, restore it, and check for equality.
 */
public void testSerialization() {
    StandardDialFrame f1 = new StandardDialFrame();
    StandardDialFrame f2 = null;

    try {
        ByteArrayOutputStream buffer = new ByteArrayOutputStream();
        ObjectOutput out = new ObjectOutputStream(buffer);
        out.writeObject(f1);
        out.close();

        ObjectInput in = new ObjectInputStream(
                new ByteArrayInputStream(buffer.toByteArray()));
        f2 = (StandardDialFrame) in.readObject();
        in.close();
    }
    catch (Exception e) {
        e.printStackTrace();
    }
    assertEquals(f1, f2);
}
 
Example 7
Project: jaer   File: NBFG256.java   Source Code and License Vote up 6 votes
private void putArray(int[] array, String key) {
    if ((array == null) || (key == null)) {
        log.warning("null array or key");
        return;
    }
    try {
        // Serialize to a byte array
        ByteArrayOutputStream bos = new ByteArrayOutputStream();
        ObjectOutput out = new ObjectOutputStream(bos);
        out.writeObject(array);
        out.close();

        // Get the bytes of the serialized object
        byte[] buf = bos.toByteArray();
        getPrefs().putByteArray(key, buf);
    } catch (Exception e) {
        log.warning(e.toString());
    }

}
 
Example 8
Project: parabuild-ci   File: SignalRendererTests.java   Source Code and License Vote up 6 votes
/**
 * Serialize an instance, restore it, and check for equality.
 */
public void testSerialization() {

    SignalRenderer r1 = new SignalRenderer();
    SignalRenderer r2 = null;

    try {
        ByteArrayOutputStream buffer = new ByteArrayOutputStream();
        ObjectOutput out = new ObjectOutputStream(buffer);
        out.writeObject(r1);
        out.close();

        ObjectInput in = new ObjectInputStream(new ByteArrayInputStream(buffer.toByteArray()));
        r2 = (SignalRenderer) in.readObject();
        in.close();
    }
    catch (Exception e) {
        System.out.println(e.toString());
    }
    assertEquals(r1, r2);

}
 
Example 9
Project: parabuild-ci   File: SymbolicAxisTests.java   Source Code and License Vote up 6 votes
/**
 * Serialize an instance, restore it, and check for equality.
 */
public void testSerialization() {

    String[] tickLabels = new String[] {"One", "Two", "Three"};
    SymbolicAxis a1 = new SymbolicAxis("Test Axis", tickLabels);
    SymbolicAxis a2 = null;

    try {
        ByteArrayOutputStream buffer = new ByteArrayOutputStream();
        ObjectOutput out = new ObjectOutputStream(buffer);
        out.writeObject(a1);
        out.close();

        ObjectInput in = new ObjectInputStream(new ByteArrayInputStream(buffer.toByteArray()));
        a2 = (SymbolicAxis) in.readObject();
        in.close();
    }
    catch (Exception e) {
        System.out.println(e.toString());
    }
    assertEquals(a1, a2);

}
 
Example 10
Project: parabuild-ci   File: StandardCategoryLabelGeneratorTests.java   Source Code and License Vote up 6 votes
/**
 * Serialize an instance, restore it, and check for equality.
 */
public void testSerialization() {

    StandardCategoryLabelGenerator g1 = new StandardCategoryLabelGenerator(
        "{2}", DateFormat.getInstance()
    );
    StandardCategoryLabelGenerator g2 = null;

    try {
        ByteArrayOutputStream buffer = new ByteArrayOutputStream();
        ObjectOutput out = new ObjectOutputStream(buffer);
        out.writeObject(g1);
        out.close();

        ObjectInput in = new ObjectInputStream(new ByteArrayInputStream(buffer.toByteArray()));
        g2 = (StandardCategoryLabelGenerator) in.readObject();
        in.close();
    }
    catch (Exception e) {
        System.out.println(e.toString());
    }
    assertEquals(g1, g2);

}
 
Example 11
Project: parabuild-ci   File: DialValueIndicatorTests.java   Source Code and License Vote up 6 votes
/**
 * Serialize an instance, restore it, and check for equality.
 */
public void testSerialization() {
    // test a default instance
    DialValueIndicator i1 = new DialValueIndicator(0, "Label");
    DialValueIndicator i2 = null;

    try {
        ByteArrayOutputStream buffer = new ByteArrayOutputStream();
        ObjectOutput out = new ObjectOutputStream(buffer);
        out.writeObject(i1);
        out.close();

        ObjectInput in = new ObjectInputStream(
                new ByteArrayInputStream(buffer.toByteArray()));
        i2 = (DialValueIndicator) in.readObject();
        in.close();
    }
    catch (Exception e) {
        e.printStackTrace();
    }
    assertEquals(i1, i2);
    
    // test a custom instance
}
 
Example 12
Project: parabuild-ci   File: StandardPieItemLabelGeneratorTests.java   Source Code and License Vote up 6 votes
/**
 * Serialize an instance, restore it, and check for equality.
 */
public void testSerialization() {

    StandardPieItemLabelGenerator g1 = new StandardPieItemLabelGenerator();
    StandardPieItemLabelGenerator g2 = null;

    try {
        ByteArrayOutputStream buffer = new ByteArrayOutputStream();
        ObjectOutput out = new ObjectOutputStream(buffer);
        out.writeObject(g1);
        out.close();

        ObjectInput in = new ObjectInputStream(new ByteArrayInputStream(buffer.toByteArray()));
        g2 = (StandardPieItemLabelGenerator) in.readObject();
        in.close();
    }
    catch (Exception e) {
        System.out.println(e.toString());
    }
    assertEquals(g1, g2);

}
 
Example 13
Project: parabuild-ci   File: IntervalCategoryLabelGeneratorTests.java   Source Code and License Vote up 6 votes
/**
 * Serialize an instance, restore it, and check for equality.
 */
public void testSerialization() {

    IntervalCategoryLabelGenerator g1
        = new IntervalCategoryLabelGenerator("{3} - {4}", DateFormat.getInstance());
    IntervalCategoryLabelGenerator g2 = null;

    try {
        ByteArrayOutputStream buffer = new ByteArrayOutputStream();
        ObjectOutput out = new ObjectOutputStream(buffer);
        out.writeObject(g1);
        out.close();

        ObjectInput in = new ObjectInputStream(new ByteArrayInputStream(buffer.toByteArray()));
        g2 = (IntervalCategoryLabelGenerator) in.readObject();
        in.close();
    }
    catch (Exception e) {
        System.out.println(e.toString());
    }
    assertEquals(g1, g2);

}
 
Example 14
Project: parabuild-ci   File: VectorSeriesCollectionTests.java   Source Code and License Vote up 6 votes
/**
 * Serialize an instance, restore it, and check for equality.
 */
public void testSerialization() {
    VectorSeries s1 = new VectorSeries("Series");
    s1.add(1.0, 1.1, 1.2, 1.3);
    VectorSeriesCollection c1 = new VectorSeriesCollection();
    c1.addSeries(s1);
    VectorSeriesCollection 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 = (VectorSeriesCollection) in.readObject();
        in.close();
    }
    catch (Exception e) {
        e.printStackTrace();
    }
    assertEquals(c1, c2);
}
 
Example 15
Project: android-training-2017   File: IOUtils.java   Source Code and License Vote up 5 votes
public static void close(ObjectOutput closeable) {
    if (closeable != null) {
        try {
            closeable.close();
        } catch (Exception e) {
            //can be ignored
            Log.e("IOUtils", e.getMessage());
        }
    }
}
 
Example 16
Project: VASSAL-src   File: IOUtils.java   Source Code and License Vote up 5 votes
/**
 * Close an {@link ObjectOutput} unconditionally. Equivalent to
 * calling <code>o.close()</code> when <code>o</code> is nonnull.
 * {@link IOException}s are swallowed, as there is generally
 * nothing that can be done about exceptions on closing.
 *
 * @param o a (possibly <code>null</code>) <code>ObjectOutput</code>
 */
public static void closeQuietly(ObjectOutput o) {
  if (o == null) return;

  try {
    o.close();
  }
  catch (IOException e) {
    // ignore
  }
}
 
Example 17
Project: openjdk-systemtest   File: TestLambdaSerialization.java   Source Code and License Vote up 5 votes
private byte[] writeObject(Object object) throws IOException {
	ByteArrayOutputStream baos = new ByteArrayOutputStream();
       ObjectOutput out = new ObjectOutputStream(baos);
	out.writeObject(object);
       out.close();
	return baos.toByteArray();
}
 
Example 18
Project: happylifeplat-tcc   File: JavaSerializer.java   Source Code and License Vote up 5 votes
@Override
public byte[] serialize(Object obj) throws TccException {
    try (ByteArrayOutputStream arrayOutputStream = new ByteArrayOutputStream()) {
        ObjectOutput objectOutput = new ObjectOutputStream(arrayOutputStream);
        objectOutput.writeObject(obj);
        objectOutput.flush();
        objectOutput.close();
        return arrayOutputStream.toByteArray();
    } catch (IOException e) {
        throw new TccException("JAVA serialize error " + e.getMessage());
    }
}
 
Example 19
Project: jaer   File: TargetLabeler.java   Source Code and License Vote up 5 votes
private void saveLocations(File f) {
        try {
            FileWriter writer = new FileWriter(f);
            writer.write(String.format("#!TargetLocations-2.0\n"));
            writer.write(String.format("# target locations\n"));
            writer.write(String.format("# written %s\n", new Date().toString()));
//            writer.write("# maxTargets=" + maxTargets+"\n");
            writer.write(String.format("# frameNumber timestamp x y targetTypeID width height\n"));
            for (Map.Entry<Integer, SimultaneouTargetLocations> entry : targetLocations.entrySet()) {
                for (TargetLocation l : entry.getValue()) {
                    if (l.location != null) {
                        writer.write(String.format("%d %d %d %d %d %d %d\n", l.frameNumber, l.timestamp, l.location.x, l.location.y, l.targetClassID, l.width, l.height));
                    } else {
                        writer.write(String.format("%d %d -1 -1 -1 -1 -1\n", l.frameNumber, l.timestamp));
                    }
                }
            }
            writer.close();
            log.info("wrote locations to file " + f.getAbsolutePath());
            if (f.getPath() != null) {
                mapDataFilenameToTargetFilename.put(lastDataFilename, f.getPath());
            }
            try {
                // Serialize to a byte array
                ByteArrayOutputStream bos = new ByteArrayOutputStream();
                ObjectOutput oos = new ObjectOutputStream(bos);
                oos.writeObject(mapDataFilenameToTargetFilename);
                oos.close();
                // Get the bytes of the serialized object
                byte[] buf = bos.toByteArray();
                getPrefs().putByteArray("TargetLabeler.hashmap", buf);
            } catch (Exception e) {
                e.printStackTrace();
            }
        } catch (IOException ex) {
            JOptionPane.showMessageDialog(glCanvas, ex.toString(), "Couldn't save locations", JOptionPane.WARNING_MESSAGE, null);
            return;
        }
    }
 
Example 20
Project: jaer   File: FilterChain.java   Source Code and License Vote up 5 votes
private void storePreferredFilterPreferences(ArrayList<String> newClassNames) throws IOException, BackingStoreException {
    log.info("storing preferred filters to preferences");
    // Serialize to a byte array
    ByteArrayOutputStream bos = new ByteArrayOutputStream();
    ObjectOutput out = new ObjectOutputStream(bos);
    out.writeObject(newClassNames);
    out.close();
    byte[] buf = bos.toByteArray();
    chip.getPrefs().putByteArray(prefsKey(), buf);
    chip.getPrefs().sync();
}