Read a string in the standard VoltDB way. That is, four
bytes of length info followed by the bytes of characters
encoded in UTF-8.

@return The String value read from the stream.
@throws IOException Rethrows any IOExceptions.
542464
public String readString() throws IOException {
        final int len = readInt();

        // check for null string
        if (len == VoltType.NULL_STRING_LENGTH) {
            return null;
        }

        if (len < VoltType.NULL_STRING_LENGTH) {
            throw new IOException("String length is negative " + len);
        }
        if (len > buffer.remaining()) {
            throw new IOException("String length is bigger than total buffer " + len);
        }

        // now assume not null
        final byte[] strbytes = new byte[len];
        readFully(strbytes);
        return new String(strbytes, Constants.UTF8ENCODING);
    }
329795
@Override
	public int read() throws IOException {
		int ch = super.read();
		if (!escaped && charsToEscape.contains((char) ch)) {
			// special case for non-displayable characters
			switch (ch) {
			case '\n':
				ch = 'n';
				break;
			case '\r':
				ch = 'r';
				break;
			case '\t':
				ch = 't';
				break;
			}
			super.unread(ch);
			escaped = true;
			ch = '\\';
		} else {
			escaped = false;
		}
		return ch;
	}
1252402
public int read() throws IOException {
        synchronized (lock) {
            ensureOpen();
            for (;;) {
                if (nextChar >= nChars) {
                    fill();
                    if (nextChar >= nChars)
                        return -1;
                }
                if (skipLF) {
                    skipLF = false;
                    if (cb[nextChar] == '\n') {
                        nextChar++;
                        continue;
                    }
                }
                return cb[nextChar++];
            }
        }
    }
1267961
private int parseUTF8Char()
        throws IOException
    {
        int ch = read();

        if (ch < 0x80)
            return ch;
        else if ((ch & 0xe0) == 0xc0) {
            int ch1 = read();
            int v = ((ch & 0x1f) << 6) + (ch1 & 0x3f);

            return v;
        }
        else if ((ch & 0xf0) == 0xe0) {
            int ch1 = read();
            int ch2 = read();
            int v = ((ch & 0x0f) << 12) + ((ch1 & 0x3f) << 6) + (ch2 & 0x3f);

            return v;
        }
        else
            throw error("bad utf-8 encoding at " + codeName(ch));
    }
301596
public String readUnmodifiedUTF ()
        throws IOException
    {
        // find out how many raw bytes of UTF8 data there is
        int utflen = readUnsignedShort();
        // read precisely that many into a buffer
        byte[] bbuf = new byte[utflen];
        in.read(bbuf);
        return new String(bbuf, "UTF-8");
        //return new String(bbuf, Charsets.UTF_8); // TODO Java 6 (Charsets is from guava)
    }
1291991
public String readStringEOF() {
        byte[] result = new byte[byteBuf.readableBytes()];
        byteBuf.readBytes(result);
        return new String(result);
    }
919404
@Override
	public String readString() {
		int limit = buf.limit();
		int len = 0;
		switch (currentDataType) {
		case AMF.TYPE_LONG_STRING:
			log.trace("Long string type");
			len = buf.getInt();
			if (len > limit) {
				len = limit;
			}
			break;
		case AMF.TYPE_STRING:
			log.trace("Std string type");
			len = buf.getUnsignedShort();
			break;
		default:
			log.debug("Unknown AMF type: {}", currentDataType);
		}
		log.debug("Length: {} limit: {}", len, limit);
		byte[] str = new byte[len];
		buf.get(str);
		String string = bufferToString(str);
		return string;
	}
226450
public static String readString(DataInputStream dis) throws IOException {
        byte[] bytes = new byte[MAX_SIZE];
        byte b = dis.readByte();
        int i = -1;
        StringBuilder sb = new StringBuilder();
        while (b != 32 && b != 10) {
            i++;
            bytes[i] = b;
            b = dis.readByte();
            if (i == 49) {
                sb.append(new String(bytes, "UTF-8"));
                i = -1;
                bytes = new byte[MAX_SIZE];
            }
        }
        sb.append(new String(bytes, 0, i + 1, "UTF-8"));
        return sb.toString();
    }
998224
public static String readString(DataInput in) throws IOException {
		// the length we read is offset by one, because a length of zero indicates a null value
		int len = in.readUnsignedByte();
		
		if (len == 0) {
			return null;
		}

		if (len >= HIGH_BIT) {
			int shift = 7;
			int curr;
			len = len & 0x7f;
			while ((curr = in.readUnsignedByte()) >= HIGH_BIT) {
				len |= (curr & 0x7f) << shift;
				shift += 7;
			}
			len |= curr << shift;
		}
		
		// subtract one for the null length
		len -= 1;
		
		final char[] data = new char[len];

		for (int i = 0; i < len; i++) {
			int c = in.readUnsignedByte();
			if (c < HIGH_BIT) {
				data[i] = (char) c;
			} else {
				int shift = 7;
				int curr;
				c = c & 0x7f;
				while ((curr = in.readUnsignedByte()) >= HIGH_BIT) {
					c |= (curr & 0x7f) << shift;
					shift += 7;
				}
				c |= curr << shift;
				data[i] = (char) c;
			}
		}
		
		return new String(data, 0, len);
	}
1181652
public static String readString(DataInput in) throws IOException {
        int length = in.readInt();
        if (length == -1)
            return null;
        byte[] buffer = new byte[length];
        in.readFully(buffer); // could/should use readFully(buffer,0,length)?
        return new String(buffer, "UTF-8");
    }
1120259
public int readLength() throws IOException {
		int length = 0;

		byte b = (byte) this.read();

		// This is short form. The short form can be used if the number of
		// octets in the Value part is less than or
		// equal to 127, and can be used whether the Value part is primitive or
		// constructed. This form is identified by
		// encoding bit 8 as zero, with the length count in bits 7 to 1 (as
		// usual, with bit 7 the most significant bit
		// of the length).
		if ((b & 0x80) == 0) {
			return b;
		}

		// This is indefinite form. The indefinite form of length can only be
		// used (but does not have to be) if the V
		// part is constructed, that
		// is to say, consists of a series of TLVs. In the indefinite form of
		// length the first bit of the first octet is
		// set to 1, as for the long form, but the value N is set to zero.
		b = (byte) (b & 0x7F);
		if (b == 0) {
			return Tag.Indefinite_Length;
		}

		// If bit 8 of the first length octet is set to 1, then we have the long
		// form of length. In long form, the first
		// octet encodes in its remaining seven bits a value N which is the
		// length of a series of octets that themselves
		// encode the length of the Value part.
		byte temp;
		for (int i = 0; i < b; i++) {
			temp = (byte) this.read();
			length = (length << 8) | (0x00FF & temp);
		}

		return length;
	}
109228
@Override
	public int read() throws IOException {
		if (pos >= limit)
			return -1;

		try {
			int c = buf[pos] & 0xff;
			if (c < 0x80) {
				pos++;
			} else if (c < 0xE0) {
				c = (char) ((c & 0x1F) << 6 | buf[pos + 1] & 0x3F);
				pos += 2;
			} else {
				c = (char) ((c & 0x0F) << 12 | (buf[pos + 1] & 0x3F) << 6 | (buf[pos + 2] & 0x3F));
				pos += 3;
			}
			if (pos > limit)
				throw new IOException();
			return c;
		} catch (ArrayIndexOutOfBoundsException e) {
			throw new IOException(e);
		}
	}
785509
public String readLine() throws IOException {
        StringBuffer buf = new StringBuffer(80);
        int line = mLineNumber;
        int c;
        while (line == mLineNumber && (c = read()) >= 0) {
            buf.append((char)c);
        }
        return buf.toString();
    }
170340
public String getString(Charset charset) throws IOException
    {
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        byte cc = get();
        while (cc != 0)
        {
            baos.write(cc);
            cc = get();
        }
        byte[] buf = baos.toByteArray();
        return new String(buf, charset);
    }
348780
public final long readTTFULong() throws IOException {
        long ret = readTTFUByte();
        ret = (ret << 8) + readTTFUByte();
        ret = (ret << 8) + readTTFUByte();
        ret = (ret << 8) + readTTFUByte();

        return ret;
    }
867717
public String readString(final JBBPByteOrder byteOrder) throws IOException {
    final int prefix = this.readByte();
    final int len;
    if (prefix == 0) {
      len = 0;
    } else if (prefix == 0xFF) {
      len = -1;
    } else if (prefix < 0x80) {
      len = prefix;
    } else if ((prefix & 0xF0) == 0x80) {
      switch (prefix & 0x0F) {
        case 1: {
          len = this.readByte();
        }
        break;
        case 2: {
          len = this.readUnsignedShort(byteOrder);
        }
        break;
        case 3: {
          int buffer;
          if (byteOrder == JBBPByteOrder.BIG_ENDIAN) {
            buffer = (this.readByte() << 16) | (this.readByte() << 8) | this.readByte();
          } else {
            buffer = this.readByte() | (this.readByte() << 8) | (this.readByte() << 16);
          }
          len = buffer;
        }
        break;
        case 4: {
          len = this.readInt(byteOrder);
        }
        break;
        default: {
          throw makeIOExceptionForWrongPrefix(prefix);
        }
      }
    } else {
      throw makeIOExceptionForWrongPrefix(prefix);
    }

    final String result;
    if (len < 0) {
      result = null;
    } else if (len == 0) {
      result = "";
    } else {
      result = JBBPUtils.utf8ToStr(this.readByteArray(len));
    }

    return result;
  }
307079
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);
  }