List of usage examples for java.io ObjectInputStream ObjectInputStream
public ObjectInputStream(InputStream in) throws IOException
From source file:gov.nih.nci.ncicb.tcga.dcc.dam.bean.QuartzQueueJobDetails.java
/** * Extract estimatedUncompressedSize and jobWSSubmissionDate from the given <code>Blob</code> * (which is expected to be a serialized <code>FilePackagerBean</code>) and populates this bean's properties * * @param jobData the serialized <code>FilePackagerBean</code> *///w w w . j a va 2 s. c om private void extractData(final Blob jobData) { // Default values that will be used in case an exception is raised Long estimatedUncompressedSize = null; Date jobWSSubmissionDate = null; if (jobData != null) { ObjectInputStream objectInputStream = null; try { //noinspection IOResourceOpenedButNotSafelyClosed objectInputStream = new ObjectInputStream(jobData.getBinaryStream()); final JobDataMap jobDataMap = (JobDataMap) objectInputStream.readObject(); final FilePackagerBean filePackagerBean = (FilePackagerBean) jobDataMap.get(JobDelegate.DATA_BEAN); ; estimatedUncompressedSize = filePackagerBean.getEstimatedUncompressedSize(); jobWSSubmissionDate = filePackagerBean.getJobWSSubmissionDate(); } catch (final IOException e) { } catch (final SQLException e) { } catch (final ClassNotFoundException e) { } finally { IOUtils.closeQuietly(objectInputStream); } } // Set this bean's fields setEstimatedUncompressedSize(estimatedUncompressedSize); setJobWSSubmissionDate(jobWSSubmissionDate); }
From source file:net.larry1123.util.api.world.blocks.BlockPropertyStorage.java
public BlockPropertyStorage(String json) throws ParseException, ClassNotFoundException { // TODO add a bit of validation JSONParser parser = new JSONParser(); JSONObject jsonObject = (JSONObject) parser.parse(json); name = (String) jsonObject.get("keyName"); blockTypeMachineName = (String) jsonObject.get("blockTypeMachineName"); blockTypeData = (Short) jsonObject.get("blockTypeData"); try {//ww w .j a va2 s .co m byte[] bytes = Base64.decodeBase64((String) jsonObject.get("value")); ObjectInputStream objectInputStream = new ObjectInputStream(new ByteArrayInputStream(bytes)); value = (Comparable) objectInputStream.readObject(); } catch (IOException e) { throw new Error(); // Not sure how that could happen but I will see what I may need to do } }
From source file:edu.harvard.i2b2.loinc.BinResourceFromLoincData.java
public static HashMap<String, String> deSerializeLoincCodeToNameMap() throws IOException { HashMap<String, String> map = null; ObjectInputStream ois = null; InputStream fis = null;// ww w.j a v a 2 s . c om try { fis = BinResourceFromLoincData.class.getResourceAsStream("/loinc/loincCodeToNameMap.bin"); ois = new ObjectInputStream(fis); map = (HashMap<String, String>) ois.readObject(); } catch (Exception e) { logger.error(e.getMessage(), e); } finally { ois.close(); fis.close(); } return map; }
From source file:com.bitranger.parknshop.util.ObjUtils.java
public static Object fromBytes(byte[] plainObj) { Object var = null; ByteArrayInputStream baIS = new ByteArrayInputStream(plainObj); ObjectInputStream objIS = null; try {//from ww w .j a v a2 s . c om objIS = new ObjectInputStream(baIS); var = objIS.readObject(); } catch (Exception e) { throw new RuntimeException(e.getMessage() + "\n\tCAUSE: " + e.getCause(), e); } finally { try { baIS.close(); if (objIS != null) { objIS.close(); } } catch (IOException e) { throw new RuntimeException(e.getMessage() + "\n\tCAUSE: " + e.getCause(), e); } } return var; }
From source file:de.tudarmstadt.ukp.dkpro.tc.weka.report.WekaBatchPredictionReport.java
@Override public void execute() throws Exception { StorageService store = getContext().getStorageService(); FlexTable<String> table = FlexTable.forClass(String.class); for (TaskContextMetadata subcontext : getSubtasks()) { if (subcontext.getType().startsWith(ExtractFeaturesAndPredictTask.class.getName())) { Map<String, String> discriminatorsMap = store .retrieveBinary(subcontext.getId(), Task.DISCRIMINATORS_KEY, new PropertiesAdapter()) .getMap();/*from ww w . j a v a 2 s . c o m*/ // deserialize file FileInputStream f = new FileInputStream(store.getStorageFolder(subcontext.getId(), ExtractFeaturesAndPredictConnector.PREDICTION_MAP_FILE_NAME)); ObjectInputStream s = new ObjectInputStream(f); Map<String, List<String>> resultMap = (Map<String, List<String>>) s.readObject(); s.close(); // write one file per batch // in files: one line per instance for (String id : resultMap.keySet()) { Map<String, String> row = new HashMap<String, String>(); row.put(predicted_value, StringUtils.join(resultMap.get(id), ",")); table.addRow(id, row); } // create a separate output folder for each execution of // ExtractFeaturesAndPredictTask, 36 is the length of the UUID hash File contextFolder = store.getStorageFolder(getContext().getId(), subcontext.getId().substring(subcontext.getId().length() - 36)); // Excel cannot cope with more than 255 columns if (table.getColumnIds().length <= 255) { getContext().storeBinary(contextFolder.getName() + System.getProperty("file.separator") + report_name + SUFFIX_EXCEL, table.getExcelWriter()); } getContext().storeBinary( contextFolder.getName() + System.getProperty("file.separator") + report_name + SUFFIX_CSV, table.getCsvWriter()); getContext().storeBinary( contextFolder.getName() + System.getProperty("file.separator") + Task.DISCRIMINATORS_KEY, new PropertiesAdapter(discriminatorsMap)); } } // output the location of the batch evaluation folder // otherwise it might be hard for novice users to locate this File dummyFolder = store.getStorageFolder(getContext().getId(), "dummy"); // TODO can we also do this without creating and deleting the dummy folder? getContext().getLoggingService().message(getContextLabel(), "Storing detailed results in:\n" + dummyFolder.getParent() + "\n"); dummyFolder.delete(); }
From source file:common.services.generic.GenericCacheService.java
@Override public T getFromFile() { File f = new File(path, "cache.tmp"); if (!f.exists()) return null; try {//w w w .j a va 2s . co m FileInputStream fi = new FileInputStream(f); ObjectInputStream si = new ObjectInputStream(fi); T tmp = (T) si.readObject(); si.close(); fi.close(); return tmp; } catch (IOException ex) { logger.error("failed to load cache path = " + path, ex); return null; } catch (ClassNotFoundException ex) { logger.error("failed to load cache path = " + path, ex); return null; } }
From source file:PersisTest.java
public void actionPerformed(ActionEvent e) { if (e.getSource() == clearBtn) { // Repaint with an empty display list. displayList = new ArrayList(); repaint();/*from w ww . j a v a2s. c o m*/ } else if (e.getSource() == saveBtn) { // Write display list array list to an object output stream. try { FileOutputStream fos = new FileOutputStream(pathname); ObjectOutputStream oos = new ObjectOutputStream(fos); oos.writeObject(displayList); oos.flush(); oos.close(); fos.close(); } catch (IOException ex) { System.err.println("Trouble writing display list array list"); } } else if (e.getSource() == restoreBtn) { // Read a new display list array list from an object input stream. try { FileInputStream fis = new FileInputStream(pathname); ObjectInputStream ois = new ObjectInputStream(fis); displayList = (ArrayList) (ois.readObject()); ois.close(); fis.close(); repaint(); } catch (ClassNotFoundException ex) { System.err.println("Trouble reading display list array list"); } catch (IOException ex) { System.err.println("Trouble reading display list array list"); } } else if (e.getSource() == quitBtn) { System.exit(0); } }
From source file:net.sf.ehcache.distribution.EventMessageTest.java
/** * test serialization and deserialization of EventMessage. *///from www. j a v a2 s .c om public void testSerialization() throws IOException, ClassNotFoundException { EventMessage eventMessage = new EventMessage(EventMessage.PUT, "key", new Element("key", "element")); ByteArrayOutputStream bout = new ByteArrayOutputStream(); ObjectOutputStream oos = new ObjectOutputStream(bout); oos.writeObject(eventMessage); byte[] serializedValue = bout.toByteArray(); oos.close(); EventMessage eventMessage2 = null; ByteArrayInputStream bin = new ByteArrayInputStream(serializedValue); ObjectInputStream ois = new ObjectInputStream(bin); eventMessage2 = (EventMessage) ois.readObject(); ois.close(); //Check after Serialization assertEquals("key", eventMessage2.getSerializableKey()); assertEquals("element", eventMessage2.getElement().getObjectValue()); assertEquals(EventMessage.PUT, eventMessage2.getEvent()); assertTrue(eventMessage2.isValid()); }
From source file:com.oprisnik.semdroid.utils.FileUtils.java
public static Object loadObjectFromStream(InputStream input) throws ClassNotFoundException, IOException { ObjectInputStream ois = null; Object obj = null;/* w w w.j a v a2 s.co m*/ try { ois = new ObjectInputStream(input); obj = ois.readObject(); } finally { IOUtils.closeQuietly(ois); } return obj; }
From source file:ddf.camel.component.catalog.content.FileSystemDataAccessObject.java
public Object loadFromPersistence(String storePath, String suffix, String key) { String pathString = storePath + key + suffix; File file = new File(pathString); if (!file.exists()) { return null; }/* w w w . jav a 2 s . c o m*/ try (InputStream inputStream = new FileInputStream(pathString)) { InputStream buffer = new BufferedInputStream(inputStream); try (ObjectInput input = new ObjectInputStream(buffer)) { return input.readObject(); } } catch (IOException e) { LOGGER.debug("IOException", e); } catch (ClassNotFoundException e) { LOGGER.debug("ClassNotFoundException", e); } return null; }