/**
   * Write a String to the output stream as translated bytes.
   *
   * @param s The String to write.
   * @throws IOException
   */
  void writeAscii(String s) throws IOException {
    String charsetName = socket.getCharset();

    if (charsetName != null) {
      try {
        write(s.getBytes(charsetName));
      } catch (UnsupportedEncodingException e) {
        write(s.getBytes());
      }
    } else {
      write(s.getBytes());
    }
  }
  /**
   * Copy the contents of a Reader stream to the server as bytes.
   *
   * <p>NB. Only reliable where the charset is single byte.
   *
   * @param in The Reader object with the data.
   * @param length The length of the data in bytes.
   * @throws IOException
   */
  void writeReaderBytes(Reader in, int length) throws IOException {
    char buffer[] = new char[1024];

    for (int i = 0; i < length; ) {
      int result = in.read(buffer);

      if (result == -1) {
        throw new java.io.IOException("Data in stream less than specified by length");
      } else if (i + result > length) {
        throw new java.io.IOException("More data in stream than specified by length");
      }

      write(Support.encodeString(socket.getCharset(), new String(buffer, 0, result)));
      i += result;
    }
  }