code: public String getString(Charset cs) {
          // find indexof \0 and create a string for the charset
          int nullAt = indexOf((byte) 0);
          boolean utf16 = cs.name().startsWith("UTF-16");
          if (utf16) {
              int oldPos = _buf.position();
              boolean nullFound = false;
              while (!nullFound && (nullAt != -1)) {
                  if (_buf.get(nullAt + 1) == 0) {
                      nullFound = true;
                      break;
                  }
                  _buf.position(nullAt + 1);
                  nullAt = indexOf((byte) 0);
              }
              if (!nullFound) {
                  throw new IllegalStateException("The string being read is not UTF-16");
              }
              _buf.position(oldPos);
          }
  
          int newLimit;
          if (nullAt != -1) {
              newLimit = nullAt;
          } else {
              newLimit = _buf.limit();
          }
          int numBytes = newLimit - _buf.position();
          int oldLimit = _buf.limit();
          try {
              _buf.limit(newLimit);
              byte[] bytes = new byte[numBytes];
              _buf.get(bytes, 0, numBytes);
              String retVal = cs.decode(java.nio.ByteBuffer.wrap(bytes)).toString();
              return retVal;
          } finally {
              _buf.limit(oldLimit);
              if (nullAt != -1) {
                  _buf.get();
                  if (utf16) {
                      _buf.get();
                  }
              }
          }
      }
docs: Returns a null-terminated string from the buffer at the current position. If the end of buffer if reached before
  discovering a null terminator byte, then the decoded string includes all bytes up to the end of the buffer.
  
  @param cs the character set
  
  @return the null-terminated string