List of usage examples for java.io ObjectInput close
public void close() throws IOException;
From source file:org.jfree.data.time.junit.TimePeriodValuesTest.java
/** * Serialize an instance, restore it, and check for equality. *//*from w w w .j a va2s . c om*/ public void testSerialization() { TimePeriodValues s1 = new TimePeriodValues("A test"); s1.add(new Year(2000), 13.75); s1.add(new Year(2001), 11.90); s1.add(new Year(2002), null); s1.add(new Year(2005), 19.32); s1.add(new Year(2007), 16.89); TimePeriodValues 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 = (TimePeriodValues) in.readObject(); in.close(); } catch (Exception e) { e.printStackTrace(); } assertTrue(s1.equals(s2)); }
From source file:org.kepler.gui.component.ShowFolders.java
/** * Load saved state/*from w w w . jav a2 s. com*/ */ private void init() { File saveFile = new File(_saveFileName); if (saveFile.exists()) { if (isDebugging) { log.debug("ShowFolders exists: " + saveFile.toString()); } try { InputStream is = null; ObjectInput oi = null; try { is = new FileInputStream(saveFile); oi = new ObjectInputStream(is); Object newObj = oi.readObject(); _showFolders = (Boolean) 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 localSaveRepoFile: " + e1.getMessage()); try { saveFile.delete(); } catch (Exception e2) { log.warn("Unable to delete localSaveRepoFile: " + e2.getMessage()); } } } else { // default to true set(true); } }
From source file:org.jfree.data.xy.junit.XYSeriesCollectionTest.java
/** * Serialize an instance, restore it, and check for equality. *///from ww w. j av a 2 s . com public void testSerialization() { XYSeries s1 = new XYSeries("Series"); s1.add(1.0, 1.1); XYSeriesCollection c1 = new XYSeriesCollection(); c1.addSeries(s1); XYSeriesCollection 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 = (XYSeriesCollection) in.readObject(); in.close(); } catch (Exception e) { e.printStackTrace(); } assertEquals(c1, c2); }
From source file:org.buzzjoe.SimpleDataStorage.SimpleDataStorage.java
/** * Returns properties value out of this.data container. * //from ww w . j a va 2s. c o m * @param propertyName Property to get * @return a string containing the value of requestet proprety */ public Object get(String propertyName) { String data = this.data.getProperty(propertyName); try { int integer = Integer.parseInt(data); // Looks like we've got an Integer value. Return it. return integer; } catch (NumberFormatException nFE) { // whooops. This wasn't integer. Let's try if we can deserialize... try { byte[] decoded = Base64.decodeBase64(data); ObjectInput in = new ObjectInputStream(new ByteArrayInputStream(decoded)); Object oData = in.readObject(); in.close(); return oData; } catch (Exception e) { // Nope. Not even serialized stuff. So it must be a string return data; } } }
From source file:org.jfree.data.junit.DefaultKeyedValuesTests.java
/** * Serialize an instance, restore it, and check for equality. *///from w w w . j a v a 2s . co m public void testSerialization() { DefaultKeyedValues v1 = new DefaultKeyedValues(); v1.addValue("Key 1", new Double(23)); v1.addValue("Key 2", null); v1.addValue("Key 3", new Double(42)); DefaultKeyedValues 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 = (DefaultKeyedValues) in.readObject(); in.close(); } catch (Exception e) { e.printStackTrace(); } assertEquals(v1, v2); }
From source file:org.jfree.data.junit.KeyedObjectsTests.java
/** * Serialize an instance, restore it, and check for equality. */// ww w .j a va2 s. c o m 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); }
From source file:com.roche.iceboar.cachestorage.LocalCacheStorage.java
public CacheStatus loadCacheStatus(String cachePath) { InputStream file = null;/*w ww . ja v a 2 s. com*/ InputStream buffer = null; ObjectInput input = null; try { file = new FileInputStream(cachePath); buffer = new BufferedInputStream(file); input = new ObjectInputStream(buffer); CacheStatus cacheStatus = (CacheStatus) input.readObject(); return cacheStatus; } catch (Exception e) { System.out.println("Can't open file with cache settings. Expected file here: " + cachePath); } finally { if (input != null) { try { input.close(); } catch (IOException e) { e.printStackTrace(); } } if (buffer != null) { try { buffer.close(); } catch (IOException e) { e.printStackTrace(); } } if (file != null) { try { file.close(); } catch (IOException e) { e.printStackTrace(); } } } return new CacheStatus(); }
From source file:org.jfree.data.junit.DefaultKeyedValuesTest.java
/** * Serialize an instance, restore it, and check for equality. */// w w w . j a va 2s . c om public void testSerialization() { DefaultKeyedValues v1 = new DefaultKeyedValues(); v1.addValue("Key 1", new Double(23)); v1.addValue("Key 2", null); v1.addValue("Key 3", new Double(42)); DefaultKeyedValues 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 = (DefaultKeyedValues) in.readObject(); in.close(); } catch (Exception e) { System.out.println(e.toString()); } assertEquals(v1, v2); }
From source file:org.wso2.carbon.identity.application.authentication.framework.store.SessionDataStore.java
private Object getBlobObject(InputStream is) throws IdentityApplicationManagementException, IOException, ClassNotFoundException { if (is != null) { ObjectInput ois = null; try {// ww w .j a v a 2s .co m ois = new ObjectInputStream(is); return ois.readObject(); } finally { if (ois != null) { try { ois.close(); } catch (IOException e) { log.error("IOException while trying to close ObjectInputStream.", e); } } } } return null; }
From source file:com.near.chimerarevo.fragments.PostsRecyclerFragment.java
private boolean readOfflineFile() { try {/* ww w . j ava 2 s . c om*/ if (new File(getActivity().getCacheDir() + "/posts.ser").exists()) { mLoadingBar.setVisibility(View.VISIBLE); mSwipeRefreshLayout.setRefreshing(true); InputStream file = new FileInputStream(getActivity().getCacheDir() + "/posts.ser"); ObjectInput input = new ObjectInputStream(new BufferedInputStream(file)); mJson = ((PostsListObject) input.readObject()).getJSONs(); input.close(); shouldAddToStack = false; shouldSmoothScroll = false; try { for (String json : mJson) { setItems(JSONUtils.getJSONArray(json, Constants.KEY_POSTS)); shouldAddToStack = true; } mSwipeRefreshLayout.setRefreshing(false); mLoadingBar.setVisibility(View.GONE); mFab.setEnabled(true); return true; } catch (Exception e) { e.printStackTrace(); } } } catch (IOException | ClassCastException | ClassNotFoundException e) { e.printStackTrace(); } mSwipeRefreshLayout.setRefreshing(false); mLoadingBar.setVisibility(View.GONE); return false; }