List of usage examples for java.io ObjectInputStream ObjectInputStream
public ObjectInputStream(InputStream in) throws IOException
From source file:com.centurylink.mdw.common.translator.impl.JavaObjectTranslator.java
public Object realToObject(String str) throws TranslationException { ObjectInputStream ois = null; try {//from ww w. j a v a2 s .c o m byte[] decoded = decodeBase64(str); ByteArrayInputStream bais = new ByteArrayInputStream(decoded); ois = new ObjectInputStream(bais); try { return ois.readObject(); } catch (ClassNotFoundException ex) { ois.close(); bais = new ByteArrayInputStream(decoded); ois = new ObjectInputStream(bais) { @Override protected Class<?> resolveClass(ObjectStreamClass desc) throws IOException, ClassNotFoundException { try { return CompiledJavaCache.getResourceClass(desc.getName(), getClass().getClassLoader(), getPackage()); } catch (ClassNotFoundException ex) { if (getPackage() != null && getPackage().getCloudClassLoader() != null) return getPackage().getCloudClassLoader().loadClass(desc.getName()); else throw ex; } catch (MdwJavaException ex) { throw new ClassNotFoundException(desc.getName(), ex); } } }; return ois.readObject(); } } catch (Throwable t) { // including NoClassDefFoundError throw new TranslationException(t.getMessage(), t); } finally { if (ois != null) { try { ois.close(); } catch (IOException ex) { } } } }
From source file:com.roche.iceboar.cachestorage.LocalCacheStorage.java
public CacheStatus loadCacheStatus(String cachePath) { InputStream file = null;//from w w w . j a v a2 s . co m 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:com.hp.saas.agm.rest.client.SessionContext.java
public static SessionContext load(File sourceFile) { ObjectInputStream in = null;//from w ww .j av a 2 s .c om try { in = new ObjectInputStream(new FileInputStream(sourceFile)); return (SessionContext) in.readObject(); } catch (ClassNotFoundException e) { throw new RuntimeException(e); } catch (FileNotFoundException e) { throw new RuntimeException(e); } catch (InvalidClassException e) { throw new InvalidFormatException(e); } catch (IOException e) { throw new RuntimeException(e); } finally { if (in != null) { try { in.close(); } catch (IOException e) { logger.log(Level.SEVERE, "IOException thrown while closing stream.", e); } } } }
From source file:com.taobao.metamorphosis.utils.codec.impl.JavaDeserializer.java
/** * @see com.taobao.notify.codec.Deserializer#decodeObject(byte[]) *//*from w w w .j av a2s . c om*/ @Override public Object decodeObject(final byte[] objContent) throws IOException { Object obj = null; ByteArrayInputStream bais = null; ObjectInputStream ois = null; try { bais = new ByteArrayInputStream(objContent); ois = new ObjectInputStream(bais); obj = ois.readObject(); } catch (final IOException ex) { throw ex; } catch (final ClassNotFoundException ex) { this.logger.warn("Failed to decode object.", ex); } finally { if (ois != null) { try { ois.close(); bais.close(); } catch (final IOException ex) { this.logger.error("Failed to close stream.", ex); } } } return obj; }
From source file:FileUserAccess.java
@SuppressWarnings("resource") @Override//from w ww .ja va 2 s.co m public Collection<User> getUsers() { File folder = new File(System.getProperty("user.dir")); File[] filesInFolder = folder.listFiles(); List<User> users = new ArrayList<>(); for (File f : filesInFolder) if (FilenameUtils.getExtension(f.getName()).equals("userobj")) { FileInputStream streamIn; try { streamIn = new FileInputStream(f); } catch (FileNotFoundException ex) { Logger.getLogger(FileUserAccess.class.getName()).log(Level.SEVERE, null, ex); return null; } ObjectInputStream objectinputstream = null; try { objectinputstream = new ObjectInputStream(streamIn); } catch (IOException ex) { Logger.getLogger(FileUserAccess.class.getName()).log(Level.SEVERE, null, ex); return null; } try { User newUser = (User) objectinputstream.readObject(); users.add(newUser); } catch (IOException | ClassNotFoundException ex) { Logger.getLogger(FileUserAccess.class.getName()).log(Level.SEVERE, null, ex); } } User[] finalCollectionOrder = new User[users.size()]; for (User u : users) finalCollectionOrder[u.getPlayerId()] = u; return Arrays.asList(finalCollectionOrder); }
From source file:it.restrung.rest.utils.IOUtils.java
/** * Loads a serialized object from a file * * @param file the file where the object was serialized * @return the serialized object in its real in memory object representation *//*from w ww. j a v a2 s. c o m*/ @SuppressWarnings("unchecked") static public <T> T loadSerializableObjectFromDisk(File file) { T result = null; if (file.exists()) { try { FileInputStream fis = new FileInputStream(file); GZIPInputStream gzis = new GZIPInputStream(fis); ObjectInputStream in = new ObjectInputStream(gzis); result = (T) in.readObject(); in.close(); } catch (FileNotFoundException e) { Log.d(IOUtils.class.getName(), "Error, file not found for load serializable object from disk"); throw new RuntimeException(e); } catch (IOException e) { throw new RuntimeException(e); } catch (ClassNotFoundException e) { throw new RuntimeException(e); } } return result; }
From source file:de.ailis.oneinstance.OneInstanceClient.java
/** * @see java.lang.Runnable#run()//from w w w .ja v a 2s . c o m */ @Override public void run() { try { try { // Send the application ID. PrintWriter out = new PrintWriter(new OutputStreamWriter(this.socket.getOutputStream(), "UTF-8")); out.println(this.appId); out.flush(); // Read the data from the client InputStream in = this.socket.getInputStream(); ObjectInputStream objIn = new ObjectInputStream(in); File workingDir = (File) objIn.readObject(); String[] args = (String[]) objIn.readObject(); // Call event handler boolean result = OneInstance.getInstance().fireNewInstance(workingDir, args); // Send the result out.println(result ? "start" : "exit"); out.flush(); // Wait for client disconnect. in.read(); } finally { this.socket.close(); } } catch (IOException e) { LOG.error(e.toString(), e); } catch (ClassNotFoundException e) { LOG.error(e.toString(), e); } }
From source file:de.tudarmstadt.ukp.dkpro.core.io.bincas.SerializedCasReader.java
@Override public void getNext(CAS aCAS) throws IOException, CollectionException { Resource res = nextFile();/*from w ww .jav a 2s . c o m*/ ObjectInputStream is = null; try { is = new ObjectInputStream(CompressionUtils.getInputStream(res.getLocation(), res.getInputStream())); CASCompleteSerializer serializer = (CASCompleteSerializer) is.readObject(); deserializeCASComplete(serializer, (CASImpl) aCAS); } catch (ClassNotFoundException e) { throw new IOException(e); } finally { closeQuietly(is); } }
From source file:com.koda.common.lcm.Tool.java
public static Object undoObject(String obj) throws IOException { ByteArrayInputStream is = new ByteArrayInputStream(undoStuff(obj)); ObjectInputStream ois = new ObjectInputStream(is); try {/*from w w w. j av a 2 s . co m*/ return ois.readObject(); } catch (ClassNotFoundException e) { throw new IOException(e); } }
From source file:com.icesoft.faces.webapp.parser.TagToComponentMap.java
/** * Build the map from a serialized source. * * @param fis Input stream for the serialized data. * @return The map//from w w w. j a v a2s . com * @throws IOException * @throws ClassNotFoundException */ static TagToComponentMap loadFrom(InputStream fis) throws IOException, ClassNotFoundException { try { ObjectInputStream ois = new ObjectInputStream(fis); return (TagToComponentMap) ois.readObject(); } catch (IOException e) { log.error("Error building map from TLD tag names", e); throw e; } catch (ClassNotFoundException e) { log.error("Error building map from TLD tag names", e); throw e; } catch (Exception e) { return new TagToComponentMap(); } }