List of usage examples for java.io ObjectInputStream close
public void close() throws IOException
From source file:com.ps.cc.action.LoginAction.java
@Override public void run(HttpServletRequest request, HttpServletResponse response) throws ActionException { try {// www .j av a 2 s . c om HttpSession session = request.getSession(); long companyId = PortalUtil.getCompanyId(request); long userId = PortalUtil.getUserId(request); User user = UserLocalServiceUtil.getUserById(companyId, userId); TwilioConfiguration twilioConfiguration = new TwilioConfiguration(); try { File file = new File("twilioConfiguration.txt"); ObjectInputStream in = new ObjectInputStream(new FileInputStream(file)); twilioConfiguration = (TwilioConfiguration) in.readObject(); in.close(); } catch (Exception ex) { //didn't exist... } String acctSid = twilioConfiguration.getAcctSid(); String authToken = twilioConfiguration.getAuthToken(); String appSid = twilioConfiguration.getAppSid(); TwilioCapability capability = new TwilioCapability(acctSid, authToken); capability.allowEventStream(null); capability.allowClientIncoming(user.getScreenName()); Map<String, String> params = new HashMap<String, String>(); params.put("portraitId", String.valueOf(user.getPortraitId())); capability.allowClientOutgoing(appSid, params); String token = capability.generateToken(); //Now we will share the json object with everyone session.setAttribute("USER_twilio_token", token); if (_log.isInfoEnabled()) { _log.info("Twilio Token Generated: " + token + " (" + user.getScreenName() + ")"); } } catch (Exception ex) { _log.error("Error during post login", ex); } }
From source file:com.joliciel.talismane.lexicon.LexiconDeserializer.java
public PosTaggerLexicon deserializeLexiconFile(ObjectInputStream ois) { PosTaggerLexicon memoryBase = null;/*w w w .j a v a 2 s . c o m*/ try { memoryBase = (PosTaggerLexicon) ois.readObject(); ois.close(); } catch (IOException ioe) { throw new RuntimeException(ioe); } catch (ClassNotFoundException cnfe) { throw new RuntimeException(cnfe); } return memoryBase; }
From source file:org.blanco.techmun.android.cproviders.MesasFetcher.java
private Mesas tryToLoadFromCache(Context context) { try {// w w w . j ava 2 s . c o m FileInputStream mesasFIS = context.openFileInput("mesas.df"); ObjectInputStream mesasOIS = new ObjectInputStream(mesasFIS); Mesas result = (Mesas) mesasOIS.readObject(); mesasOIS.close(); return result; } catch (IOException e) { Log.e("tachmun", "Error opening cache file for mesas in content provider. " + "No cache will be restored", e); return null; } catch (ClassNotFoundException e) { Log.e("tachmun", "Error in cache file for mesas in content provider. " + "Something is there but is not a Mesas object. Cache no restored", e); return null; } }
From source file:org.blanco.techmun.android.cproviders.EventosFetcher.java
private Eventos tryToLoadFromCache(Context context, long mesaId) { try {/*from w ww.ja v a 2s .c o m*/ FileInputStream mesasFIS = context.openFileInput("eventos_" + mesaId + ".df"); ObjectInputStream mesasOIS = new ObjectInputStream(mesasFIS); Eventos result = (Eventos) mesasOIS.readObject(); mesasOIS.close(); return result; } catch (IOException e) { Log.e("tachmun", "Error opening cache file for mesas in content provider. " + "No cache will be restored", e); return null; } catch (ClassNotFoundException e) { Log.e("tachmun", "Error in cache file for mesas in content provider. " + "Something is there but is not a Mesas object. Cache no restored", e); return null; } }
From source file:de.tudarmstadt.ukp.dkpro.tc.ml.report.BatchPredictionReport.java
@Override public void execute() throws Exception { StorageService store = getContext().getStorageService(); FlexTable<String> table = FlexTable.forClass(String.class); for (TaskContextMetadata subcontext : getSubtasks()) { // FIXME this is a bad hack if (subcontext.getType().contains("ExtractFeaturesAndPredictTask")) { Map<String, String> discriminatorsMap = store .retrieveBinary(subcontext.getId(), Task.DISCRIMINATORS_KEY, new PropertiesAdapter()) .getMap();// w ww.j a va 2s .com // deserialize file FileInputStream f = new FileInputStream( store.getStorageFolder(subcontext.getId(), 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: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 av a 2 s . co m 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();/* w w w .j av a2s.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:com.sun.j2ee.blueprints.waf.controller.web.flow.handlers.ClientStateFlowHandler.java
public String processFlow(HttpServletRequest request) throws FlowHandlerException { String forwardScreen = request.getParameter("referring_screen"); // de-serialize the request attributes. Map params = (Map) request.getParameterMap(); HashMap newParams = new HashMap(); String cacheId = request.getParameter("cacheId"); if (!params.isEmpty()) { Iterator it = params.keySet().iterator(); // put the request attributes stored in the session in the request while (it.hasNext()) { String key = (String) it.next(); if (key.startsWith(cacheId + "_attribute_")) { String[] values = (String[]) params.get(key); String valueString = values[0]; byte[] bytes = Base64.decode(valueString.getBytes()); try { ObjectInputStream ois = new ObjectInputStream(new ByteArrayInputStream(bytes)); Object requestObject = requestObject = ois.readObject(); ois.close(); // put the de-serialized object back into the request String requestObjectKey = key.substring((cacheId + "_attribute_").length(), key.length()); request.setAttribute(requestObjectKey, requestObject); } catch (java.io.OptionalDataException ode) { System.err.println("ClientCacheLinkFlowHandler caught: " + ode); } catch (java.lang.ClassNotFoundException cnfe) { System.err.println("ClientCacheLinkFlowHandler caught: " + cnfe); } catch (java.io.IOException iox) { System.err.println("ClientCacheLinkFlowHandler caught: " + iox); }/*from ww w. ja v a 2 s .co m*/ } } } return forwardScreen; }
From source file:net.schweerelos.parrot.ui.NodeWrapperPersistentLayoutImpl.java
@SuppressWarnings("unchecked") @Override/*from w w w . j a v a 2 s .c o m*/ public synchronized void restore(String fileName) throws IOException, ClassNotFoundException { ObjectInputStream ois = new ObjectInputStream(new FileInputStream(fileName)); uriToNodeLocation = (Map<String, Point>) ois.readObject(); ois.close(); initializeLocations(); locked = true; fireStateChanged(); }
From source file:com.joliciel.lefff.LefffMemoryLoader.java
public LefffMemoryBase deserializeMemoryBase(ZipInputStream zis) { LefffMemoryBase memoryBase = null;//w w w. jav a 2s. c om MONITOR.startTask("deserializeMemoryBase"); try { ZipEntry zipEntry; if ((zipEntry = zis.getNextEntry()) != null) { LOG.debug("Scanning zip entry " + zipEntry.getName()); ObjectInputStream in = new ObjectInputStream(zis); memoryBase = (LefffMemoryBase) in.readObject(); zis.closeEntry(); in.close(); } else { throw new RuntimeException("No zip entry in input stream"); } } catch (IOException ioe) { throw new RuntimeException(ioe); } catch (ClassNotFoundException cnfe) { throw new RuntimeException(cnfe); } finally { MONITOR.endTask("deserializeMemoryBase"); } Map<PosTagSet, LefffPosTagMapper> posTagMappers = memoryBase.getPosTagMappers(); PosTagSet posTagSet = posTagMappers.keySet().iterator().next(); memoryBase.setPosTagSet(posTagSet); return memoryBase; }