code: private void setupResponse(ByteArrayOutputStream response,
                               Call call, Status status,
                               Writable rv, String errorClass, String error)
    throws IOException {
      response.reset();
      DataOutputStream out = new DataOutputStream(response);
      out.writeInt(call.id);                // write call id
      
      if (status == Status.SUCCESS) {
        out.write(Status.SUCCESSBYTES);
        rv.write(out);
      } else {
        out.writeInt(status.state);           // write status
        WritableUtils.writeString(out, errorClass);
        WritableUtils.writeString(out, error);
      }
      call.setResponse(ByteBuffer.wrap(response.toByteArray()));
    }
docs: Setup response for the IPC Call.
  
  @param response buffer to serialize the response into
  @param call {@link Call} to which we are setting up the response
  @param status {@link Status} of the IPC call
  @param rv return value for the IPC Call, if the call was successful
  @param errorClass error class, if the the call failed
  @param error error message, if the call failed
  @throws IOException