List of usage examples for java.io ObjectInputStream close
public void close() throws IOException
From source file:com.novemberain.quartz.mongodb.MongoDBJobStore.java
private 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(); return map;//from w ww . j av a 2 s. c o m }
From source file:com.openteach.diamond.repository.client.cache.FileLRUCache.java
/** * // w w w .ja v a 2 s . c om */ private void initCtrl() { // init index String ctrlFileName = String.format("%s.%s", fileName, CTRL_SUFFIX); ObjectInputStream in = null; // create index file is need this.ctrlFile = new File(ctrlFileName); if (!this.ctrlFile.exists()) { try { this.ctrlFile.createNewFile(); } catch (IOException e) { logger.error(String.format("Create index file:%s failed", ctrlFileName), e); throw new RuntimeException(e); } } try { in = new ObjectInputStream(new FileInputStream(ctrlFile)); Ctrl ctrl = (Ctrl) in.readObject(); this.offset = ctrl.offset; for (Index index : ctrl.indexs) { indexStore.put(index.key, index); } this.frees.addAll(ctrl.frees); ctrl.indexs.clear(); ctrl.frees.clear(); ctrl = null; } catch (IOException e) { logger.error(String.format("Read ctrl file:%s failed", ctrlFileName), e); } catch (ClassNotFoundException e) { logger.error(String.format("Read ctrl file:%s failed", ctrlFileName), e); throw new RuntimeException(e); } finally { if (null != in) { try { in.close(); } catch (IOException e) { } } } // init data file try { this.dataFile = new RandomAccessFile(fileName, "rw"); } catch (FileNotFoundException e) { throw new RuntimeException(e); } }
From source file:com.izforge.izpack.installer.unpacker.UnpackerBase.java
/** * Unpacks the installation files.// w w w . ja va 2 s .c o m */ public void unpack() { logIntro(); state = State.UNPACKING; ObjectInputStream objIn = null; try { FileQueue queue = queueFactory.isSupported() ? queueFactory.create() : null; InputStream in = resources.getInputStream("packs.info"); objIn = new ObjectInputStream(in); @SuppressWarnings("unchecked") List<PackInfo> packsInfo = (List<PackInfo>) objIn.readObject(); objIn.close(); selectedPacks = installData.getSelectedPacks(); preUnpack(selectedPacks); unpack(packsInfo, queue); postUnpack(selectedPacks, queue); } catch (Exception exception) { setResult(false); logger.log(Level.SEVERE, exception.getMessage(), exception); listener.stopAction(); if (exception instanceof ResourceInterruptedException) { prompt.message(Type.INFORMATION, messages.get("installer.cancelled")); } else { IzPackException ize; if (exception instanceof InstallerException) { InstallerException ie = (InstallerException) exception; Throwable t = ie.getCause(); ize = new IzPackException(messages.get("installer.errorMessage"), t != null ? t : exception); } else if (exception instanceof IzPackException) { ize = (IzPackException) exception; } else { ize = new IzPackException(exception.getMessage(), exception); } switch (ize.getPromptType()) { case ERROR: prompt.message(ize); break; case WARNING: AbstractUIHandler handler = new PromptUIHandler(prompt); if (handler.askWarningQuestion(null, AbstractPrompt.getThrowableMessage(ize) + "\n" + messages.get("installer.continueQuestion"), AbstractUIHandler.CHOICES_YES_NO, AbstractUIHandler.ANSWER_NO) == AbstractUIHandler.ANSWER_YES) { return; } break; default: break; } } housekeeper.shutDown(4); } finally { cleanup(); logEpilog(); IOUtils.closeQuietly(objIn); } }
From source file:com.android.volley.cache.ACache.java
/** * ? Serializable?/*www . jav a2 s .c om*/ * * @param key * @return Serializable ? */ public CacheFeed getAsObject(String key) { BinaryShell shell = getAsBinary(key); if (shell == null) return null; byte[] data = shell.content; if (data != null) { ByteArrayInputStream bais = null; ObjectInputStream ois = null; try { bais = new ByteArrayInputStream(data); ois = new ObjectInputStream(bais); Object reObject = ois.readObject(); return new CacheFeed(reObject, shell.outOfDate); } catch (Exception e) { e.printStackTrace(); return null; } finally { try { if (bais != null) bais.close(); } catch (IOException e) { e.printStackTrace(); } try { if (ois != null) ois.close(); } catch (IOException e) { e.printStackTrace(); } } } return null; }
From source file:vinci.project2.pkg1.View.java
/** * Load me, baby//from w w w. java 2s . co m */ private void loadSerial(String filename) throws FileNotFoundException, IOException, ClassNotFoundException { try { FileInputStream fis = new FileInputStream(filename); System.out.println(filename); BufferedInputStream bis = new BufferedInputStream(fis); ObjectInputStream ois = new ObjectInputStream(bis); Save save = (Save) ois.readObject(); ageField.setText(String.valueOf(save.age)); capRateGainsField.setText(String.valueOf(save.capRateGains)); iTaxField.setText(String.valueOf(save.iTax)); retAgeField.setText(String.valueOf(save.retAge)); preContField.setText(String.valueOf(save.preCont)); postContField.setText(String.valueOf(save.postCont)); rorField.setText(String.format("%.2f", (save.ror))); preBalField.setText(String.valueOf(save.preBal)); postBalField.setText(String.valueOf(save.postBal)); fis.close(); ois.close(); } catch (ClassNotFoundException c) { } }
From source file:com.adito.boot.AbstractPropertyClass.java
public void restore() throws IOException { log.info("Restoring property class " + getName()); if (store == null) { throw new IllegalStateException("Nothing stored for " + getName()); }/* ww w . j a va2s . c o m*/ ObjectInputStream ois = new ObjectInputStream(new ByteArrayInputStream(store.toByteArray())) { protected Class<?> resolveClass(ObjectStreamClass desc) throws IOException, ClassNotFoundException { try { return Class.forName(desc.getName(), false, AbstractPropertyClass.this.getClass().getClassLoader()); } catch (ClassNotFoundException ex) { return super.resolveClass(desc); } } }; try { definitions = (Map<String, PropertyDefinition>) ois.readObject(); categories = (List<PropertyDefinitionCategory>) ois.readObject(); categoryMap = (Map<String, PropertyDefinitionCategory>) ois.readObject(); store = null; // PropertyClass member variable is transient so we need to reinitialise for (PropertyDefinition def : definitions.values()) def.init(this); for (PropertyDefinitionCategory cat : categories) cat.setPropertyClass(this); } catch (ClassNotFoundException cnfe) { throw new IOException("Deserialisation failed. " + cnfe.getMessage()); } finally { ois.close(); } }
From source file:com.ecyrd.jspwiki.ReferenceManager.java
/** * Reads the serialized data from the disk back to memory. * Returns the date when the data was last written on disk *///from w w w. j ava2 s . co m @SuppressWarnings("unchecked") private synchronized long unserializeFromDisk() throws IOException, ClassNotFoundException { ObjectInputStream in = null; long saved = 0L; try { StopWatch sw = new StopWatch(); sw.start(); File f = new File(m_engine.getWorkDir(), SERIALIZATION_FILE); in = new ObjectInputStream(new BufferedInputStream(new FileInputStream(f))); long ver = in.readLong(); if (ver != serialVersionUID) { throw new IOException("File format has changed; I need to recalculate references."); } saved = in.readLong(); m_refersTo = (Map) in.readObject(); m_referredBy = (Map) in.readObject(); in.close(); m_unmutableReferredBy = Collections.unmodifiableMap(m_referredBy); m_unmutableRefersTo = Collections.unmodifiableMap(m_refersTo); sw.stop(); log.debug("Read serialized data successfully in " + sw); } finally { if (in != null) in.close(); } return saved; }
From source file:com.octo.captcha.engine.bufferedengine.buffer.DiskCaptchaBuffer.java
/** * Reads Index to disk on startup. <p/>if the index file does not exist, it creates a new one. <p/>Note that the * cache is locked for the entire time that the index is being written *///from w w w .j a v a 2 s. co m private synchronized void readIndex() throws IOException { ObjectInputStream objectInputStream = null; FileInputStream fin = null; if (indexFile.exists() && persistant) { try { fin = new FileInputStream(indexFile); objectInputStream = new ObjectInputStream(fin); diskElements = (HashedMap) objectInputStream.readObject(); freeSpace = (ArrayList) objectInputStream.readObject(); } catch (StreamCorruptedException e) { log.error("Corrupt index file. Creating new index."); createNewIndexFile(); } catch (IOException e) { log.error("IOException reading index. Creating new index. "); createNewIndexFile(); } catch (ClassNotFoundException e) { log.error("Class loading problem reading index. Creating new index. ", e); createNewIndexFile(); } finally { try { if (objectInputStream != null) { objectInputStream.close(); } else if (fin != null) { fin.close(); } } catch (IOException e) { log.error("Problem closing the index file."); } } } else { createNewIndexFile(); } }
From source file:com.bigdata.dastor.db.ColumnFamilyStore.java
protected Set<String> readSavedCache(File path, boolean sort) throws IOException { Set<String> keys; if (sort) {/*from w w w . j a va 2 s . com*/ // sort the results on read because cache may be written many times during server lifetime, // so better to pay that price once on startup than sort at write time. keys = new TreeSet<String>(StorageProxy.keyComparator); } else { keys = new HashSet<String>(); } long start = System.currentTimeMillis(); if (path.exists()) { if (logger_.isDebugEnabled()) logger_.debug("reading saved cache from " + path); ObjectInputStream in = new ObjectInputStream(new BufferedInputStream(new FileInputStream(path))); Charset UTF8 = Charset.forName("UTF-8"); while (in.available() > 0) { int size = in.readInt(); byte[] bytes = new byte[size]; in.readFully(bytes); keys.add(new String(bytes, UTF8)); } in.close(); if (logger_.isDebugEnabled()) logger_.debug(String.format("completed reading (%d ms; %d keys) from saved cache at %s", (System.currentTimeMillis() - start), keys.size(), path)); } return keys; }