code: public void writeString(char[] buffer, int offset, int length)
          throws IOException
      {
          if (buffer == null) {
              if (SIZE < _offset + 16)
                  flushBuffer();
  
              _buffer[_offset++] = (byte) ('N');
          }
          else {
              while (length > 0x8000) {
                  int sublen = 0x8000;
  
                  if (SIZE < _offset + 16)
                      flushBuffer();
  
                  // chunk can't end in high surrogate
                  char tail = buffer[offset + sublen - 1];
  
                  if (0xd800 <= tail && tail <= 0xdbff)
                      sublen--;
  
                  _buffer[_offset++] = (byte) BC_STRING_CHUNK;
                  _buffer[_offset++] = (byte) (sublen >> 8);
                  _buffer[_offset++] = (byte) (sublen);
  
                  printString(buffer, offset, sublen);
  
                  length -= sublen;
                  offset += sublen;
              }
  
              if (SIZE < _offset + 16)
                  flushBuffer();
  
              if (length <= STRING_DIRECT_MAX) {
                  _buffer[_offset++] = (byte) (BC_STRING_DIRECT + length);
              }
              else if (length <= STRING_SHORT_MAX) {
                  _buffer[_offset++] = (byte) (BC_STRING_SHORT + (length >> 8));
                  _buffer[_offset++] = (byte) length;
              }
              else {
                  _buffer[_offset++] = (byte) ('S');
                  _buffer[_offset++] = (byte) (length >> 8);
                  _buffer[_offset++] = (byte) (length);
              }
  
              printString(buffer, offset, length);
          }
      }
docs: Writes a string value to the stream using UTF-8 encoding.
  The string will be written with the following syntax:
  
  <code><pre>
  S b16 b8 string-value
  </pre></code>
  
  If the value is null, it will be written as
  
  <code><pre>
  N
  </pre></code>
  
  @param value the string value to write.