List of usage examples for java.io ObjectInputStream close
public void close() throws IOException
From source file:gnomezgrave.gsyncj.auth.Profile.java
public static Profile loadProfileSettings(String fileName) throws IOException, ClassNotFoundException { ObjectInputStream oi = new ObjectInputStream(new FileInputStream(fileName)); Profile profile = (Profile) oi.readObject(); oi.close(); return profile; }
From source file:jp.queuelinker.system.util.SerializeUtil.java
/** * Deserializes an object from a byte array by using the Java standard serialization mechanism. * @param data/* ww w . jav a2 s . com*/ * @param offset * @param length * @return */ public static Object deserialize(final byte[] data, final int offset, final int length) { Object ret = null; ByteArrayInputStream byteStream = new ByteArrayInputStream(data, offset, length); try { ObjectInputStream objStream = new ObjectInputStream(byteStream); ret = objStream.readObject(); objStream.close(); } catch (IOException e) { logger.error("Exception: " + e); } catch (ClassNotFoundException e) { logger.error("Exception: " + e); } return ret; }
From source file:Util.java
/** * Reads a serialized object from a file that has been compressed using gzip. * You probably want to use {@link #readObject} instead, because it will automatically guess * from the extension whether the file is compressed, and call this method if necessary. * @param f Compressed file to read object from * @see #readObject//from w w w .j a va 2 s.c o m */ public static Object readGzippedObject(File f) { try { ObjectInputStream ois = new ObjectInputStream( new BufferedInputStream(new GZIPInputStream(new FileInputStream(f)))); Object obj = ois.readObject(); ois.close(); return obj; } catch (IOException e) { throw new RuntimeException(e); } catch (ClassNotFoundException e) { throw new RuntimeException(e); } }
From source file:org.terracotta.management.cli.rest.HttpServices.java
private static Object load(String filename) throws IOException, ClassNotFoundException { File path = new File(System.getProperty("user.home"), ".tc/mgmt"); File file = new File(path, filename); if (!file.exists()) { return null; }// w w w. j ava 2s .c o m ObjectInputStream ois = new ObjectInputStream(new FileInputStream(file)); try { return ois.readObject(); } finally { ois.close(); } }
From source file:conceptnet.ConceptBuilder.java
public static Concept readConcept(String name) { Concept c = null;// www . j ava 2s . c o m String path = conceptPath + name; File f = new File(path); if (!f.exists() || f.isDirectory()) { return null; } try { ObjectInputStream ois = new ObjectInputStream(new FileInputStream(f)); c = (Concept) (ois.readObject()); ois.close(); } catch (Exception e) { e.printStackTrace(); } return c; }
From source file:gnomezgrave.gsyncj.auth.ProfileSettings.java
public static ProfileSettings loadProfileSettings(String fileName) throws IOException, ClassNotFoundException { ObjectInputStream oi = new ObjectInputStream(new FileInputStream(fileName)); ProfileSettings profileSettings = (ProfileSettings) oi.readObject(); oi.close(); return profileSettings; }
From source file:de.kbs.acavis.service.SerializationHelper.java
public static PublicationIdentifier deserializePublicationIdentifier(String serialization) throws IOException, ClassNotFoundException { byte b[] = serialization.getBytes(); ByteArrayInputStream bi = new ByteArrayInputStream(b); ObjectInputStream si = new ObjectInputStream(bi); PublicationIdentifier identifier = (PublicationIdentifier) si.readObject(); si.close(); bi.close();//from w w w. j ava 2 s. c om return identifier; }
From source file:edu.tufts.vue.util.Encryption.java
private static synchronized Key getKey() { try {/* w ww.ja v a2 s.co m*/ if (key == null) { File keyFile = new File( VueUtil.getDefaultUserFolder().getAbsolutePath() + File.separator + KEY_FILE); if (keyFile.exists()) { ObjectInputStream is = new ObjectInputStream(new FileInputStream(keyFile)); key = (Key) is.readObject(); is.close(); } else { key = KeyGenerator.getInstance(algorithm).generateKey(); ObjectOutputStream os = new ObjectOutputStream(new FileOutputStream(keyFile)); os.writeObject(key); os.close(); } return key; } else { return key; } } catch (Exception ex) { ex.printStackTrace(); return null; } }
From source file:Main.java
public static Object convertByteArrayToObject(byte[] bytes) throws IOException, ClassNotFoundException { ObjectInputStream is = null; ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(bytes); is = new ObjectInputStream(new BufferedInputStream(byteArrayInputStream)); Object obj = is.readObject(); is.close(); return obj;/*www. j a v a 2 s . c o m*/ }
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 w w. j a va2s . co 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; }