code: void writeClose(int code, ByteString reason) throws IOException {
      ByteString payload = ByteString.EMPTY;
      if (code != 0 || reason != null) {
        if (code != 0) {
          validateCloseCode(code);
        }
        Buffer buffer = new Buffer();
        buffer.writeShort(code);
        if (reason != null) {
          buffer.write(reason);
        }
        payload = buffer.readByteString();
      }
  
      try {
        writeControlFrame(OPCODE_CONTROL_CLOSE, payload);
      } finally {
        writerClosed = true;
      }
    }
docs: Send a close frame with optional code and reason.
  
  @param code Status code as defined by <a
  href="http://tools.ietf.org/html/rfc6455#section-7.4">Section 7.4 of RFC 6455</a> or {@code 0}.
  @param reason Reason for shutting down or {@code null}.