List of usage examples for java.io ObjectInputStream close
public void close() throws IOException
From source file:net.sf.ehcache.jcache.JCacheStatisticsTest.java
/** * We want to be able to use Statistics as a value object. * We need to do some magic with the reference held to Cache *///from www .j a v a2 s. co m public void testSerialization() throws IOException, ClassNotFoundException { Ehcache ehcache = new net.sf.ehcache.Cache("test", 1, true, false, 5, 2); manager.addCache(ehcache); Cache cache = new JCache(ehcache, null); cache.put("key1", "value1"); cache.put("key2", "value1"); cache.get("key1"); cache.get("key1"); CacheStatistics statistics = cache.getCacheStatistics(); assertEquals(2, statistics.getCacheHits()); assertEquals(0, statistics.getCacheMisses()); assertEquals(CacheStatistics.STATISTICS_ACCURACY_BEST_EFFORT, statistics.getStatisticsAccuracy()); statistics.clearStatistics(); ByteArrayOutputStream bout = new ByteArrayOutputStream(); ObjectOutputStream oos = new ObjectOutputStream(bout); oos.writeObject(statistics); byte[] serializedValue = bout.toByteArray(); oos.close(); CacheStatistics afterDeserializationStatistics = null; ByteArrayInputStream bin = new ByteArrayInputStream(serializedValue); ObjectInputStream ois = new ObjectInputStream(bin); afterDeserializationStatistics = (CacheStatistics) ois.readObject(); ois.close(); //Check after Serialization assertEquals(2, afterDeserializationStatistics.getCacheHits()); assertEquals(0, afterDeserializationStatistics.getCacheMisses()); assertEquals(CacheStatistics.STATISTICS_ACCURACY_BEST_EFFORT, statistics.getStatisticsAccuracy()); statistics.clearStatistics(); }
From source file:com.lmco.ddf.commands.catalog.IngestCommand.java
private Metacard readMetacard(File file) throws FileNotFoundException, ClassNotFoundException, MimeTypeParseException, MetacardCreationException, InterruptedException, CatalogTransformerException { Metacard result = null;//from w ww . j ava2s . c o m try { if (DEFAULT_TRANSFORMER_ID.matches(transformerId)) { ObjectInputStream ois = new ObjectInputStream(new FileInputStream(file)); result = (Metacard) ois.readObject(); ois.close(); } else { FileInputStream fis = new FileInputStream(file); result = generateMetacard(fis); fis.close(); } } catch (IOException e) { console.println(e); } return result; }
From source file:de.tudarmstadt.ukp.dkpro.wsd.si.dictionary.UkbDictionaryInventory.java
public UkbDictionaryInventory(String inputPath, String serializiblePath, String neededMentionsPath) throws FileNotFoundException, IOException { // Open the serialized version or create it from scratch try {// www . j av a 2s .c o m // System.out.println("Trying to load dictionary from serializable."); ObjectInputStream dictionaryReader = new ObjectInputStream( new BZip2CompressorInputStream(new FileInputStream(serializiblePath))); dictionary = (UkbDictionary) dictionaryReader.readObject(); dictionaryReader.close(); // System.out.println("Loaded dictionary from serializable."); } catch (Exception e) { // System.out.println("Trying to load dictionary from input."); dictionary = new UkbDictionary(inputPath, neededMentionsPath); System.out.println("Loaded dictionary from input."); ObjectOutputStream dictionaryWriter = new ObjectOutputStream( new BZip2CompressorOutputStream(new FileOutputStream(serializiblePath))); dictionaryWriter.writeObject(dictionary); dictionaryWriter.close(); // System.out.println("Stored dictionary in serializable."); } }
From source file:de.intranda.goobi.plugins.utils.ModsUtils.java
private static Object readFile(File file) { FileInputStream fis;//from w ww. j ava 2 s . c o m Object obj = null; try { fis = new FileInputStream(file); ObjectInputStream ois = new ObjectInputStream(fis); obj = ois.readObject(); ois.close(); } catch (FileNotFoundException e) { logger.warn("No binary file exists to read. Aborting."); } catch (IOException e) { logger.error("Error reading binary file", e); } catch (ClassNotFoundException e) { logger.error("Error reading object from binary file", e); } return obj; }
From source file:ch.rgw.tools.StringTool.java
static private Object StringToObject(final String s) { String sx = s.substring(1);/*from w w w .j a v a2 s . com*/ char pref = s.charAt(0); switch (pref) { case 'A': return sx; case 'B': return (new Integer(Integer.parseInt(sx))); case 'Z': byte[] b = dePrintable(sx); try { ByteArrayInputStream bais = new ByteArrayInputStream(b); ObjectInputStream ois = new ObjectInputStream(bais); Object ret = ois.readObject(); ois.close(); bais.close(); return ret; } catch (Exception ex) { ExHandler.handle(ex); return null; } } return null; }
From source file:org.sakaiproject.orm.ibatis.support.BlobSerializableTypeHandler.java
protected Object getResultInternal(ResultSet rs, int index, LobHandler lobHandler) throws SQLException, IOException { InputStream is = lobHandler.getBlobAsBinaryStream(rs, index); if (is != null) { ObjectInputStream ois = new ObjectInputStream(is); try {/*from ww w. ja v a2 s . co m*/ return ois.readObject(); } catch (ClassNotFoundException ex) { throw new SQLException("Could not deserialize BLOB contents: " + ex.getMessage()); } finally { ois.close(); } } else { return null; } }
From source file:net.fizzl.redditengine.impl.PersistentCookieStore.java
/** * Load Cookies from a file// ww w. ja v a 2 s . c o m */ private void load() { RedditApi api = DefaultRedditApi.getInstance(); Context ctx = api.getContext(); try { FileInputStream fis = ctx.openFileInput(cookiestore); ObjectInputStream ois = new ObjectInputStream(fis); SerializableCookieStore tempStore = (SerializableCookieStore) ois.readObject(); super.clear(); for (Cookie c : tempStore.getCookies()) { super.addCookie(c); } ois.close(); fis.close(); } catch (FileNotFoundException e) { Log.w(getClass().getName(), e.getMessage()); } catch (Exception e) { e.printStackTrace(); } }
From source file:BckgrndServiceThreads.fileListingTH.java
Object getSerializedObject(String objectName) throws Exception { FileInputStream inputFile = new FileInputStream(objectName); ObjectInputStream inputObject = new ObjectInputStream(inputFile); Object getObjectToReturn = inputObject.readObject(); inputObject.close(); return getObjectToReturn; }
From source file:org.nuvola.tvshowtime.ApplicationLauncher.java
@Scheduled(fixedDelay = Long.MAX_VALUE) public void init() { tvShowTimeTemplate = new RestTemplate(); File storeToken = new File(tvShowTimeConfig.getTokenFile()); if (storeToken.exists()) { try {/*from w w w.j ava 2 s. c o m*/ FileInputStream fileInputStream = new FileInputStream(storeToken); ObjectInputStream objectInputStream = new ObjectInputStream(fileInputStream); accessToken = (AccessToken) objectInputStream.readObject(); objectInputStream.close(); fileInputStream.close(); LOG.info("AccessToken loaded from file with success : " + accessToken); } catch (Exception e) { LOG.error("Error parsing the AccessToken stored in 'session_token'."); LOG.error("Please remove the 'session_token' file, and try again."); LOG.error(e.getMessage()); System.exit(1); } try { processWatchedEpisodes(); } catch (Exception e) { LOG.error("Error during marking episodes as watched."); LOG.error(e.getMessage()); System.exit(1); } } else { requestAccessToken(); } }
From source file:com.baidu.terminator.storage.file.FileStorage.java
public Object getbyID(Long dataId) { // load from database DataIndex recordData = dataIndexMapper.selectDataIndexByID(dataId); RequestResponseBundle bundles = new RequestResponseBundle(); // read from file if (recordData != null) { Long offset;//w w w .j a v a 2 s .c o m offset = recordData.getOffset(); String filePath = this.filePath; try { FileInputStream dataStream = new FileInputStream(filePath); dataStream.skip(offset); ObjectInputStream objStream = new ObjectInputStream(dataStream); bundles = (RequestResponseBundle) objStream.readObject(); objStream.close(); dataStream.close(); } catch (Exception e) { logger.error("[UPDATE] file data does not exists"); System.out.println("[UPDATE] file data does not exists!"); e.printStackTrace(); } } return bundles; }