List of usage examples for java.io ObjectInputStream ObjectInputStream
public ObjectInputStream(InputStream in) throws IOException
From source file:com.limegroup.gnutella.licenses.LicenseCache.java
/** * Loads values from cache file, if available *///from w w w .j a va 2s. c o m private void deserialize() { ObjectInputStream ois = null; try { if (!CACHE_FILE.exists()) { // finally-block will initialize maps return; } ois = new ObjectInputStream(new BufferedInputStream(new FileInputStream(CACHE_FILE))); Object o = ois.readObject(); if (o != null) licenses = GenericsUtils.scanForMap(o, URI.class, License.class, GenericsUtils.ScanMode.REMOVE); o = ois.readObject(); if (o != null) data = GenericsUtils.scanForMap(o, Object.class, Object.class, GenericsUtils.ScanMode.REMOVE); removeOldEntries(); } catch (Throwable t) { LOG.error("Can't read licenses", t); } finally { IOUtils.close(ois); if (licenses == null) licenses = new HashMap<URI, License>(); if (data == null) data = new HashMap<Object, Object>(); } }
From source file:com.machinepublishers.jbrowserdriver.HttpCache.java
/** * {@inheritDoc}/* w w w. j av a2 s. c om*/ */ @Override public HttpCacheEntry getEntry(String key) throws IOException { try (Lock lock = new Lock(new File(cacheDir, DigestUtils.sha1Hex(key)), true, false)) { BufferedInputStream bufferIn = new BufferedInputStream(lock.streamIn); try (ObjectInputStream objectIn = new ObjectInputStream(bufferIn)) { return (HttpCacheEntry) objectIn.readObject(); } catch (Throwable t) { LogsServer.instance().exception(t); } } catch (FileNotFoundException e) { return null; } return null; }
From source file:net.sf.farrago.server.FarragoServletCommandSink.java
private void handleRequest(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse) throws ServletException { ObjectInputStream ois = null; ObjectOutputStream oos = null; try {//from w w w. j a va 2s .c om // Get the method to execute String method = httpServletRequest.getHeader(ServletCommandSinkIdentifier.METHOD_IDENTIFIER); if (method != null) { ois = new ObjectInputStream(httpServletRequest.getInputStream()); // And initialize the output OutputStream os = httpServletResponse.getOutputStream(); oos = new ObjectOutputStream(os); Object objectToReturn = null; try { // Some command to process ? if (method.equals(ServletCommandSinkIdentifier.PROCESS_COMMAND)) { // Read parameter objects Long connuid = (Long) ois.readObject(); Long uid = (Long) ois.readObject(); Command cmd = (Command) ois.readObject(); CallingContext ctx = (CallingContext) ois.readObject(); // Delegate execution to the CommandProcessor objectToReturn = processor.process(connuid, uid, cmd, ctx); } else if (method.equals(ServletCommandSinkIdentifier.CONNECT_COMMAND)) { String url = ois.readUTF(); Properties props = (Properties) ois.readObject(); Properties clientInfo = (Properties) ois.readObject(); CallingContext ctx = (CallingContext) ois.readObject(); ConnectionConfiguration connectionConfiguration = VJdbcConfiguration.singleton() .getConnection(url); if (connectionConfiguration != null) { Connection conn = connectionConfiguration.create(props); objectToReturn = processor.registerConnection(conn, connectionConfiguration, clientInfo, ctx); } else { objectToReturn = new SQLException("VJDBC-Connection " + url + " not found"); } } } catch (Throwable t) { // Wrap any exception so that it can be transported back to // the client objectToReturn = SQLExceptionHelper.wrap(t); } // Write the result in the response buffer oos.writeObject(objectToReturn); oos.flush(); httpServletResponse.flushBuffer(); } else { // No VJDBC-Method ? Then we redirect the stupid browser user to // some information page :-) httpServletResponse.sendRedirect("index.html"); } } catch (Exception e) { logger.error("Unexpected Exception", e); throw new ServletException(e); } finally { StreamCloser.close(ois); StreamCloser.close(oos); } }
From source file:com.izforge.izpack.panels.target.TargetPanelHelper.java
/** * Determines if there is IzPack installation information at the specified path that is incompatible with the * current version of IzPack.//from w w w .ja v a2 s. c o m * <p/> * To be incompatible, the file {@link InstallData#INSTALLATION_INFORMATION} must exist in the supplied directory, * and not contain recognised {@link Pack} instances. * * @param dir the path to check * @param readInstallationInformation check .installationinformation file or skip it * @return {@code true} if there is incompatible installation information, * {@code false} if there is no installation info, or it is compatible */ @SuppressWarnings("unchecked") public static boolean isIncompatibleInstallation(String dir, Boolean readInstallationInformation) { boolean result = false; File file = new File(dir, InstallData.INSTALLATION_INFORMATION); if (file.exists() && readInstallationInformation) { FileInputStream input = null; ObjectInputStream objectInput = null; try { input = new FileInputStream(file); objectInput = new ObjectInputStream(input); List<Object> packs = (List<Object>) objectInput.readObject(); for (Object pack : packs) { if (!(pack instanceof Pack)) { return true; } } } catch (Throwable exception) { logger.log(Level.FINE, "Installation information at path=" + file.getPath() + " failed to deserialize", exception); result = true; } finally { IOUtils.closeQuietly(objectInput); IOUtils.closeQuietly(input); } } return result; }
From source file:com.ibm.watson.developer_cloud.professor_languo.ingestion.indexing.StackExchangeThreadSerializer.java
/** * reproduce the StackExchangeThread with the byte array * /*from ww w . j a va 2s.co m*/ * @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:de.tudarmstadt.ukp.experiments.argumentation.clustering.entropy.ClusterTopicMatrixGenerator.java
@Override @SuppressWarnings("unchecked") public void initialize(UimaContext context) throws ResourceInitializationException { super.initialize(context); try {//from w ww. ja v a 2 s . co m // load mapping debateURL -> topic distribution debateTopicMap = (Map<String, List<Double>>) new ObjectInputStream( new FileInputStream(debateTopicMapFile)).readObject(); // load centroids centroids = (TreeMap<Integer, Vector>) new ObjectInputStream(new FileInputStream(centroidsFile)) .readObject(); // initialize matrix int numTopics = debateTopicMap.entrySet().iterator().next().getValue().size(); clusterTopicMatrix = new DenseMatrix(centroids.size(), numTopics); } catch (IOException | ClassNotFoundException e) { throw new ResourceInitializationException(e); } }
From source file:fr.eoidb.util.ImageDownloader.java
@SuppressWarnings("unchecked") public void loadImageCache(Context context) { if (BuildConfig.DEBUG) Log.v(LOG_TAG, "Loading image cache..."); File cacheFile = new File(context.getCacheDir(), cacheFileName); if (cacheFile.exists() && cacheFile.length() > 0) { ObjectInputStream ois = null; try {//from www. j a v a 2s. co m HashMap<String, String> cacheDescription = new HashMap<String, String>(); ois = new ObjectInputStream(new FileInputStream(cacheFile)); cacheDescription = (HashMap<String, String>) ois.readObject(); for (Entry<String, String> cacheDescEntry : cacheDescription.entrySet()) { loadSingleCacheFile(cacheDescEntry.getKey(), context); } } catch (StreamCorruptedException e) { Log.e(LOG_TAG, e.getMessage(), e); } catch (FileNotFoundException e) { Log.e(LOG_TAG, e.getMessage(), e); } catch (EOFException e) { //delete the corrupted cache file Log.w(LOG_TAG, "Deleting the corrupted cache file.", e); cacheFile.delete(); } catch (IOException e) { Log.e(LOG_TAG, e.getMessage(), e); } catch (ClassNotFoundException e) { Log.e(LOG_TAG, e.getMessage(), e); } finally { if (ois != null) { try { ois.close(); } catch (IOException e) { Log.e(LOG_TAG, e.getMessage(), e); } } } } }
From source file:com.tecapro.inventory.common.util.CommonUtil.java
/** * decodeBase64 serializeData into InfoValue object * @param serializeData/*from w w w . j a v a 2s . c o m*/ * @param value * @return * @throws Exception */ public Object deserialize(byte[] serializeData) throws Exception { byte[] decodebytes = Base64.decodeBase64(serializeData); ObjectInputStream istream = null; ByteArrayInputStream byteStream = null; Object result = null; try { byteStream = new ByteArrayInputStream(decodebytes); istream = new ObjectInputStream(byteStream); result = istream.readObject(); } finally { if (byteStream != null) { byteStream.close(); } if (istream != null) { istream.close(); } } return result; }
From source file:com.joliciel.talismane.lexicon.LexiconDeserializer.java
public PosTaggerLexicon deserializeLexiconFile(File lexiconFile) { MONITOR.startTask("deserializeLexiconFile(File)"); try {/* w ww . j a v a 2s.c o m*/ LOG.debug("deserializing " + lexiconFile.getName()); boolean isZip = false; if (lexiconFile.getName().endsWith(".zip")) isZip = true; PosTaggerLexicon lexicon = null; ZipInputStream zis = null; FileInputStream fis = null; ObjectInputStream in = null; try { fis = new FileInputStream(lexiconFile); if (isZip) { zis = new ZipInputStream(fis); lexicon = this.deserializeLexiconFile(zis); } else { in = new ObjectInputStream(fis); lexicon = (PosTaggerLexicon) in.readObject(); in.close(); } } catch (IOException ioe) { throw new RuntimeException(ioe); } catch (ClassNotFoundException cnfe) { throw new RuntimeException(cnfe); } return lexicon; } finally { MONITOR.endTask("deserializeLexiconFile(File)"); } }
From source file:io.smartspaces.scheduling.quartz.orientdb.internal.util.SerialUtils.java
private static Map<String, ?> stringMapFromBytes(byte[] bytes) throws IOException, ClassNotFoundException { ByteArrayInputStream bais = new ByteArrayInputStream(bytes); ObjectInputStream ois = new ObjectInputStream(bais); @SuppressWarnings("unchecked") Map<String, ?> map = (Map<String, ?>) ois.readObject(); ois.close();/*w w w . j av a 2 s . c o m*/ return map; }