List of usage examples for java.io ObjectOutput writeObject
public void writeObject(Object obj) throws IOException;
From source file:org.polymap.rhei.fulltext.servlet.SearchServlet.java
@Override protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { log.info("Request: " + request.getQueryString()); String srsParam = request.getParameter("srs"); CoordinateReferenceSystem worldCRS = DEFAULT_WORLD_CRS; if (srsParam != null) { try {//w w w .ja v a 2 s . c om worldCRS = CRS.decode(srsParam); } catch (Exception e) { worldCRS = DEFAULT_WORLD_CRS; } } log.debug("worldCRS: " + worldCRS); // completion request ***************************** if (request.getParameter("term") != null) { String searchStr = request.getParameter("term"); searchStr = StringEscapeUtils.unescapeHtml4(searchStr); try { JSONArray result = new JSONArray(); for (String record : dispatcher.propose(searchStr, 7, null)) { //result.put( StringEscapeUtils.escapeHtml( record ) ); result.put(record); } log.info("Response: " + result.toString()); response.setContentType("application/json; charset=UTF-8"); response.setCharacterEncoding("UTF-8"); response.getWriter().println(result.toString()); } catch (Exception e) { log.info("Response: " + "Fehler: " + e.getMessage(), e); response.setContentType("text/html"); response.getWriter().println("Fehler: " + e.getMessage()); } } // content request (GeoRSS/KML/GeoJSON) *********** else if (request.getParameter("search") != null) { String searchStr = request.getParameter("search"); searchStr = URLDecoder.decode(searchStr, "UTF-8"); log.info(" searchStr= " + searchStr); String outputType = request.getParameter("outputType"); int maxResults = request.getParameter("maxResults") != null ? Integer.parseInt(request.getParameter("maxResults")) : DEFAULT_MAX_SEARCH_RESULTS; try { // gzipped response? CountingOutputStream cout = new CountingOutputStream(response.getOutputStream()); OutputStream bout = cout; String acceptEncoding = request.getHeader("Accept-Encoding"); if (acceptEncoding != null && acceptEncoding.toLowerCase().contains("gzip")) { try { bout = new GZIPOutputStream(bout); response.setHeader("Content-Encoding", "gzip"); } catch (NoSuchMethodError e) { // for whatever reason the syncFlush ctor is not always available log.warn(e.toString()); } } ObjectOutput out = null; // KML if ("KML".equalsIgnoreCase(outputType)) { throw new RuntimeException("Not supported currently."); // out = new KMLEncoder( bout ); // response.setContentType( "application/vnd.google-earth.kml+xml; charset=UTF-8" ); // response.setCharacterEncoding( "UTF-8" ); } // JSON else if ("JSON".equalsIgnoreCase(outputType)) { response.setContentType("application/json; charset=UTF-8"); response.setCharacterEncoding("UTF-8"); out = new GeoJsonEncoder(bout, worldCRS); } // RSS else { // XXX figure the real client URL (without reverse proxies) //String baseURL = StringUtils.substringBeforeLast( request.getRequestURL().toString(), "/" ) + "/index.html"; String baseURL = (String) System.getProperties().get("org.polymap.atlas.feed.url"); log.info(" baseURL: " + baseURL); String title = (String) System.getProperties().get("org.polymap.atlas.feed.title"); String description = (String) System.getProperties().get("org.polymap.atlas.feed.description"); out = new GeoRssEncoder(bout, worldCRS, baseURL, title, description); response.setContentType("application/rss+xml; charset=UTF-8"); response.setCharacterEncoding("UTF-8"); } // make sure that empty searchStr *always* results in empty reponse if (searchStr != null && searchStr.length() > 0) { for (JSONObject feature : dispatcher.search(searchStr, maxResults)) { try { out.writeObject(feature); } catch (Exception e) { log.warn("Error during encode: " + e, e); } } } // make sure that streams and deflaters are flushed out.close(); log.info(" written: " + cout.getCount() + " bytes"); } catch (Exception e) { log.error(e.getLocalizedMessage(), e); } } response.flushBuffer(); }
From source file:org.apache.openjpa.persistence.EntityManagerImpl.java
public void writeExternal(ObjectOutput out) throws IOException { try {//from ww w . j a v a 2s .c o m // this requires that only AbstractBrokerFactory-sourced // brokers can be serialized Object factoryKey = ((AbstractBrokerFactory) _broker.getBrokerFactory()).getPoolKey(); out.writeObject(factoryKey); ByteArrayOutputStream baos = new ByteArrayOutputStream(); ObjectOutputStream innerOut = new ObjectOutputStream(baos); _broker.getDelegate().putUserObject(JPAFacadeHelper.EM_KEY, null); innerOut.writeObject(_broker.getDelegate()); innerOut.flush(); out.writeObject(baos.toByteArray()); } catch (RuntimeException re) { try { re = _ret.translate(re); } catch (Exception e) { // ignore } throw re; } }
From source file:org.apache.geode.internal.InternalDataSerializer.java
/** * write an object in java Serializable form with a SERIALIZABLE DSCODE so that it can be * deserialized with DataSerializer.readObject() * //from w w w. j a v a2 s .c om * @param o the object to serialize * @param out the data output to serialize to */ public static void writeSerializableObject(Object o, DataOutput out) throws IOException { out.writeByte(SERIALIZABLE); if (out instanceof ObjectOutputStream) { ((ObjectOutputStream) out).writeObject(o); } else { OutputStream stream; if (out instanceof OutputStream) { stream = (OutputStream) out; } else { final DataOutput out2 = out; stream = new OutputStream() { @Override public void write(int b) throws IOException { out2.write(b); } }; } boolean wasDoNotCopy = false; if (out instanceof HeapDataOutputStream) { // To fix bug 52197 disable doNotCopy mode // while serialize with an ObjectOutputStream. // The problem is that ObjectOutputStream keeps // an internal byte array that it reuses while serializing. wasDoNotCopy = ((HeapDataOutputStream) out).setDoNotCopy(false); } try { ObjectOutput oos = new ObjectOutputStream(stream); if (stream instanceof VersionedDataStream) { Version v = ((VersionedDataStream) stream).getVersion(); if (v != null && v != Version.CURRENT) { oos = new VersionedObjectOutput(oos, v); } } oos.writeObject(o); // To fix bug 35568 just call flush. We can't call close because // it calls close on the wrapped OutputStream. oos.flush(); } finally { if (wasDoNotCopy) { ((HeapDataOutputStream) out).setDoNotCopy(true); } } } }
From source file:org.apache.lens.server.query.QueryExecutionServiceImpl.java
@Override public void writeExternal(ObjectOutput out) throws IOException { super.writeExternal(out); // persist all drivers synchronized (drivers) { out.writeInt(drivers.size());/* w w w .ja v a2 s. c om*/ LensDriver driver = null; for (Map.Entry<String, LensDriver> driverEntry : drivers.entrySet()) { driver = driverEntry.getValue(); synchronized (driver) { out.writeUTF(driverEntry.getKey()); out.writeUTF(driver.getClass().getName()); driver.writeExternal(out); } } } // persist allQueries synchronized (allQueries) { out.writeInt(allQueries.size()); for (QueryContext ctx : allQueries.values()) { synchronized (ctx) { out.writeObject(ctx); boolean isDriverAvailable = (ctx.getSelectedDriver() != null); out.writeBoolean(isDriverAvailable); if (isDriverAvailable) { out.writeUTF(ctx.getSelectedDriver().getFullyQualifiedName()); } } } log.info("Persisted {} queries", allQueries.size()); } }
From source file:org.apache.axis2.context.MessageContext.java
/** * Calls the serializeSelfManagedData() method of each handler that * implements the <bold>SelfManagedDataManager</bold> interface. * Handlers for this message context are identified via the * executionChain list./*www . jav a2 s . c om*/ * * @param out The output stream */ private void serializeSelfManagedData(ObjectOutput out) { selfManagedDataHandlerCount = 0; try { if ((selfManagedDataMap == null) || (executionChain == null) || (selfManagedDataMap.size() == 0) || (executionChain.size() == 0)) { out.writeBoolean(ExternalizeConstants.EMPTY_OBJECT); if (DEBUG_ENABLED && log.isTraceEnabled()) { log.trace(getLogIDString() + ":serializeSelfManagedData(): No data : END"); } return; } // let's create a temporary list with the handlers ArrayList<Handler> flatExecChain = flattenPhaseListToHandlers(executionChain, null); //ArrayList selfManagedDataHolderList = serializeSelfManagedDataHelper(flatExecChain.iterator(), new ArrayList()); ArrayList<SelfManagedDataHolder> selfManagedDataHolderList = serializeSelfManagedDataHelper( flatExecChain); if (selfManagedDataHolderList.size() == 0) { out.writeBoolean(ExternalizeConstants.EMPTY_OBJECT); if (DEBUG_ENABLED && log.isTraceEnabled()) { log.trace(getLogIDString() + ":serializeSelfManagedData(): No data : END"); } return; } out.writeBoolean(ExternalizeConstants.ACTIVE_OBJECT); // SelfManagedData can be binary so won't be able to treat it as a // string - need to treat it as a byte [] // how many handlers actually // returned serialized SelfManagedData out.writeInt(selfManagedDataHolderList.size()); for (int i = 0; i < selfManagedDataHolderList.size(); i++) { out.writeObject(selfManagedDataHolderList.get(i)); } } catch (IOException e) { if (DEBUG_ENABLED && log.isTraceEnabled()) { log.trace("MessageContext:serializeSelfManagedData(): Exception [" + e.getClass().getName() + "] description [" + e.getMessage() + "]", e); } } }
From source file:com.sentaroh.android.SMBExplorer.SMBExplorerMain.java
@Override public void writeExternal(ObjectOutput objout) throws IOException { // Log.v("","wr"); objout.writeLong(serialVersionUID);// ww w.jav a 2 s .c om SerializeUtil.writeArrayList(objout, paste_list); SerializeUtil.writeUtf(objout, paste_from_url); SerializeUtil.writeUtf(objout, paste_to_url); SerializeUtil.writeUtf(objout, paste_item_list); objout.writeBoolean(is_paste_copy); objout.writeBoolean(is_paste_enabled); objout.writeBoolean(is_paste_from_local); SerializeUtil.writeArrayList(objout, local_dir_hist); SerializeUtil.writeArrayList(objout, remote_dir_hist); SerializeUtil.writeArrayList(objout, remote_file_list_cache); objout.writeObject(remote_curr_file_list); SerializeUtil.writeArrayList(objout, local_file_list_cache); objout.writeObject(local_curr_file_list); vsa.writeExternal(objout); objout.writeUTF(dialog_msg_cat); SerializeUtil.writeUtf(objout, remoteBase); SerializeUtil.writeUtf(objout, localBase); SerializeUtil.writeUtf(objout, remoteDir); SerializeUtil.writeUtf(objout, localDir); SerializeUtil.writeUtf(objout, currentTabName); SerializeUtil.writeUtf(objout, smbUser); SerializeUtil.writeUtf(objout, smbPass); objout.writeBoolean(localUpButtonEnabled); objout.writeBoolean(localTopButtonEnabled); objout.writeBoolean(remoteUpButtonEnabled); objout.writeBoolean(remoteTopButtonEnabled); }