List of usage examples for java.io ObjectInputStream readObject
public final Object readObject() throws IOException, ClassNotFoundException
From source file:com.jaspersoft.jasperserver.core.util.TolerantObjectWrapper.java
private void readObject(ObjectInputStream stream) throws ClassNotFoundException, IOException { obj = stream.readObject(); }
From source file:com.manning.blogapps.chapter11.rome.DiskFeedInfoCache.java
public SyndFeedInfo getFeedInfo(URL url) { SyndFeedInfo info = null;//from w w w . ja v a2 s. c o m String fileName = cachePath + File.separator + "feed_" + url.hashCode(); FileInputStream fis; try { fis = new FileInputStream(fileName); ObjectInputStream ois = new ObjectInputStream(fis); info = (SyndFeedInfo) ois.readObject(); fis.close(); } catch (FileNotFoundException fnfe) { logger.debug("Cache miss for " + url.toString()); } catch (ClassNotFoundException cnfe) { // Error writing to cahce is fatal throw new RuntimeException("Attempting to read from cache", cnfe); } catch (IOException fnfe) { // Error writing to cahce is fatal throw new RuntimeException("Attempting to read from cache", fnfe); } if (info == null) logger.info("Cache MISS!"); return info; }
From source file:SaveYourDrawingToFile.java
public void actionPerformed(ActionEvent e) { if (e.getSource() == clearBtn) { displayList = new Vector(); repaint();//from ww w .j a v a 2 s . c o m } else if (e.getSource() == saveBtn) { try { FileOutputStream fos = new FileOutputStream(pathname); ObjectOutputStream oos = new ObjectOutputStream(fos); oos.writeObject(displayList); oos.flush(); oos.close(); fos.close(); } catch (Exception ex) { System.out.println("Trouble writing display list vector"); } } else if (e.getSource() == restoreBtn) { try { FileInputStream fis = new FileInputStream(pathname); ObjectInputStream ois = new ObjectInputStream(fis); displayList = (Vector) (ois.readObject()); ois.close(); fis.close(); repaint(); } catch (Exception ex) { System.out.println("Trouble reading display list vector"); } } else if (e.getSource() == quitBtn) { setVisible(false); dispose(); System.exit(0); } }
From source file:io.gumga.application.GumgaTempFileService.java
/** * Encontrar o arquivo temporario//w ww. j a v a2 s . co m * @param tempFileName nome do arquivo a ser procurado * @return arquivo */ public GumgaFile find(String tempFileName) { if (tempFileName == null || tempFileName.isEmpty()) { return null; } try { //TODO Melhorar o tratamento da Exception para FileNotFound FileInputStream fis = new FileInputStream(gumgaValues.getUploadTempDir() + "/" + tempFileName); ObjectInputStream ois = new ObjectInputStream(fis); GumgaFile gf = (GumgaFile) ois.readObject(); ois.close(); fis.close(); return gf; } catch (Exception ex) { log.error("erro ao recuperar arquivo temporario " + tempFileName, ex); } return null; }
From source file:ch.epfl.leb.sass.ijplugin.IJPluginModel.java
/** * Loads a model from a file./* www. j av a 2s . com*/ * * @param fileIn The input stream from the file. */ public static IJPluginModel read(FileInputStream fileIn) { IJPluginModel model = null; try { ObjectInputStream in = new ObjectInputStream(fileIn); model = (IJPluginModel) in.readObject(); in.close(); fileIn.close(); } catch (IOException ex) { ex.printStackTrace(); } catch (ClassNotFoundException c) { c.printStackTrace(); } return model; }
From source file:com.g3net.tool.ObjectUtils.java
/** * //from w ww . ja va 2s .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.acme.CodeDrivenProcessor.java
public CodeDrivenProcessor(String resource) { // 1. load the resource // 2. deserialize the lambda System.out.println("resource=" + resource); if (resource == null) return;/*from w w w . j ava 2 s . c om*/ try { // InputStream is = new FileInputStream(new File("/tmp/bytes"));// InputStream is = this.getClass().getClassLoader().getResourceAsStream(resource); if (is == null) return; System.out.println("deserializing"); ObjectInputStream ois = new ObjectInputStream(is); delegate = (Processor<Tuple, Tuple>) ois.readObject(); ois.close(); } catch (IOException e) { e.printStackTrace(); } catch (ClassNotFoundException e) { e.printStackTrace(); } }
From source file:com.vnomicscorp.spring.security.cas.authentication.redis.DefaultCasAuthenticationTokenSerializer.java
@Override public CasAuthenticationToken deserialize(String serialized) throws CasAuthenticationTokenSerializerException { try {//from w w w .ja v a 2 s . com ByteArrayInputStream bais = new ByteArrayInputStream(Base64.decode(serialized.getBytes(charset))); ObjectInputStream oos = new ObjectInputStream(bais); return (CasAuthenticationToken) oos.readObject(); } catch (IOException e) { throw new CasAuthenticationTokenSerializerException(e); } catch (ClassNotFoundException e) { throw new CasAuthenticationTokenSerializerException(e); } }
From source file:org.ambraproject.model.article.ArticleTypeTest.java
@Test public void testDeserializedArticleTypeEquality() throws Exception { ArticleType art1 = ArticleType/*from w w w . ja v a 2s . co m*/ .getArticleTypeForURI(new URI("http://rdf.plos.org/RDF/articleType/Interview"), false); ByteArrayOutputStream bout = new ByteArrayOutputStream(); ObjectOutputStream out = new ObjectOutputStream(bout); out.writeObject(art1); out.flush(); ByteArrayInputStream bin = new ByteArrayInputStream(bout.toByteArray()); ObjectInputStream in = new ObjectInputStream(bin); ArticleType art2 = (ArticleType) in.readObject(); assertTrue(art1 == art2, "Article 1 == Article 2"); assertTrue(art1.equals(art2), "Article 1 should .equals() Article 2"); }
From source file:de.dfki.asr.compass.model.AbstractCompassEntity.java
public AbstractCompassEntity deepCopy() throws IOException, ClassNotFoundException { AbstractCompassEntity entity = null; forceEagerFetch();/*from ww w . j a va2 s. co m*/ // Write the object out to a byte array ByteArrayOutputStream bos = new ByteArrayOutputStream(); ObjectOutputStream out = new ObjectOutputStream(bos); out.writeObject(this); out.flush(); out.close(); // Make an input stream from the byte array and read // a copy of the object back in. ObjectInputStream in = new ObjectInputStream(new ByteArrayInputStream(bos.toByteArray())); entity = (AbstractCompassEntity) in.readObject(); entity.clearIdsAfterDeepCopy(); return entity; }