private static int readInteger(InputStream is)
    throws IOException
  {
    int size = 0;
    int sign = 1;
    int read = is.read();
    if (read == '-')
    {
      read = is.read();
      sign = -1;
    }

    do
    {
      if (read == CR)
      {
        if (is.read() == LF)
        {
          break;
        }
      }

      int value = read - ZERO;
      if (value >= 0 && value < 10)
      {
        size *= 10;
        size += value;
      }
      else
      {
        throw new IOException("Invalid character in integer");
      }

      read = is.read();
    }
    while (true);

    return size * sign;
  }