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.time.junit.MinuteTest.java

/**
 * Serialize an instance, restore it, and check for equality.
 *///w  w w .  j  a v a 2  s.c  o  m
public void testSerialization() {
    Minute m1 = new Minute();
    Minute m2 = null;

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

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

From source file:com.lhy.commons.encrypt.service.EncryptService.java

@Override
public License getLicense(File licenseFile, String ipAddress) {
    License licFile = null;//from  w  w  w  .  j  a  v a 2 s.c  om
    try {
        ObjectInput in = new ObjectInputStream(new FileInputStream(licenseFile));
        licFile = (License) in.readObject();
        if (licFile.getIpAddress().equals(DigestUtils.sha512Hex(ipAddress))
                && licFile.getLicenseType().equals(LicenseType.user)) {
            licFile.setLicenseType(LicenseType.user);
        } else {
            licFile.setLicenseType(LicenseType.developer);
        }
        in.close();
    } catch (FileNotFoundException e) {
        log.error(e.getMessage());
    } catch (IOException e) {
        log.error(e.getMessage());
    } catch (ClassNotFoundException e) {
        log.error(e.getMessage());
    }
    return licFile;
}

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

/**
 * Serialize an instance, restore it, and check for equality.
 */// w  w  w.  j a  va  2 s.  co m
public void testSerialization() {
    Millisecond m1 = new Millisecond();
    Millisecond m2 = null;
    try {
        ByteArrayOutputStream buffer = new ByteArrayOutputStream();
        ObjectOutput out = new ObjectOutputStream(buffer);
        out.writeObject(m1);
        out.close();

        ObjectInput in = new ObjectInputStream(new ByteArrayInputStream(buffer.toByteArray()));
        m2 = (Millisecond) in.readObject();
        in.close();
    } catch (Exception e) {
        e.printStackTrace();
    }
    assertEquals(m1, m2);
}

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

/**
 * Serialize an instance, restore it, and check for equality.
 *///w w w . j a  v  a  2s.co m
public void testSerialization() {
    Hour h1 = new Hour();
    Hour h2 = null;

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

        ObjectInput in = new ObjectInputStream(new ByteArrayInputStream(buffer.toByteArray()));
        h2 = (Hour) in.readObject();
        in.close();
    } catch (Exception e) {
        e.printStackTrace();
    }
    assertEquals(h1, h2);
}

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

/**
 * Serialize an instance, restore it, and check for equality.
 *//*from ww w. java 2 s.c  o  m*/
public void testSerialization() {
    Day d1 = new Day(15, 4, 2000);
    Day 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 = (Day) in.readObject();
        in.close();
    } catch (Exception e) {
        e.printStackTrace();
    }
    assertEquals(d1, d2);
}

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

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

    DefaultCategoryDataset d1 = new DefaultCategoryDataset();
    d1.setValue(23.4, "R1", "C1");
    DefaultCategoryDataset 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 = (DefaultCategoryDataset) in.readObject();
        in.close();
    } catch (Exception e) {
        e.printStackTrace();
    }
    assertEquals(d1, d2);

}

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

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

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

}

From source file:org.kepler.objectmanager.library.LibSearchConfiguration.java

private void init() {
    File saveFile = new File(_saveFileName);

    if (saveFile.exists()) {
        if (isDebugging) {
            log.debug("Save file exists: " + saveFile.toString());
        }/*from  w w w.  j  a v a2  s  . co m*/

        try {
            InputStream is = null;
            ObjectInput oi = null;
            try {
                is = new FileInputStream(saveFile);
                oi = new ObjectInputStream(is);
                Object newObj = oi.readObject();
                _searchTypes = (Vector<Integer>) newObj;
                return;
            } finally {
                if (oi != null) {
                    oi.close();
                }
                if (is != null) {
                    is.close();
                }
            }

        } catch (Exception e1) {
            // problem reading file, try to delete it
            log.warn("Exception while reading save file: " + e1.getMessage());
            try {
                saveFile.delete();
            } catch (Exception e2) {
                log.warn("Unable to delete save file: " + e2.getMessage());
            }
        }
    } else {
        setDefaults();
    }

}

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

/**
 * Serialize an instance, restore it, and check for equality.
 *//*from w  w w .ja v  a2 s.  c om*/
public void testSerialization() {

    Month m1 = new Month(12, 1999);
    Month m2 = null;

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

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

}

From source file:com.near.chimerarevo.fragments.SearchFragment.java

private boolean readOfflineFile() {
    try {//from  ww w . j  a  v a  2 s.c om
        if (new File(getActivity().getCacheDir() + "/search.ser").exists()) {
            InputStream file = new FileInputStream(getActivity().getCacheDir() + "/search.ser");
            InputStream buffer = new BufferedInputStream(file);
            ObjectInput input = new ObjectInputStream(buffer);
            mJson = ((PostsListObject) input.readObject()).getJSONs();
            input.close();
            shouldSmoothScroll = false;
            try {
                for (String json : mJson)
                    setItems(JSONUtils.getJSONArray(json, Constants.KEY_POSTS));
            } catch (Exception e) {
                e.printStackTrace();
                return false;
            }
            return true;
        } else
            return false;
    } catch (IOException | ClassNotFoundException e) {
        e.printStackTrace();
    }
    return false;
}