class ParsableByteArray {

  public @Nullable String readLine() {
    if (bytesLeft() == 0) {
      return null;
    }
    int lineLimit = position;
    while (lineLimit < limit && !Util.isLinebreak(data[lineLimit])) {
      lineLimit++;
    }
    if (lineLimit - position >= 3 && data[position] == (byte) 0xEF
        && data[position + 1] == (byte) 0xBB && data[position + 2] == (byte) 0xBF) {
      // There's a UTF-8 byte order mark at the start of the line. Discard it.
      position += 3;
    }
    String line = Util.fromUtf8Bytes(data, position, lineLimit - position);
    position = lineLimit;
    if (position == limit) {
      return line;
    }
    if (data[position] == '\r') {
      position++;
      if (position == limit) {
        return line;
      }
    }
    if (data[position] == '\n') {
      position++;
    }
    return line;
  }

  public  ParsableByteArray();
  public  ParsableByteArray(int limit);
  public  ParsableByteArray(byte[] data);
  public  ParsableByteArray(byte[] data, int limit);

}