/**
  * Handle a simple ping request.
  *
  * @param channel the channel
  * @param header the protocol header
  * @throws IOException for any error
  */
 protected static void handlePing(final Channel channel, final ManagementProtocolHeader header)
     throws IOException {
   final ManagementProtocolHeader response = new ManagementPongHeader(header.getVersion());
   final MessageOutputStream output = channel.writeMessage();
   try {
     writeHeader(response, output);
     output.close();
   } finally {
     StreamUtils.safeClose(output);
   }
 }
 protected static void writeResponse(
     final Channel channel, final ManagementRequestHeader header, final Exception error)
     throws IOException {
   final ManagementResponseHeader response = ManagementResponseHeader.create(header, error);
   final MessageOutputStream output = channel.writeMessage();
   try {
     writeHeader(response, output);
     output.close();
   } finally {
     StreamUtils.safeClose(output);
   }
 }
 private void sendVersionZeroHeader(Channel channel) throws IOException {
   log.debug("Selecting version 0x00 to receive full version list.");
   CancellableDataOutputStream dos = new CancellableDataOutputStream(channel.writeMessage());
   try {
     dos.writeBytes(JMX);
     dos.writeByte(0x00);
     String remotingJMXVersion = Version.getVersionString();
     byte[] versionBytes = remotingJMXVersion.getBytes("UTF-8");
     dos.writeInt(versionBytes.length);
     dos.write(versionBytes);
   } catch (IOException e) {
     dos.cancel();
     throw e;
   } finally {
     IoUtils.safeClose(dos);
   }
 }