List of usage examples for java.io ObjectInputStream close
public void close() throws IOException
From source file:com.tempescope.wunderground.WeatherLocationManager.java
public static WeatherLocationManager getManager(File file) { if (!file.exists()) { WeatherLocationManager manager = new WeatherLocationManager(); manager.file = file;//from w ww . ja v a 2s. co m return manager; } try { ObjectInputStream in = new ObjectInputStream(new BufferedInputStream(new FileInputStream(file))); WeatherLocationManager manager = (WeatherLocationManager) in.readObject(); in.close(); manager.file = file; return manager; } catch (IOException e) { e.printStackTrace(); } catch (ClassNotFoundException e) { // TODO Auto-generated catch block e.printStackTrace(); } return null; }
From source file:com.mnt.base.util.SerializeUtil.java
public static Object deSerialize(byte[] source) { Object result;/*from w w w.j av a 2 s .com*/ if (CommonUtil.isEmpty(source)) { result = null; } else { ByteArrayInputStream bais = new ByteArrayInputStream(source); try { ObjectInputStream ois = new ObjectInputStream(bais); result = ois.readObject(); ois.close(); } catch (Exception e) { log.error("error while open byte array input stream.", e); result = null; } } return result; }
From source file:com.ibm.watson.developer_cloud.professor_languo.ingestion.indexing.StackExchangeThreadSerializer.java
public static StackExchangeThread deserializeThreadFromBinFile(String binFile) throws IngestionException { Object deserializedObj = null; try {//from ww w .j ava2 s . c om InputStream binIn = new FileInputStream(binFile); ObjectInputStream in = new ObjectInputStream(binIn); deserializedObj = in.readObject(); in.close(); binIn.close(); } catch (IOException | ClassNotFoundException e) { throw new IngestionException(e); } return (StackExchangeThread) deserializedObj; }
From source file:com.ibm.watson.developer_cloud.professor_languo.ingestion.indexing.StackExchangeThreadSerializer.java
/** * reproduce the Java Object with the byte array * /* w ww .j a v a 2 s .com*/ * @param binCode - the byte array for that Java Object * @return the original Java Object before serialization * @throws IngestionException */ public static Object deserializeObjFromBinArr(byte[] binCode) throws IngestionException { Object deserializedObj = null; ByteArrayInputStream binIn = new ByteArrayInputStream(binCode); try { ObjectInputStream in = new ObjectInputStream(binIn); deserializedObj = in.readObject(); in.close(); binIn.close(); } catch (IOException | ClassNotFoundException e) { throw new IngestionException(e); } return deserializedObj; }
From source file:com.ibm.watson.developer_cloud.professor_languo.ingestion.indexing.StackExchangeThreadSerializer.java
/** * reproduce the StackExchangeThread with the byte array * /*from w w w . j a v a 2s . c om*/ * @param binCode - the byte array for that StackExchangeThread * @return the original StackExchangeThread before serialization * @throws IngestionException */ public static StackExchangeThread deserializeThreadFromBinArr(byte[] binCode) throws IngestionException { Object deserializedObj = null; ByteArrayInputStream binIn = new ByteArrayInputStream(binCode); try { ObjectInputStream in = new ObjectInputStream(binIn); deserializedObj = in.readObject(); in.close(); binIn.close(); } catch (IOException | ClassNotFoundException e) { throw new IngestionException(e); } return (StackExchangeThread) deserializedObj; }
From source file:RedisCache.java
/** Read the object from Base64 string. */ private static Object fromString(String s) throws IOException, ClassNotFoundException { byte[] data = Base64.decodeBase64(s); ObjectInputStream ois = new ObjectInputStream(new ByteArrayInputStream(data)); Object o = ois.readObject();/*w ww . jav a 2s . c o m*/ ois.close(); return o; }
From source file:Main.java
public static Object readSerializableObjectFromFile(FileInputStream fileIn) { Object b = null;/* w ww . ja va 2 s.c om*/ ObjectInputStream in = null; try { in = new ObjectInputStream(fileIn); b = in.readObject(); } catch (Exception e) { e.printStackTrace(); } finally { if (in != null) { try { in.close(); } catch (IOException e) { e.printStackTrace(); } } } return b; }
From source file:com.db4o.sync4o.SyncKey.java
static public SyncKey fromEncodedString(String s) throws Exception { ObjectInputStream ois = new ObjectInputStream(new ByteArrayInputStream(Base64.decodeBase64(s.getBytes()))); SyncKey key = (SyncKey) ois.readObject(); ois.close(); return key;//from ww w . ja v a 2 s . co m }
From source file:com.taobao.tair.etc.TranscoderUtil.java
public static Object deserialize(byte[] in) { Object rv = null;/*from w w w . j a v a 2 s . c om*/ try { if (in != null) { ByteArrayInputStream bis = new ByteArrayInputStream(in); ObjectInputStream is = new ObjectInputStream(bis); rv = is.readObject(); is.close(); bis.close(); } } catch (Exception e) { throw new RuntimeException("deserialize failed", e); } return rv; }
From source file:Main.java
@SuppressWarnings("unchecked") static <T extends Serializable> T fromBlob(Class<T> clazz, byte[] blob) throws IOException, ClassNotFoundException { T result = null;//from w ww . j a v a 2s. co m ObjectInputStream ois = null; try { ByteArrayInputStream bos = new ByteArrayInputStream(blob); ois = new ObjectInputStream(bos); result = (T) ois.readObject(); } finally { if (ois != null) { try { ois.close(); } catch (IOException e) { e.printStackTrace(); } } } return result; }