Example usage for java.io ObjectInput close

List of usage examples for java.io ObjectInput close

Introduction

In this page you can find the example usage for java.io ObjectInput close.

Prototype

public void close() throws IOException;

Source Link

Document

Closes the input stream.

Usage

From source file:org.jfree.data.category.junit.CategoryToPieDatasetTest.java

/**
 * Serialize an instance, restore it, and check for equality.
 *//*from w  w w .  ja  v a 2s  .co m*/
public void testSerialization() {
    DefaultCategoryDataset underlying = new DefaultCategoryDataset();
    underlying.addValue(1.1, "R1", "C1");
    underlying.addValue(2.2, "R1", "C2");
    CategoryToPieDataset d1 = new CategoryToPieDataset(underlying, TableOrder.BY_COLUMN, 1);
    CategoryToPieDataset 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 = (CategoryToPieDataset) in.readObject();
        in.close();
    } catch (Exception e) {
        e.printStackTrace();
    }
    assertEquals(d1, d2);

    // regular equality for the datasets doesn't check the fields, just
    // the data values...so let's check some more things...
    assertEquals(d1.getUnderlyingDataset(), d2.getUnderlyingDataset());
    assertEquals(d1.getExtractType(), d2.getExtractType());
    assertEquals(d1.getExtractIndex(), d2.getExtractIndex());
}

From source file:org.jfree.data.xy.junit.CategoryTableXYDatasetTest.java

/**
 * Serialize an instance, restore it, and check for equality.
 *///from w  w  w .j a v a 2s.co  m
public void testSerialization() {

    CategoryTableXYDataset d1 = new CategoryTableXYDataset();
    d1.add(1.0, 1.1, "Series 1");
    d1.add(2.0, 2.2, "Series 1");

    CategoryTableXYDataset 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 = (CategoryTableXYDataset) in.readObject();
        in.close();
    } catch (Exception e) {
        e.printStackTrace();
    }
    assertEquals(d1, d2);

}

From source file:org.jfree.data.xy.junit.DefaultTableXYDatasetTest.java

/**
 * Serialize an instance, restore it, and check for equality.
 *///from w w w.j av a2s. c  o  m
public void testSerialization() {

    DefaultTableXYDataset d1 = new DefaultTableXYDataset();
    XYSeries s1 = new XYSeries("Series 1", true, false);
    s1.add(1.0, 1.1);
    s1.add(2.0, 2.2);
    d1.addSeries(s1);

    DefaultTableXYDataset 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 = (DefaultTableXYDataset) in.readObject();
        in.close();
    } catch (Exception e) {
        e.printStackTrace();
    }
    assertEquals(d1, d2);

}

From source file:com.near.chimerarevo.services.NewsService.java

private boolean readOfflineFile(String result) {
    try {/*from   ww w .j  av a 2 s.  c o m*/
        if (new File(getCacheDir() + "/posts.ser").exists()) {
            InputStream file = new FileInputStream(getCacheDir() + "/posts.ser");
            ObjectInput input = new ObjectInputStream(new BufferedInputStream(file));
            ArrayList<String> mJson = ((PostsListObject) input.readObject()).getJSONs();
            input.close();
            if (mJson != null && mJson.size() > 0) {
                try {
                    JsonParser parser = new JsonParser();
                    JsonElement o1 = parser.parse(result);
                    JsonElement o2 = parser.parse(mJson.get(0));
                    return !o1.equals(o2);
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        }
    } catch (IOException | ClassNotFoundException | ClassCastException e) {
        e.printStackTrace();
    }
    return false;
}

From source file:org.jfree.data.xy.junit.DefaultWindDatasetTest.java

/**
 * Serialize an instance, restore it, and check for equality.
 *//* w w w  .j av a 2  s  .  c  om*/
public void testSerialization() {
    DefaultWindDataset d1 = new DefaultWindDataset();
    DefaultWindDataset 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 = (DefaultWindDataset) in.readObject();
        in.close();
    } catch (Exception e) {
        e.printStackTrace();
    }
    assertEquals(d1, d2);

    // try a dataset with some content...
    d1 = createSampleDataset1();
    try {
        ByteArrayOutputStream buffer = new ByteArrayOutputStream();
        ObjectOutput out = new ObjectOutputStream(buffer);
        out.writeObject(d1);
        out.close();

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

}

From source file:org.rhq.enterprise.server.plugins.alertMicroblog.MicroblogSender.java

private AccessToken restoreAccessToken(String tokenFilePath) throws IOException {
    //use buffering
    InputStream file = new FileInputStream(tokenFilePath);
    InputStream buffer = new BufferedInputStream(file);
    ObjectInput input = new ObjectInputStream(buffer);

    AccessToken token = null;/*ww w.j a  v a  2s.  c  om*/

    try {
        token = (AccessToken) input.readObject();
    } catch (ClassNotFoundException e) {
        log.error("Erro reading token from disk: ", e);
    } finally {
        input.close();
    }

    return token;
}

From source file:org.jfree.data.xy.junit.DefaultXYDatasetTest.java

/**
 * Serialize an instance, restore it, and check for equality.
 *///from   w  w  w  .j a  v a  2s. co  m
public void testSerialization() {

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

    // try a dataset with some content...
    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);
    try {
        ByteArrayOutputStream buffer = new ByteArrayOutputStream();
        ObjectOutput out = new ObjectOutputStream(buffer);
        out.writeObject(d1);
        out.close();

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

}

From source file:org.jfree.data.xy.junit.DefaultXYZDatasetTest.java

/**
 * Serialize an instance, restore it, and check for equality.
 */// ww  w .j ava  2  s  . c  o  m
public void testSerialization() {

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

    // try a dataset with some content...
    double[] x1 = new double[] { 1.0, 2.0, 3.0 };
    double[] y1 = new double[] { 4.0, 5.0, 6.0 };
    double[] z1 = new double[] { 7.0, 8.0, 9.0 };
    double[][] data1 = new double[][] { x1, y1, z1 };
    d1.addSeries("S1", data1);
    try {
        ByteArrayOutputStream buffer = new ByteArrayOutputStream();
        ObjectOutput out = new ObjectOutputStream(buffer);
        out.writeObject(d1);
        out.close();

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

}

From source file:org.jfree.data.xy.junit.TableXYDatasetTest.java

/**
 * Serialize an instance, restore it, and check for equality.
 *///w  w  w.j  av  a 2 s  .  co m
public void testSerialization() {

    DefaultTableXYDataset d1 = new DefaultTableXYDataset();
    d1.addSeries(createSeries2());
    DefaultTableXYDataset 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 = (DefaultTableXYDataset) in.readObject();
        in.close();
    } catch (Exception e) {
        System.out.println(e.toString());
    }
    assertEquals(d1, d2);

}

From source file:org.jfree.data.time.junit.SecondTest.java

/**
 * Serialize an instance, restore it, and check for equality.
 *///  ww w  . ja v a  2  s . co m
public void testSerialization() {
    Second s1 = new Second();
    Second 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 = (Second) in.readObject();
        in.close();
    } catch (Exception e) {
        e.printStackTrace();
    }
    assertEquals(s1, s2);
}