List of usage examples for java.io ObjectInputStream readUTF
public String readUTF() throws IOException
From source file:org.taverna.server.master.worker.RemoteRunDelegate.java
@SuppressWarnings("unchecked") private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException { in.defaultReadObject();/*w w w . j a va 2 s . co m*/ if (log == null) log = getLog("Taverna.Server.LocalWorker"); final String creatorName = in.readUTF(); SecurityContextFactory factory = (SecurityContextFactory) in.readObject(); try { secContext = factory.create(this, new UsernamePrincipal(creatorName)); } catch (RuntimeException | IOException e) { throw e; } catch (Exception e) { throw new SecurityContextReconstructionException(e); } run = ((MarshalledObject<RemoteSingleRun>) in.readObject()).get(); }
From source file:tvbrowser.core.Settings.java
private static void loadWindowSettings() { File windowSettingsFile = new File(Settings.getUserSettingsDirName(), WINDOW_SETTINGS_FILE); if (windowSettingsFile.isFile() && windowSettingsFile.canRead()) { try {// ww w . j a v a 2s. c om StreamUtilities.objectInputStream(windowSettingsFile, new ObjectInputStreamProcessor() { public void process(ObjectInputStream in) throws IOException { if (in.available() > 0) { in.readInt(); // read version int n = in.readInt(); // read number of window settings mWindowSettings = new HashMap<String, WindowSetting>(n); for (int i = 0; i < n; i++) { mWindowSettings.put(in.readUTF(), new WindowSetting(in)); } } in.close(); } }); } catch (Exception e) { // propably defect settings, create new settings mWindowSettings = null; } } if (mWindowSettings == null) { mWindowSettings = new HashMap<String, WindowSetting>(1); } }
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 {/*w ww. j a v a2 s . co m*/ // 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:org.apache.hadoop.hbase.io.hfile.bucket.BucketCache.java
@SuppressWarnings("unchecked") private void retrieveFromFile() throws IOException, BucketAllocatorException, ClassNotFoundException { File persistenceFile = new File(persistencePath); if (!persistenceFile.exists()) { return;/*ww w. j a va 2s .c om*/ } assert !cacheEnabled; FileInputStream fis = null; ObjectInputStream ois = null; try { if (!ioEngine.isPersistent()) throw new IOException("Attempt to restore non-persistent cache mappings!"); fis = new FileInputStream(persistencePath); ois = new ObjectInputStream(fis); long capacitySize = ois.readLong(); if (capacitySize != cacheCapacity) throw new IOException("Mismatched cache capacity:" + StringUtils.byteDesc(capacitySize) + ", expected: " + StringUtils.byteDesc(cacheCapacity)); String ioclass = ois.readUTF(); String mapclass = ois.readUTF(); if (!ioEngine.getClass().getName().equals(ioclass)) throw new IOException("Class name for IO engine mismatch: " + ioclass + ", expected:" + ioEngine.getClass().getName()); if (!backingMap.getClass().getName().equals(mapclass)) throw new IOException("Class name for cache map mismatch: " + mapclass + ", expected:" + backingMap.getClass().getName()); UniqueIndexMap<Integer> deserMap = (UniqueIndexMap<Integer>) ois.readObject(); BucketAllocator allocator = new BucketAllocator(cacheCapacity, backingMap, this.realCacheSize); backingMap = (ConcurrentHashMap<BlockCacheKey, BucketEntry>) ois.readObject(); bucketAllocator = allocator; deserialiserMap = deserMap; } finally { if (ois != null) ois.close(); if (fis != null) fis.close(); if (!persistenceFile.delete()) { throw new IOException("Failed deleting persistence file " + persistenceFile.getAbsolutePath()); } } }
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 *///w ww .j ava 2 s . com private synchronized long unserializeAttrsFromDisk(WikiPage p) throws IOException, ClassNotFoundException { ObjectInputStream in = null; long saved = 0L; try { StopWatch sw = new StopWatch(); sw.start(); // // Find attribute cache, and check if it exists // File f = new File(m_engine.getWorkDir(), SERIALIZATION_DIR); f = new File(f, getHashFileName(p.getName())); if (!f.exists()) { return 0L; } log.debug("Deserializing attributes for " + p.getName()); in = new ObjectInputStream(new BufferedInputStream(new FileInputStream(f))); long ver = in.readLong(); if (ver != serialVersionUID) { log.debug("File format has changed; cannot deserialize."); return 0L; } saved = in.readLong(); String name = in.readUTF(); if (!name.equals(p.getName())) { log.debug("File name does not match (" + name + "), skipping..."); return 0L; // Not here } long entries = in.readLong(); for (int i = 0; i < entries; i++) { String key = in.readUTF(); Object value = in.readObject(); p.setAttribute(key, value); log.debug(" attr: " + key + "=" + value); } in.close(); sw.stop(); log.debug("Read serialized data for " + name + " successfully in " + sw); p.setHasMetadata(); } catch (NoSuchAlgorithmException e) { log.fatal("No MD5!?!"); } finally { if (in != null) in.close(); } return saved; }