private int read() throws IOException {
    if (reader != null)
      return reader.read();
    else if (input != null)
      return input.read();
    else
      throw new IllegalStateException();
  }