List of usage examples for java.io ObjectInputStream ObjectInputStream
public ObjectInputStream(InputStream in) throws IOException
From source file:SerialCloneTest.java
public Object clone() { try {/*from www. j a va 2s .co m*/ // save the object to a byte array ByteArrayOutputStream bout = new ByteArrayOutputStream(); ObjectOutputStream out = new ObjectOutputStream(bout); out.writeObject(this); out.close(); // read a clone of the object from the byte array ByteArrayInputStream bin = new ByteArrayInputStream(bout.toByteArray()); ObjectInputStream in = new ObjectInputStream(bin); Object ret = in.readObject(); in.close(); return ret; } catch (Exception e) { return null; } }
From source file:com.talis.storage.s3.ExternalizableS3ObjectTest.java
@Test public void roundTripS3ObjectSerialization() throws Exception { ByteArrayOutputStream tmp = new ByteArrayOutputStream(); ObjectOutputStream out = new ObjectOutputStream(tmp); byte[] bytes = ("When replying to any emails you have prior to migration " + "(ie any in your inbox before you have been migrated) " + "you will need to change the way you reply to them").getBytes(); ByteBuffer buffer = ByteBuffer.allocate(bytes.length); buffer.put(bytes);//from www .ja va 2 s.c om S3ObjectFactory factory = new S3ObjectFactory("bucket"); S3Object original = factory.newObject("foo", 0, MediaType.TEXT_PLAIN_TYPE, buffer); out.writeObject(original); out.flush(); out.close(); byte[] serialized = tmp.toByteArray(); ObjectInputStream in = new ObjectInputStream(new ByteArrayInputStream(serialized)); S3Object clone = (S3Object) in.readObject(); assertObjectsEqual(original, clone); }
From source file:com.ps.cc.controller.Init.java
@RequestMapping public String index(ModelMap map, RenderRequest renderRequest) throws Exception { TwilioConfiguration twilioConfiguration = new TwilioConfiguration(); try {/* w w w .j av a 2 s.co m*/ 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... } map.addAttribute("command", twilioConfiguration); return "index"; }
From source file:disko.flow.analyzers.socket.SocketReceiver.java
private Message readMessage(ServerSocket serverSocket) { while (true) { Socket clientSocket = null; ObjectInputStream in = null; try {//w w w . ja v a 2 s . c o m clientSocket = serverSocket.accept(); in = new ObjectInputStream(clientSocket.getInputStream()); Message message = null; try { message = (Message) in.readObject(); } catch (IOException e) { log.error("Error reading object.", e); continue; } catch (ClassNotFoundException e) { log.error("Class not found.", e); continue; } // while (in.read() != -1); // if (in.available() > 0) // { // System.err.println("OOPS, MORE THAT ON SOCKET HASN'T BEEN // READ: " + in.available()); // while (in.available() > 0) // in.read(); // } return message; } catch (SocketTimeoutException ex) { if (Thread.interrupted()) return null; } catch (InterruptedIOException e) // this doesn't really work, that's why we put an Socket timeout and we check for interruption { return null; } catch (IOException e) { log.error("Could not listen on port: " + port, e); } finally { if (in != null) try { in.close(); } catch (Throwable t) { log.error("While closing receiver input.", t); } if (clientSocket != null) try { clientSocket.close(); } catch (Throwable t) { log.error("While closing receiver socket.", t); } } } }
From source file:com.sun.j2ee.blueprints.waf.controller.impl.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();/*w ww .j a v a 2 s .co m*/ // 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) { logger.error("ClientCacheLinkFlowHandler caught: ", ode); } catch (java.lang.ClassNotFoundException cnfe) { logger.error("ClientCacheLinkFlowHandler caught: ", cnfe); } catch (java.io.IOException iox) { logger.error("ClientCacheLinkFlowHandler caught: ", iox); } } } } return forwardScreen; }
From source file:it.unimi.di.big.mg4j.io.IOFactories.java
public static Object loadObject(final IOFactory ioFactory, final String filename) throws IOException, ClassNotFoundException { final ObjectInputStream ois = new ObjectInputStream( new FastBufferedInputStream(ioFactory.getInputStream(filename))); final Object result = ois.readObject(); ois.close();/*from w w w . j ava 2s . c o m*/ return result; }
From source file:net.dfs.server.filemapper.impl.FileLocationTrackerImpl.java
@SuppressWarnings("unchecked") public void loadMap() { try {/* w ww . j a v a 2 s . c o m*/ ObjectInputStream load = new ObjectInputStream(new FileInputStream(new File("locationMap"))); hashMap = (HashMap<String, String>) load.readObject(); } catch (FileNotFoundException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } catch (ClassNotFoundException e) { e.printStackTrace(); } log.info("Hash Map Loaded"); }
From source file:de.tudarmstadt.ukp.csniper.resbuild.stuff.CasFlusher.java
public static void flush(File aSerializedCas, OutputStream aOutputStream, int aBegin, int aEnd) throws IOException { CAS cas = new CASImpl(); InputStream is = null;/*w w w . jav a2s . c o m*/ try { is = new FileInputStream(aSerializedCas); if (aSerializedCas.getName().endsWith(".gz")) { is = new GZIPInputStream(is); } else if (aSerializedCas.getName().endsWith(".xz")) { is = new XZInputStream(is); } is = new ObjectInputStream(new BufferedInputStream(is)); CASCompleteSerializer serializer = (CASCompleteSerializer) ((ObjectInputStream) is).readObject(); ((CASImpl) cas).reinit(serializer); } catch (ClassNotFoundException e) { throw new IOException(e); } finally { IOUtils.closeQuietly(is); } Collection<AnnotationFS> annos; if (aBegin > -1 && aEnd > -1) { annos = CasUtil.selectCovered(cas, CasUtil.getType(cas, Annotation.class), aBegin, aEnd); } else { annos = CasUtil.selectAll(cas); } for (AnnotationFS anno : annos) { StringBuilder sb = new StringBuilder(); sb.append("[" + anno.getClass().getSimpleName() + "] "); sb.append("(" + anno.getBegin() + "," + anno.getEnd() + ") "); sb.append(anno.getCoveredText() + "\n"); IOUtils.write(sb, aOutputStream, "UTF-8"); } }
From source file:cn.guoyukun.spring.jpa.repository.hibernate.type.ObjectSerializeUserType.java
/** * JDBC ResultSet??,??// ww w . j a va2 s . com * (?null?) * names???? * * @param names * @param owner * @return * @throws HibernateException * @throws SQLException */ @Override public Object nullSafeGet(ResultSet rs, String[] names, SessionImplementor session, Object owner) throws HibernateException, SQLException { ObjectInputStream ois = null; try { String hexStr = rs.getString(names[0]); ois = new ObjectInputStream(new ByteArrayInputStream(Hex.decodeHex(hexStr.toCharArray()))); return ois.readObject(); } catch (Exception e) { throw new HibernateException(e); } finally { try { ois.close(); } catch (IOException e) { } } }
From source file:com.remobile.file.AssetFilesystem.java
private void lazyInitCaches() { synchronized (listCacheLock) { if (listCache == null) { ObjectInputStream ois = null; try { ois = new ObjectInputStream(assetManager.open("cdvasset.manifest")); listCache = (Map<String, String[]>) ois.readObject(); lengthCache = (Map<String, Long>) ois.readObject(); listCacheFromFile = true; } catch (ClassNotFoundException e) { e.printStackTrace();//from ww w .j a va 2 s. co m } catch (IOException e) { // Asset manifest won't exist if the gradle hook isn't set up correctly. } finally { if (ois != null) { try { ois.close(); } catch (IOException e) { } } } if (listCache == null) { Log.w("AssetFilesystem", "Asset manifest not found. Recursive copies and directory listing will be slow."); listCache = new HashMap<String, String[]>(); } } } }