List of usage examples for java.io ObjectInputStream ObjectInputStream
public ObjectInputStream(InputStream in) throws IOException
From source file:org.sample.readerwriter.MyReader.java
@Override public MyObject readFrom(Class<MyObject> type, Type type1, Annotation[] antns, MediaType mt, MultivaluedMap<String, String> mm, InputStream in) throws IOException, WebApplicationException { try {//from w w w. j av a 2 s . c o m ObjectInputStream ois = new ObjectInputStream(in); return (MyObject) ois.readObject(); } catch (ClassNotFoundException ex) { Logger.getLogger(MyReader.class.getName()).log(Level.SEVERE, null, ex); } return null; }
From source file:com.github.tell.codec.Base64Serializer.java
public Serializable decodeFromString(final String encoded) throws IOException, ClassNotFoundException { final byte[] decoded = Base64.decodeBase64(encoded); final ByteArrayInputStream bais = new ByteArrayInputStream(decoded); final ObjectInputStream ois = new ObjectInputStream(bais); return (Serializable) ois.readObject(); }
From source file:com.plexobject.testplayer.dao.jdbc.GenericDaoJdbc.java
protected static Object toObject(Blob blob) { try {//from ww w .j a v a 2 s . com if (blob == null) return null; InputStream in = blob.getBinaryStream(); if (in == null) return null; int c; ByteArrayOutputStream out = new ByteArrayOutputStream(2048); while ((c = in.read()) != -1) { out.write(c); } byte[] b = out.toByteArray(); if (b.length == 0) return null; ObjectInputStream ois = new ObjectInputStream(new ByteArrayInputStream(b)); Object object = ois.readObject(); ois.close(); return object; } catch (RuntimeException e) { throw e; } catch (Exception e) { throw new DaoException("Failed to deserialize", e); } }
From source file:com.joliciel.talismane.machineLearning.perceptron.PerceptronClassificationModel.java
@Override public void loadModelFromStream(InputStream inputStream) { try {//from w w w. j av a2 s . c o m ObjectInputStream in = new ObjectInputStream(inputStream); params = (PerceptronModelParameters) in.readObject(); } catch (IOException e) { LogUtils.logError(LOG, e); throw new RuntimeException(e); } catch (ClassNotFoundException e) { LogUtils.logError(LOG, e); throw new RuntimeException(e); } }
From source file:com.sec.ose.osi.thread.job.identify.data.IdentifyErrorQueue.java
private void init(String userID) { identifyQueueErrorFileName = DAT_FILE_DIRECTORY + "/error_" + userID + ".dat"; File dir = new File(DAT_FILE_DIRECTORY); if (!dir.exists()) { if (dir.mkdirs() == false) { System.err.println("Can not create folder"); }/* w ww . jav a2 s . co m*/ } File file = new File(identifyQueueErrorFileName); FileInputStream fis = null; ObjectInputStream oisReader = null; try { if (!file.exists()) { file.createNewFile(); } else { fis = new FileInputStream(identifyQueueErrorFileName); if (fis != null && fis.available() > 0) { oisReader = new ObjectInputStream(fis); IdentifyData tmpIdentifiedData; while ((tmpIdentifiedData = (IdentifyData) oisReader.readObject()) != null) { log.debug("read from File : \n" + tmpIdentifiedData + "\n - queueSize: " + size()); identifyDataQueueError.add(tmpIdentifiedData); log.debug("add - queueSize: " + size()); } } } } catch (IOException e) { log.debug("The end of the stream/block data has been reached"); } catch (Exception e) { log.warn(e); } finally { try { if (oisReader != null) { try { oisReader.close(); } catch (Exception e) { log.debug(e); } } if (fis != null) { try { fis.close(); } catch (Exception e) { log.debug(e); } } } catch (Exception e) { log.warn(e); } } updateDatFileByIdentifyErrorQueue(); }
From source file:com.backbase.expert.extensions.sushi.util.Base64Serializer.java
@Override public Object readObject(String string) { ObjectInputStream ois = null; Object obj = null;// w w w . ja v a 2s.c o m try { String base64String = string; byte[] data = Base64.decodeBase64(base64String); ois = new ObjectInputStream(new ByteArrayInputStream(data)); obj = ois.readObject(); } catch (Exception e) { LOG.error("Could not decode the provided base64 string. Stream will be closed, and null is returned.", e); } finally { IOUtils.closeQuietly(ois); } return obj; }
From source file:org.sakaiproject.orm.ibatis.support.BlobSerializableTypeHandler.java
protected Object getResultInternal(ResultSet rs, int index, LobHandler lobHandler) throws SQLException, IOException { InputStream is = lobHandler.getBlobAsBinaryStream(rs, index); if (is != null) { ObjectInputStream ois = new ObjectInputStream(is); try {//from w w w . j a va2s .c o m return ois.readObject(); } catch (ClassNotFoundException ex) { throw new SQLException("Could not deserialize BLOB contents: " + ex.getMessage()); } finally { ois.close(); } } else { return null; } }
From source file:com.l2jfree.gameserver.instancemanager.GameTimeManager.java
private GregorianCalendar loadData() { if (!Config.DATETIME_SAVECAL) return null; ObjectInputStream is = null;/* w ww.j a va2s . c om*/ try { is = new ObjectInputStream(new FileInputStream("data/serial/clock.dat")); return (GregorianCalendar) is.readObject(); } catch (Exception e) { _log.warn("", e); return null; } finally { IOUtils.closeQuietly(is); } }
From source file:com.hazelcast.simulator.utils.FileUtils.java
@SuppressWarnings("unchecked") public static <E> E readObject(File file) { FileInputStream stream = null; ObjectInputStream inputStream = null; try {//from ww w. ja v a2 s .c o m stream = new FileInputStream(file); inputStream = new ObjectInputStream(stream); return (E) inputStream.readObject(); } catch (IOException e) { throw new FileUtilsException(e); } catch (ClassNotFoundException e) { throw new FileUtilsException(e); } finally { closeQuietly(inputStream); closeQuietly(stream); } }
From source file:com.cloudera.recordservice.hcatalog.common.HCatRSUtil.java
public static Object deserialize(String str) throws IOException { if (str == null || str.length() == 0) { return null; }/*from www . jav a2 s .com*/ try { ByteArrayInputStream serialObj = new ByteArrayInputStream(decodeBytes(str)); ObjectInputStream objStream = new ObjectInputStream(serialObj); return objStream.readObject(); } catch (Exception e) { throw new IOException("Deserialization error: " + e.getMessage(), e); } }