code: public static String readStringOpt(DataInput in) throws IOException {
      final int length = WritableUtils.readVInt(in);
      if (length == NULL_STRING_LENGTH) {
        return null;
      }
      byte [] bytes = new byte[length];
      in.readFully(bytes, 0, length);
      char[] charArray = UTF8.getCharArray(length);
      for (int i = 0; i < bytes.length; i++) {
        if (bytes[i] < UTF8.MIN_ASCII_CODE) {
          // non-ASCII codepoints' higher bytes
          // are of the form (10xxxxxx), hence the bytes
          // represent a non-ASCII string
          // do expensive conversion
          return decode(bytes);
        }
        // copy to temporary array
        charArray[i] = (char) bytes[i];
      }
      // only ASCII bytes, do fast conversion
      // using bytes as actual characters
      return new String(charArray, 0, length);
    }
docs: Read a UTF8 encoded string from in