List of usage examples for java.io ObjectInputStream readObject
public final Object readObject() throws IOException, ClassNotFoundException
From source file:com.amazon.sqs.javamessaging.message.SQSObjectMessage.java
/** * Deserialize the <code>String</code> into <code>Serializable</code> * object./*from w w w. j ava 2 s. co m*/ */ protected static Serializable deserialize(String serialized) throws JMSException { if (serialized == null) { return null; } Serializable deserializedObject; ObjectInputStream objectInputStream = null; try { byte[] bytes = Base64.decode(serialized); objectInputStream = new ObjectInputStream(new ByteArrayInputStream(bytes)); deserializedObject = (Serializable) objectInputStream.readObject(); } catch (IOException e) { LOG.error("IOException: Message cannot be written", e); throw convertExceptionToMessageFormatException(e); } catch (Exception e) { LOG.error("Unexpected exception: ", e); throw convertExceptionToMessageFormatException(e); } finally { if (objectInputStream != null) { try { objectInputStream.close(); } catch (IOException e) { LOG.warn(e.getMessage()); } } } return deserializedObject; }
From source file:atg.tools.dynunit.test.util.FileUtil.java
/** * @see org.apache.commons.lang3.SerializationUtils#deserialize(java.io.InputStream) *//*from www . j a va 2s .c om*/ @Nullable @Deprecated @SuppressWarnings("unchecked") public static Map<String, Long> deserialize(@NotNull final File file, final long serialTtl) { if (file.exists() && file.lastModified() < System.currentTimeMillis() - serialTtl) { logger.debug("Deleting previous serial {} because it's older than {} ms", file.getPath(), serialTtl); file.delete(); } Map<String, Long> o = null; try { if (file.exists()) { final ObjectInputStream in = new ObjectInputStream(new FileInputStream(file)); try { o = (Map<String, Long>) in.readObject(); } finally { in.close(); } } } catch (Exception e) { logger.catching(e); } if (o == null) { o = new HashMap<String, Long>(); } return o; }
From source file:com.ery.ertc.estorm.util.ToolUtil.java
public static Object deserializeObject(String serStr, boolean isGzip, boolean urlEnCode) throws IOException { byte[] bts = null; if (urlEnCode) { bts = org.apache.commons.codec.binary.Base64.decodeBase64(serStr.getBytes("ISO-8859-1")); } else {//from w ww . j a v a2 s. com bts = serStr.getBytes("ISO-8859-1"); } if (isGzip) bts = GZIPUtils.unzip(bts); ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(bts); ObjectInputStream objectInputStream = new ObjectInputStream(byteArrayInputStream); try { return objectInputStream.readObject(); } catch (ClassNotFoundException e) { e.printStackTrace(); throw new IOException(e); } finally { objectInputStream.close(); byteArrayInputStream.close(); } }
From source file:com.yahoo.bullet.record.AvroBulletRecordTest.java
public static AvroBulletRecord fromRecordBytes(byte[] data) { try {// w ww . j a v a 2s .c o m ObjectInputStream stream = new ObjectInputStream(new ByteArrayInputStream(data)); return (AvroBulletRecord) stream.readObject(); } catch (IOException | ClassNotFoundException e) { throw new RuntimeException(e); } }
From source file:com.vmware.identity.openidconnect.sample.RelyingPartyInstaller.java
static Object readObject(String file) throws IOException, ClassNotFoundException { FileInputStream fis = null;/*from w w w.j ava 2s . c o m*/ ObjectInputStream ois = null; try { fis = new FileInputStream(file); ois = new ObjectInputStream(fis); Object object = ois.readObject(); return object; } finally { if (ois != null) { ois.close(); } } }
From source file:com.couchbase.client.java.transcoder.TranscoderUtils.java
/** * Takes the input content and deserializes it. * * @param content the content to deserialize. * @return the serializable object./*from w w w .java 2s . c o m*/ * @throws Exception if something goes wrong during deserialization. */ public static Serializable deserialize(final ByteBuf content) throws Exception { byte[] serialized = new byte[content.readableBytes()]; content.getBytes(0, serialized); ByteArrayInputStream bis = new ByteArrayInputStream(serialized); ObjectInputStream is = new ObjectInputStream(bis); Serializable deserialized = (Serializable) is.readObject(); is.close(); bis.close(); return deserialized; }
From source file:com.cooksys.postmaster.PostmasterModelSingleton.java
public static PostmasterModelSingleton getInstance() { if (_instance == null) { try {/*from www.j a v a 2s .c om*/ //see if we can read the object from the file first FileInputStream fileInputStream = new FileInputStream(POSTMASTER_DATA_FILE); ObjectInputStream objectInputStream = new ObjectInputStream(fileInputStream); _instance = (PostmasterModelSingleton) objectInputStream.readObject(); //fill in transient variables from their serializable counterparts _instance.createTransientPropertyInstances(); for (ParsedHttpRequest request : _instance.requestList) { _instance.incomingMessagesList.add(request.getRequestLine()); } int index = 0; for (ParsedHttpResponse response : _instance.responseList) { Text defaultResponseText = new Text(response.getName()); if (index == _instance.defaultResponseIndex) { defaultResponseText.setFont(Font.font(null, FontWeight.BOLD, 12)); } _instance.savedResponsesList.add(defaultResponseText); index++; } _instance.messageConsole.set(_instance.messageConsoleSerializable); } catch (FileNotFoundException ex) { //File does not exist, so create a new instance _instance = new PostmasterModelSingleton(); } catch (IOException | ClassNotFoundException ex) { //for these exceptions, just create a new instance Logger.getLogger(PostmasterModelSingleton.class.getName()).log(Level.SEVERE, null, ex); _instance = new PostmasterModelSingleton(); } } return _instance; }
From source file:edu.iu.daal_cov.COVDaalCollectiveMapper.java
private static PartialResult deserializePartialResult(ByteArray byteArray) throws IOException, ClassNotFoundException { /* Create an input stream to deserialize the numeric table from the array */ byte[] buffer = byteArray.get(); ByteArrayInputStream inputByteStream = new ByteArrayInputStream(buffer); ObjectInputStream inputStream = new ObjectInputStream(inputByteStream); /* Create a numeric table object */ PartialResult restoredDataTable = (PartialResult) inputStream.readObject(); restoredDataTable.unpack(daal_Context); return restoredDataTable; }
From source file:edu.harvard.i2b2.Icd9ToSnomedCT.BinResourceFromIcd9ToSnomedCTMap.java
public static HashMap<String, String> deSerializeIcd9CodeToNameMap() throws IOException { logger.debug("loading map.."); HashMap<String, String> map = null; ObjectInputStream ois = null; InputStream fis = null;/*from www. j a va 2s . co m*/ try { fis = BinResourceFromIcd9ToSnomedCTMap.class.getResourceAsStream(binFileName); if (fis == null) logger.error("mapping file not found:" + binFileName); ois = new ObjectInputStream(fis); map = (HashMap<String, String>) ois.readObject(); } catch (Exception e) { logger.error(e.getMessage(), e); } finally { ois.close(); fis.close(); } logger.debug("..loaded"); return map; }
From source file:com.stgmastek.core.logic.ExecutionOrder.java
/** * Reads the saved state of the batch for revision runs * If the current batch number it 1000 and revision is 5, * then this method would look for saved state of batch 1000 * with revision (5 - 1) i.e. '1000_4.savepoint' * //from ww w . j av a 2 s.com * @param batchContext * The context for the batch * @throws BatchException * Any exception thrown during reading of the serialized file */ public static synchronized void updateBatchState(BatchContext batchContext) throws BatchException { BatchInfo newBatchInfo = batchContext.getBatchInfo(); String savepointFilePath = Configurations.getConfigurations().getConfigurations("CORE", "SAVEPOINT", "DIRECTORY"); String savePointFile = FilenameUtils.concat(savepointFilePath, newBatchInfo.getBatchNo() + "_" + (newBatchInfo.getBatchRevNo() - 1) + ".savepoint"); if (logger.isDebugEnabled()) { logger.debug("Reading the saved state from file : " + savePointFile); } FileInputStream fis = null; try { //Check whether the file exists File f = new File(savePointFile); if (!f.exists()) throw new BatchException("Cannot locate the the save point file named :" + savePointFile); fis = new FileInputStream(f); ObjectInputStream ois = new ObjectInputStream(fis); BatchInfo savedBatchInfo = (BatchInfo) ois.readObject(); newBatchInfo.setOrderedMap(savedBatchInfo.getOrderedMap()); newBatchInfo.setProgressLevelAtLastSavePoint( (ProgressLevel) savedBatchInfo.getProgressLevelAtLastSavePoint()); //This object is different but still cloned. newBatchInfo.setBatchRunDate(savedBatchInfo.getBatchRunDate()); newBatchInfo.setDateRun(savedBatchInfo.isDateRun()); if (logger.isDebugEnabled()) { logger.debug( "Last batch saved state is " + savedBatchInfo.getProgressLevelAtLastSavePoint().toString()); } //Set the ExecutionStatus in the ProgressLevel ExecutionStatus savedExecutionStatus = newBatchInfo.getProgressLevelAtLastSavePoint() .getExecutionStatus(); ProgressLevel.getProgressLevel(newBatchInfo.getBatchNo()) .setExecutionStatus(savedExecutionStatus.getEntity(), savedExecutionStatus.getStageCode()); fis.close(); fis = null; ois.close(); ois = null; } catch (FileNotFoundException e) { logger.error(e); throw new BatchException(e.getMessage(), e); } catch (IOException e) { logger.error(e); throw new BatchException(e.getMessage(), e); } catch (ClassNotFoundException e) { logger.error(e); throw new BatchException(e.getMessage(), e); } finally { if (fis != null) { try { fis.close(); } catch (IOException e) { } } } }