Handle the command send from my client peer.
@param in The (optional) Inputstream to get the params from.
@param out The stream to write the results.
517309
public void doProcess(InputStream in, PrintWriter out, Map<String, Object> properties)
        throws RemoteException
    {
        String strCommand = this.getProperty(REMOTE_COMMAND, properties);
        try {
            if (FREE_REMOTE_SESSION.equals(strCommand))
            {
                ((BaseSession)m_remoteObject).freeRemoteSession();
                this.free();    // Free this (peer's) resources.
            }
            else if (MAKE_REMOTE_SESSION.equals(strCommand))
            {
                String strSessionClassName = this.getNextStringParam(in, NAME, properties);
                RemoteBaseSession remoteSession = ((RemoteBaseSession)m_remoteObject).makeRemoteSession(strSessionClassName);
                this.setReturnSessionOrObject(out, remoteSession);
            }
            else if (DO_REMOTE_ACTION.equals(strCommand))
            {
                String strAction = this.getNextStringParam(in, NAME, properties);
                Map<String,Object> propIn = this.getNextPropertiesParam(in, PROPERTIES, properties);
                if (propIn != null)
                    properties.putAll(propIn);
                Object objReturn = ((RemoteBaseSession)m_remoteObject).doRemoteAction(strAction, properties);
                this.setReturnSessionOrObject(out, objReturn);  // Could be a session.
            }
            else
                super.doProcess(in, out, properties);
        } catch (Exception ex)    {
            // ex.printStackTrace();    // Don't print this error, since I am returning it to my ajax caller.
            this.setReturnObject(out, ex);
        }
    }
1370025
@Handler
    public void onOutput(Output<ByteBuffer> event,
            PlainChannel plainChannel)
            throws InterruptedException, SSLException, ExecutionException {
        if (plainChannel.hub() != this) {
            return;
        }
        plainChannel.sendUpstream(event);
    }
962335
public void sendRequest (
        int invOid, int invCode, int methodId, Object[] args, Transport transport)
    {
        if (_clobj == null) {
            log.warning("Dropping invocation request on shutdown director", "code", invCode,
                        "methodId", methodId);
            return;
        }

        // configure any invocation listener marshallers among the arguments
        int acount = args.length;
        for (int ii = 0; ii < acount; ii++) {
            Object arg = args[ii];
            if (arg instanceof ListenerMarshaller) {
                ListenerMarshaller lm = (ListenerMarshaller)arg;
                lm.requestId = nextRequestId();
                lm.mapStamp = System.currentTimeMillis();
                // create a mapping for this marshaller so that we can properly dispatch responses
                // sent to it
                _listeners.put(lm.requestId, lm);
            }
        }

        // create an invocation request event
        InvocationRequestEvent event = new InvocationRequestEvent(invOid, invCode, methodId, args);
        event.setTransport(transport);

        // because invocation directors are used on the server, we set the source oid here so that
        // invocation requests are properly attributed to the right client object when created by
        // server-side entities only sort of pretending to be a client
        event.setSourceOid(_clobj.getOid());

//         Log.info("Sending invreq " + event + ".");

        // now dispatch the event
        _omgr.postEvent(event);
    }
1289772
@Override
  public void deliver(WriteStream os, OutHttp2 outHttp)
    throws IOException
  {
    outHttp.writeBlock(_streamId);
  }
438581
@Override
    InputStream execute(String cmd, Object ... args) throws AgentLoadException, IOException {
        assert args.length <= 3;                // includes null

        // did we detach?
        String p;
        synchronized (this) {
            if (this.path == null) {
                throw new IOException("Detached from target VM");
            }
            p = this.path;
        }

        // create UNIX socket
        int s = socket();

        // connect to target VM
        try {
            connect(s, p);
        } catch (IOException x) {
            close(s);
            throw x;
        }

        IOException ioe = null;

        // connected - write request
        // <ver> <cmd> <args...>
        try {
            writeString(s, PROTOCOL_VERSION);
            writeString(s, cmd);

            for (int i=0; i<3; i++) {
                if (i < args.length && args[i] != null) {
                    writeString(s, (String)args[i]);
                } else {
                    writeString(s, "");
                }
            }
        } catch (IOException x) {
            ioe = x;
        }


        // Create an input stream to read reply
        SocketInputStream sis = new SocketInputStream(s);

        // Read the command completion status
        int completionStatus;
        try {
            completionStatus = readInt(sis);
        } catch (IOException x) {
            sis.close();
            if (ioe != null) {
                throw ioe;
            } else {
                throw x;
            }
        }

        if (completionStatus != 0) {
            sis.close();

            // In the event of a protocol mismatch then the target VM
            // returns a known error so that we can throw a reasonable
            // error.
            if (completionStatus == ATTACH_ERROR_BADVERSION) {
                throw new IOException("Protocol mismatch with target VM");
            }

            // Special-case the "load" command so that the right exception is
            // thrown.
            if (cmd.equals("load")) {
                throw new AgentLoadException("Failed to load agent library");
            } else {
                throw new IOException("Command failed in target VM");
            }
        }

        // Return the input stream so that the command output can be read
        return sis;
    }
847064
public void write(OutputStream out)throws SocksException,
                                             IOException{
     if(data == null){
       Socks5Message msg;

       if(addrType == SOCKS_ATYP_DOMAINNAME)
          msg = new Socks5Message(command,host,port);
       else{
          if(ip == null){
             try{
               ip = InetAddress.getByName(host);
             }catch(UnknownHostException uh_ex){
               throw new SocksException(Proxy.SOCKS_JUST_ERROR);
             }
          }
          msg = new Socks5Message(command,ip,port);
       }
       data = msg.data;
     }
     out.write(data);
   }
142647
public static void write(InputStream in, int bufferSize) {
		ServletOutputStream out = null;
		try {
			out = getOutputStream();
			IoUtil.copy(in, out, bufferSize);
		} catch (IOException e) {
			throw new RenderException("Error when output to client!", e);
		} finally {
			IoUtil.close(out);
			IoUtil.close(in);
		}
	}
1352805
@Override
  public void deliver(final MessageAmp msg, Outbox outbox)
      throws Exception
  {
    //outbox.setMessage(msg);
    
    try {
      msg.invoke(_inbox, _actor);
    } catch (ServiceExceptionConnect e) {
      if (log.isLoggable(Level.FINEST)) {
        log.log(Level.FINEST, e.toString(), e);
      }
      else {
        log.fine(e.toString());
      }
    } catch (IllegalStateException e) {
      if (log.isLoggable(Level.FINE)) {
        log.log(Level.FINE, e.toString(), e);
      }
    } catch (Throwable e) {
      if (log.isLoggable(Level.FINER)) {
        log.log(Level.FINER, e.toString(), e);
      }
      else {
        log.fine(e.toString());
      }
    }
  }
108969
public void sendData(InputStream in) throws ResponseException {
        if(con.isClosed()) return;

        Socket socket = null;
        try {
            socket = conHandler.createDataSocket();
            dataConnections.add(socket);
            OutputStream out = socket.getOutputStream();

            byte[] buffer = new byte[bufferSize];
            int len;
            while((len = in.read(buffer)) != -1) {
                Utils.write(out, buffer, len, conHandler.isAsciiMode());
                bytesTransferred += len;
            }

            out.flush();
            Utils.closeQuietly(out);
            Utils.closeQuietly(in);
            Utils.closeQuietly(socket);
        } catch(SocketException ex) {
            throw new ResponseException(426, "Transfer aborted");
        } catch(IOException ex) {
            throw new ResponseException(425, "An error occurred while transferring the data");
        } finally {
            onUpdate();
            if(socket != null) dataConnections.remove(socket);
        }
    }
1090467
@Override
    public boolean sendCommand(String command) {
        try {
            sendCommand2(command);
        } catch (Exception ex) {
            logger.error("Could not run command " + command, ex);
            return false;
        }
        return true;
    }
1258447
public static void streamOut(OutputStream out, Object object) throws IOException {
        streamOut(out, object, false);
    }
645301
public static void copy(InputStream in,
			OutputStream out) throws IOException {
		copy(in, out, false);
	}
686681
public static void write(HttpServletResponse response, InputStream in, int bufferSize) {
		ServletOutputStream out = null;
		try {
			out = response.getOutputStream();
			IoUtil.copy(in, out, bufferSize);
		} catch (IOException e) {
			throw new UtilException(e);
		} finally {
			IoUtil.close(out);
			IoUtil.close(in);
		}
	}
1291366
public static void copy(byte[] in, OutputStream out) throws IOException {
        assert in != null : "No input byte array specified";
        assert out != null : "No output stream specified";
        try {
            out.write(in);
        } finally {
            try {
                out.close();
            } catch (IOException ex) {
            }
        }
    }
450145
protected /*HttpBuilder*/void streamOut(InputStream in) {
//        StreamResponse resp = new StreamResponse(context, in);
//        context.setControllerResponse(resp);
//        return new HttpBuilder(resp);
        //TODO finish and TEST the god damn method
        //------------------
        Result r = ResultBuilder.ok()
                .contentType(MediaType.APPLICATION_OCTET_STREAM)
                .renderable(in);
//        context.setControllerResponse(r);
        result = r;
    }
897874
@Override
  public void deliver(WriteStream os, OutHttp2 outHttp)
    throws IOException
  {
    OutHeader outHeader = outHttp.getOutHeader();
    
    int streamId = streamId(outHttp);
    
    outHeader.openHeaders(streamId,
                          getPad(),
                          getPriorityDependency(), 
                          getPriorityWeight(),
                          isPriorityExclusive(),
                          getFlagsHttp());
    
    writeHeaders(outHeader);
    
    outHeader.closeHeaders();
  }
924287
public static void transferStream(Reader in, Writer out)
   {
       try {
           char[] cbuf = new char[1000];
           int iLen = 0;
           while ((iLen = in.read(cbuf, 0, cbuf.length)) > 0)
           {   // Write the entire file to the output buffer
               out.write(cbuf, 0, iLen);
           }
           in.close();
       } catch (MalformedURLException ex)  {
           ex.printStackTrace();
       } catch (IOException ex) {
           ex.printStackTrace();
       }
   }