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

The following examples show how to use java.io.ObjectOutput#close() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: YIntervalRendererTests.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Serialize an instance, restore it, and check for equality.
 */
public void testSerialization() {

    YIntervalRenderer r1 = new YIntervalRenderer();
    YIntervalRenderer 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 = (YIntervalRenderer) in.readObject();
        in.close();
    }
    catch (Exception e) {
        e.printStackTrace();
    }
    assertEquals(r1, r2);

}
 
Example 2
Source File: Size2DTest.java    From ccu-historian with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Serialize an instance, restore it, and check for equality.
 */
public void testSerialization() {

    final Size2D s1 = new Size2D(3.0, 4.0);
    Size2D s2 = null;

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

        final ObjectInput in = new ObjectInputStream(new ByteArrayInputStream(buffer.toByteArray()));
        s2 = (Size2D) in.readObject();
        in.close();
    }
    catch (Exception e) {
        System.out.println(e.toString());
    }
    assertTrue(s1.equals(s2));

}
 
Example 3
Source File: UnitTypeTest.java    From ccu-historian with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Serialize an instance, restore it, and check for identity.
 */
public void testSerialization() {

    UnitType t1 = UnitType.ABSOLUTE;
    UnitType t2 = null;

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

        ObjectInput in = new ObjectInputStream(new ByteArrayInputStream(buffer.toByteArray()));
        t2 = (UnitType) in.readObject();
        in.close();
    }
    catch (Exception e) {
        System.out.println(e.toString());
    }
    assertTrue(t1 == t2); 

}
 
Example 4
Source File: XYCoordinateTests.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Serialize an instance, restore it, and check for equality.
 */
public void testSerialization() {
    XYCoordinate v1 = new XYCoordinate(1.0, 2.0);
    XYCoordinate 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 = (XYCoordinate) in.readObject();
        in.close();
    }
    catch (Exception e) {
        e.printStackTrace();
    }
    assertEquals(v1, v2);
}
 
Example 5
Source File: NormalDistributionFunction2DTests.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Serialize an instance, restore it, and check for equality.
 */
public void testSerialization() {
    NormalDistributionFunction2D f1 = new NormalDistributionFunction2D(1.0,
            2.0);
    NormalDistributionFunction2D 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 = (NormalDistributionFunction2D) in.readObject();
        in.close();
    }
    catch (Exception e) {
        e.printStackTrace();
    }
    assertEquals(f1, f2);
}
 
Example 6
Source File: SimpleHistogramDatasetTests.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Serialize an instance, restore it, and check for equality.
 */
public void testSerialization() {
    SimpleHistogramDataset d1 = new SimpleHistogramDataset("D1");
    SimpleHistogramDataset d2 = null;        
    try {
        ByteArrayOutputStream buffer = new ByteArrayOutputStream();
        ObjectOutput out = new ObjectOutputStream(buffer);
        out.writeObject(d1);
        out.close();
        ObjectInput in = new ObjectInputStream(
                new ByteArrayInputStream(buffer.toByteArray()));
        d2 = (SimpleHistogramDataset) in.readObject();
        in.close();
    }
    catch (Exception e) {
        e.printStackTrace();
    }
    assertEquals(d1, d2);
}
 
Example 7
Source File: GroupedStackedBarRendererTests.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Serialize an instance, restore it, and check for equality.
 */
public void testSerialization() {

    GroupedStackedBarRenderer r1 = new GroupedStackedBarRenderer();
    GroupedStackedBarRenderer 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 = (GroupedStackedBarRenderer) in.readObject();
        in.close();
    }
    catch (Exception e) {
        System.out.println(e.toString());
    }
    assertEquals(r1, r2);

}
 
Example 8
Source File: TextFragmentTest.java    From ccu-historian with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Serialize an instance, restore it, and check for equality.
 */
public void testSerialization() {

    final TextFragment tf1 = new TextFragment("Test");
    TextFragment tf2 = null;

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

        final ObjectInput in = new ObjectInputStream(new ByteArrayInputStream(buffer.toByteArray()));
        tf2 = (TextFragment) in.readObject();
        in.close();
    }
    catch (Exception e) {
        System.out.println(e.toString());
    }
    assertEquals(tf1, tf2);

}
 
Example 9
Source File: OHLCSeriesTests.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Serialize an instance, restore it, and check for equality.
 */
public void testSerialization() {

    OHLCSeries s1 = new OHLCSeries("s1");
    s1.add(new Year(2006), 2.0, 4.0, 1.0, 3.0);
    OHLCSeries 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 = (OHLCSeries) in.readObject();
        in.close();
    }
    catch (Exception e) {
        e.printStackTrace();
    }
    assertEquals(s1, s2);

}
 
Example 10
Source File: YIntervalTests.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Serialize an instance, restore it, and check for equality.
 */
public void testSerialization() {
    YInterval i1 = new YInterval(1.0, 0.5, 1.5);
    YInterval 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 = (YInterval) in.readObject();
        in.close();
    }
    catch (Exception e) {
        e.printStackTrace();
    }
    assertEquals(i1, i2);
}
 
Example 11
Source File: XYIntervalDataItemTests.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Serialize an instance, restore it, and check for equality.
 */
public void testSerialization() {
    XYIntervalDataItem item1 = new XYIntervalDataItem(1.0, 0.5, 1.5, 2.0,
            1.9, 2.1);
    XYIntervalDataItem item2 = null;
    try {
        ByteArrayOutputStream buffer = new ByteArrayOutputStream();
        ObjectOutput out = new ObjectOutputStream(buffer);
        out.writeObject(item1);
        out.close();

        ObjectInput in = new ObjectInputStream(
                new ByteArrayInputStream(buffer.toByteArray()));
        item2 = (XYIntervalDataItem) in.readObject();
        in.close();
    }
    catch (Exception e) {
        e.printStackTrace();
    }
    assertEquals(item1, item2);
}
 
Example 12
Source File: CategoryStepRendererTests.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Serialize an instance, restore it, and check for equality.
 */
public void testSerialization() {

    CategoryStepRenderer r1 = new CategoryStepRenderer();
    CategoryStepRenderer 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 = (CategoryStepRenderer) in.readObject();
        in.close();
    }
    catch (Exception e) {
        e.printStackTrace();
    }
    assertEquals(r1, r2);

}
 
Example 13
Source File: NarNode.java    From opennars with MIT License 5 votes vote down vote up
/**
 * Send Narsese that contains the optional mustContainTerm
 *
 * @param input
 * @param target
 * @throws IOException 
 */
public static void sendNarsese(String input, TargetNar target) throws IOException {
    ByteArrayOutputStream bStream = new ByteArrayOutputStream();
    ObjectOutput oo = new ObjectOutputStream(bStream); 
    oo.writeObject(input);
    oo.close();
    byte[] serializedMessage = bStream.toByteArray();
    boolean searchTerm = target.mustContainTerm != null;
    boolean containsFound = searchTerm && input.contains(target.mustContainTerm.toString());
    if(!searchTerm || containsFound) {
        DatagramPacket packet = new DatagramPacket(serializedMessage, serializedMessage.length, target.targetAddress, target.targetPort);
        target.sendSocket.send(packet);
        //System.out.println("narsese sent:" + input);
    }
}
 
Example 14
Source File: XYTaskDatasetTests.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Serialize an instance, restore it, and check for equality.
 */
public void testSerialization() {
    TaskSeries s1 = new TaskSeries("Series");
    s1.add(new Task("Task 1", new Date(0L), new Date(1L)));
    TaskSeriesCollection u1 = new TaskSeriesCollection();
    u1.add(s1);
    XYTaskDataset d1 = new XYTaskDataset(u1);
    XYTaskDataset d2 = null;
    try {
        ByteArrayOutputStream buffer = new ByteArrayOutputStream();
        ObjectOutput out = new ObjectOutputStream(buffer);
        out.writeObject(d1);
        out.close();

        ObjectInput in = new ObjectInputStream(
                new ByteArrayInputStream(buffer.toByteArray()));
        d2 = (XYTaskDataset) in.readObject();
        in.close();
    }
    catch (Exception e) {
        e.printStackTrace();
    }
    assertEquals(d1, d2);

    // basic check for independence
    s1.add(new Task("Task 2", new Date(10L), new Date(11L)));
    assertFalse(d1.equals(d2));
    TaskSeriesCollection u2 = d2.getTasks();
    TaskSeries s2 = u2.getSeries("Series");
    s2.add(new Task("Task 2", new Date(10L), new Date(11L)));
    assertTrue(d1.equals(d2));
}
 
Example 15
Source File: SosMetadataUpdate.java    From SensorWebClient with GNU General Public License v2.0 5 votes vote down vote up
protected static void cacheMetadata(File cache, String serviceUrl) throws Exception {
    OutputStream os = new FileOutputStream(cache);
    ObjectOutput serializer = new ObjectOutputStream(new BufferedOutputStream(os));
    try {
        serializer.writeObject(getSOSMetadata(serviceUrl));
    } finally {
        serializer.close();
        os.close();
    }
}
 
Example 16
Source File: DefaultKeyedValuesDatasetTests.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Serialize an instance, restore it, and check for equality.
 */
public void testSerialization() {

    DefaultKeyedValuesDataset d1 = new DefaultKeyedValuesDataset();
    d1.setValue("C1", new Double(234.2));
    d1.setValue("C2", null);
    d1.setValue("C3", new Double(345.9));
    d1.setValue("C4", new Double(452.7));

    KeyedValuesDataset d2 = null;

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

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

}
 
Example 17
Source File: MultipleXYSeriesLabelGeneratorTests.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Serialize an instance, restore it, and check for equality.
 */
public void testSerialization() {

    MultipleXYSeriesLabelGenerator g1 
            = new MultipleXYSeriesLabelGenerator();
    g1.addSeriesLabel(0, "Add0");
    g1.addSeriesLabel(0, "Add0b");
    g1.addSeriesLabel(1, "Add1");
    MultipleXYSeriesLabelGenerator 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 = (MultipleXYSeriesLabelGenerator) in.readObject();
        in.close();
    }
    catch (Exception e) {
        e.printStackTrace();
    }
    assertEquals(g1, g2);

}
 
Example 18
Source File: CompassPlotTests.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Serialize an instance, restore it, and check for equality.
 */
public void testSerialization() {

    CompassPlot p1 = new CompassPlot(null);
    p1.setRosePaint(new GradientPaint(1.0f, 2.0f, Color.red, 3.0f, 4.0f,
            Color.blue));
    p1.setRoseCenterPaint(new GradientPaint(4.0f, 3.0f, Color.red, 2.0f,
            1.0f, Color.green));
    p1.setRoseHighlightPaint(new GradientPaint(4.0f, 3.0f, Color.red, 2.0f,
            1.0f, Color.green));
    CompassPlot 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 = (CompassPlot) in.readObject();
        in.close();
    }
    catch (Exception e) {
        e.printStackTrace();
    }
    assertEquals(p1, p2);

}
 
Example 19
Source File: KeyedObjectsTests.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Serialize an instance, restore it, and check for equality.
 */
public void testSerialization() {

    KeyedObjects ko1 = new KeyedObjects();
    ko1.addObject("Key 1", "Object 1");
    ko1.addObject("Key 2", null);
    ko1.addObject("Key 3", "Object 2");

    KeyedObjects ko2 = null;

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

        ObjectInput in = new ObjectInputStream(
                new ByteArrayInputStream(buffer.toByteArray()));
        ko2 = (KeyedObjects) in.readObject();
        in.close();
    }
    catch (Exception e) {
        e.printStackTrace();
    }
    assertEquals(ko1, ko2);

}
 
Example 20
Source File: SlidingGanttCategoryDatasetTests.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Serialize an instance, restore it, and check for equality.
 */
public void testSerialization() {
    TaskSeries s1 = new TaskSeries("Series");
    s1.add(new Task("Task 1", new Date(0L), new Date(1L)));
    TaskSeriesCollection u1 = new TaskSeriesCollection();
    u1.add(s1);
    SlidingGanttCategoryDataset d1 = new SlidingGanttCategoryDataset(
            u1, 0, 5);
    SlidingGanttCategoryDataset d2 = null;
    try {
        ByteArrayOutputStream buffer = new ByteArrayOutputStream();
        ObjectOutput out = new ObjectOutputStream(buffer);
        out.writeObject(d1);
        out.close();

        ObjectInput in = new ObjectInputStream(
                new ByteArrayInputStream(buffer.toByteArray()));
        d2 = (SlidingGanttCategoryDataset) in.readObject();
        in.close();
    }
    catch (Exception e) {
        e.printStackTrace();
    }
    assertEquals(d1, d2);

    // basic check for independence
    s1.add(new Task("Task 2", new Date(10L), new Date(11L)));
    assertFalse(d1.equals(d2));
    TaskSeriesCollection u2
            = (TaskSeriesCollection) d2.getUnderlyingDataset();
    TaskSeries s2 = u2.getSeries("Series");
    s2.add(new Task("Task 2", new Date(10L), new Date(11L)));
    assertTrue(d1.equals(d2));
}