List of usage examples for java.io ObjectInputStream close
public void close() throws IOException
From source file:dkpro.similarity.algorithms.wikipedia.measures.WikiLinkCache.java
/** * Loads the cache from file// w w w . jav a 2 s. co m * * @param file * @throws IOException * @throws FileNotFoundException * @throws ClassNotFoundException * @throws Exception */ public Object deserializeObject(File file) throws FileNotFoundException, IOException, ClassNotFoundException { logger.info("Loading cache from file: " + file.getAbsolutePath()); ObjectInputStream ois = new ObjectInputStream(new FileInputStream(file)); Object o = ois.readObject(); ois.close(); logger.info("Done."); return o; }
From source file:common.services.generic.GenericCacheService.java
@Override public T getFromFile() { File f = new File(path, "cache.tmp"); if (!f.exists()) return null; try {// w w w . j a v a2s .c o m FileInputStream fi = new FileInputStream(f); ObjectInputStream si = new ObjectInputStream(fi); T tmp = (T) si.readObject(); si.close(); fi.close(); return tmp; } catch (IOException ex) { logger.error("failed to load cache path = " + path, ex); return null; } catch (ClassNotFoundException ex) { logger.error("failed to load cache path = " + path, ex); return null; } }
From source file:slina.mb.controller.ObjectSaverFactory.java
@Test public void testDeserilization() throws IOException, ClassNotFoundException { InputStream osx = new FileInputStream("logEvent.ser"); ObjectInputStream ocm = new ObjectInputStream(osx); @SuppressWarnings("unchecked") ArrayList<LogEvent> yy = (ArrayList<LogEvent>) ocm.readObject(); ocm.close(); assertEquals(7, yy.size());/* ww w .j a v a 2 s. co m*/ }
From source file:com.g3net.tool.ObjectUtils.java
/** * /*from ww w . j a va2 s . c o m*/ * @param data ?? * @return ??? * @throws Exception */ public static Object deSerializeObject(byte[] data) throws Exception { ByteArrayInputStream bis = null; ObjectInputStream ois = null; if (data == null || data.length == 0) { return null; } try { bis = new ByteArrayInputStream(data); ois = new ObjectInputStream(bis); return ois.readObject(); } finally { if (ois != null) { ois.close(); } } }
From source file:com.ps.cc.controller.Init.java
@RequestMapping public String index(ModelMap map, RenderRequest renderRequest) throws Exception { TwilioConfiguration twilioConfiguration = new TwilioConfiguration(); try {/* ww w . j av a2 s. c o m*/ File file = new File("twilioConfiguration.txt"); ObjectInputStream in = new ObjectInputStream(new FileInputStream(file)); twilioConfiguration = (TwilioConfiguration) in.readObject(); in.close(); } catch (Exception ex) { //didn't exist... } map.addAttribute("command", twilioConfiguration); return "index"; }
From source file:com.googlecode.DownloadCache.java
private void loadIndex() throws Exception { if (this.indexFile.isFile()) { FileInputStream input = new FileInputStream(this.indexFile); ObjectInputStream deserialize = new ObjectInputStream(input); this.index = (Map<String, CachedFileEntry>) deserialize.readObject(); deserialize.close(); } else {/*from ww w. j av a 2 s. co m*/ this.index = new HashMap<String, CachedFileEntry>(); } }
From source file:com.sun.j2ee.blueprints.waf.controller.impl.ClientStateFlowHandler.java
public String processFlow(HttpServletRequest request) throws FlowHandlerException { String forwardScreen = request.getParameter("referring_screen"); // de-serialize the request attributes. Map params = (Map) request.getParameterMap(); HashMap newParams = new HashMap(); String cacheId = request.getParameter("cacheId"); if (!params.isEmpty()) { Iterator it = params.keySet().iterator(); // put the request attributes stored in the session in the request while (it.hasNext()) { String key = (String) it.next(); if (key.startsWith(cacheId + "_attribute_")) { String[] values = (String[]) params.get(key); String valueString = values[0]; byte[] bytes = Base64.decode(valueString.getBytes()); try { ObjectInputStream ois = new ObjectInputStream(new ByteArrayInputStream(bytes)); Object requestObject = requestObject = ois.readObject(); ois.close(); // put the de-serialized object back into the request String requestObjectKey = key.substring((cacheId + "_attribute_").length(), key.length()); request.setAttribute(requestObjectKey, requestObject); } catch (java.io.OptionalDataException ode) { logger.error("ClientCacheLinkFlowHandler caught: ", ode); } catch (java.lang.ClassNotFoundException cnfe) { logger.error("ClientCacheLinkFlowHandler caught: ", cnfe); } catch (java.io.IOException iox) { logger.error("ClientCacheLinkFlowHandler caught: ", iox); }/*from w ww.ja v a2 s. c om*/ } } } return forwardScreen; }
From source file:edu.uga.cs.fluxbuster.clustering.hierarchicalclustering.Dendrogram.java
/** * Creates a deep copy of any object./* www . j a v a 2 s .c o m*/ * * @param o the object to copy * @return the copy */ public Object deepCopy(Object o) { try { ByteArrayOutputStream byteOut = new ByteArrayOutputStream(); ObjectOutputStream out = new ObjectOutputStream(byteOut); out.writeObject(o); out.close(); byte[] data = byteOut.toByteArray(); ObjectInputStream in = new ObjectInputStream(new ByteArrayInputStream(data)); Object copy = in.readObject(); in.close(); return copy; } catch (Exception e) { if (log.isErrorEnabled()) { log.error("Error performing deep copy.", e); } } return null; }
From source file:com.impetus.kundera.property.accessor.ObjectAccessor.java
@Override public final Object fromBytes(Class targetClass, byte[] bytes) { try {/*w w w. ja v a2 s . com*/ if (targetClass != null && targetClass.equals(byte[].class)) { return bytes; } ObjectInputStream ois; ois = new ObjectInputStream(new ByteArrayInputStream(bytes)); Object o = ois.readObject(); ois.close(); return o; } catch (IOException e) { throw new PropertyAccessException(e); } catch (ClassNotFoundException e) { throw new PropertyAccessException(e); } }
From source file:edu.uci.ics.jung.visualization.layout.PersistentLayoutImpl.java
/** * Restore the graph Vertex locations from a file * @param fileName the file to use// ww w.ja va2 s . com * @throws IOException for file problems * @throws ClassNotFoundException for classpath problems */ @SuppressWarnings("unchecked") public void restore(String fileName) throws IOException, ClassNotFoundException { ObjectInputStream ois = new ObjectInputStream(new FileInputStream(fileName)); map = (Map) ois.readObject(); ois.close(); initializeLocations(); locked = true; fireStateChanged(); }