Examples of DirtyOutputStreamWriter


Examples of org.persvr.remote.DataSerializer.DirtyOutputStreamWriter

      @Override
      public Object call(Context cx, Scriptable scope,
          Scriptable thisObj, Object[] args) {
        try {
          HttpServletResponse response = Client.getCurrentObjectResponse().getHttpResponse();
          DirtyOutputStreamWriter writer = new DirtyOutputStreamWriter(response.getOutputStream(),"UTF8");
          try{
            new JavaScriptSerializer().serialize(args[0], Client.getCurrentObjectResponse(), writer);
          }
          catch(RuntimeException e){
            if(writer.isDirty)
              writer.write("&&");
            throw e;
          }
          finally{
            writer.flushIfDirty();
          }
          return null;
        } catch (IOException e) {
          throw new RuntimeException(e);
        }
      }

    });
   
    Scriptable applicationJson = new NativeObject();
    objectProto.put("representation:application/json", objectProto, applicationJson);
    objectProtoMirror.put("representation:application/json", objectProtoMirror, applicationJson);
    objectProto.setAttributes("representation:application/json",ScriptableObject.DONTENUM);
    applicationJson.put("quality", applicationJson, 0.8);
    applicationJson.put("output", applicationJson, new PersevereNativeFunction(){
      @Override
      public Object call(Context cx, Scriptable scope,
          Scriptable thisObj, Object[] args) {
        try {
          HttpServletResponse response = Client.getCurrentObjectResponse().getHttpResponse();
          DirtyOutputStreamWriter writer = new DirtyOutputStreamWriter(response.getOutputStream(),"UTF8");
          try{
            new JSONSerializer().serialize(args[0], Client.getCurrentObjectResponse(), writer);
          }
          catch(RuntimeException e){
            if(writer.isDirty)
              writer.write("&&");
            throw e;
          }
          finally{
            writer.flushIfDirty();
          }
          return null;
        } catch (IOException e) {
          throw new RuntimeException(e);
        }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.