/** {@inheritDoc} */
  public void loadData(final InputStream input, final String name)
      throws IOException, OrekitException {

    // set up a reader for line-oriented bulletin B files
    final BufferedReader reader = new BufferedReader(new InputStreamReader(input));

    // read all file, ignoring header
    synchronized (this) {
      int lineNumber = 0;
      boolean inHeader = true;
      for (String line = reader.readLine(); line != null; line = reader.readLine()) {
        ++lineNumber;
        boolean parsed = false;

        if (linePattern.matcher(line).matches()) {
          inHeader = false;
          // this is a data line, build an entry from the extracted fields
          final String[] fields = line.split(" +");
          final int year = Integer.parseInt(fields[YEAR_FIELD]);
          final int month = Integer.parseInt(fields[MONTH_FIELD]);
          final int day = Integer.parseInt(fields[DAY_FIELD]);
          final int mjd = Integer.parseInt(fields[MJD_FIELD]);
          if (new DateComponents(year, month, day).getMJD() == mjd) {
            // the first six fields are consistent with the expected format
            final double x = Double.parseDouble(fields[POLE_X_FIELD]) * ARC_SECONDS_TO_RADIANS;
            final double y = Double.parseDouble(fields[POLE_Y_FIELD]) * ARC_SECONDS_TO_RADIANS;
            final double dtu1 = Double.parseDouble(fields[UT1_UTC_FIELD]);
            final double lod = Double.parseDouble(fields[LOD_FIELD]);
            final double dpsi = Double.parseDouble(fields[DDPSI_FIELD]) * ARC_SECONDS_TO_RADIANS;
            final double deps = Double.parseDouble(fields[DDEPS_FIELD]) * ARC_SECONDS_TO_RADIANS;
            if (history1980 != null) {
              history1980.addEntry(new EOP1980Entry(mjd, dtu1, lod, dpsi, deps));
            }
            if (history2000 != null) {
              history2000.addEntry(new EOP2000Entry(mjd, dtu1, lod, x, y));
            }
            parsed = true;
          }
        }
        if (!(inHeader || parsed)) {
          throw new OrekitException(
              "unable to parse line {0} in IERS data file {1}", lineNumber, name);
        }
      }

      // check if we have read something
      if (inHeader) {
        throw new OrekitException("file {0} is not a supported IERS data file", name);
      }
    }
  }
  /** {@inheritDoc} */
  public void loadData(final InputStream input, final String name)
      throws OrekitException, IOException {

    // set up a reader for line-oriented bulletin B files
    final BufferedReader reader = new BufferedReader(new InputStreamReader(input));

    // Extract mjd bounds from section 1
    int mjdMin = -1;
    int mjdMax = -1;
    boolean inFinalValuesPart = false;
    for (String line = reader.readLine(); line != null; line = reader.readLine()) {
      Matcher matcher = finalValuesStartPattern.matcher(line);
      if (matcher.matches()) {
        // we are entering final values part (in section 1)
        inFinalValuesPart = true;
      } else if (inFinalValuesPart) {
        matcher = section1DataPattern.matcher(line);
        if (matcher.matches()) {
          // this is a data line, build an entry from the extracted fields
          final int mjd = Integer.parseInt(matcher.group(1));
          if (mjdMin < 0) {
            mjdMin = mjd;
          } else {
            mjdMax = mjd;
          }
        } else {
          matcher = finalValuesEndPattern.matcher(line);
          if (matcher.matches()) {
            // we leave final values part
            break;
          }
        }
      }
    }

    // read the data lines in the final values part inside section 2
    synchronized (this) {
      boolean inSection2 = false;
      for (String line = reader.readLine(); line != null; line = reader.readLine()) {
        Matcher matcher = sectionHeaderPattern.matcher(line);
        if (matcher.matches() && "2".equals(matcher.group(1))) {
          // we are entering section 2
          inSection2 = true;
        } else if (inSection2) {
          matcher = section2DataPattern.matcher(line);
          if (matcher.matches()) {
            // this is a data line, build an entry from the extracted fields
            final int date = Integer.parseInt(matcher.group(1));
            final double x = Double.parseDouble(matcher.group(2)) * ARC_SECONDS_TO_RADIANS;
            final double y = Double.parseDouble(matcher.group(3)) * ARC_SECONDS_TO_RADIANS;
            final double dtu1 = Double.parseDouble(matcher.group(4));
            final double lod = Double.parseDouble(matcher.group(5)) * MILLI_SECONDS_TO_SECONDS;
            final double dpsi = Double.parseDouble(matcher.group(6)) * MILLI_ARC_SECONDS_TO_RADIANS;
            final double deps = Double.parseDouble(matcher.group(7)) * MILLI_ARC_SECONDS_TO_RADIANS;
            if (date >= mjdMin) {
              if (history1980 != null) {
                history1980.addEntry(new EOP1980Entry(date, dtu1, lod, dpsi, deps));
              }
              if (history2000 != null) {
                history2000.addEntry(new EOP2000Entry(date, dtu1, lod, x, y));
              }
              if (date >= mjdMax) {
                // don't bother reading the rest of the file
                return;
              }
            }
          }
        }
      }
    }
  }