List<BlockInfo> parseLine(String line) throws IOException {
    if (currentState == State.DEFAULT) {
      if (line.contains("<INodeSection>")) {
        transitionTo(State.INODE_SECTION);
      } else {
        return Collections.emptyList();
      }
    }
    if (line.contains("<inode>")) {
      transitionTo(State.INODE);
    }
    if (line.contains("<type>FILE</type>")) {
      transitionTo(State.FILE);
    }
    List<String> replicationStrings = valuesFromXMLString(line, "replication");
    if (!replicationStrings.isEmpty()) {
      if (replicationStrings.size() > 1) {
        throw new IOException(String.format("Found %s replication strings",
            replicationStrings.size()));
      }
      transitionTo(State.FILE_WITH_REPLICATION);
      currentReplication = Short.parseShort(replicationStrings.get(0));
    }
    Matcher blockMatcher = BLOCK_PATTERN.matcher(line);
    List<BlockInfo> blockInfos = new ArrayList<>();
    while (blockMatcher.find()) {
      if (currentState != State.FILE_WITH_REPLICATION) {
        throw new IOException(
            "Found a block string when in state: " + currentState);
      }
      long id = Long.parseLong(blockMatcher.group(1));
      long gs = Long.parseLong(blockMatcher.group(2));
      long size = Long.parseLong(blockMatcher.group(3));
      blockInfos.add(new BlockInfo(id, gs, size, currentReplication));
    }
    if (line.contains("</inode>")) {
      transitionTo(State.INODE_SECTION);
    }
    if (line.contains("</INodeSection>")) {
      transitionTo(State.DEFAULT);
    }
    return blockInfos;
  }
@Test
  public void testNonInodeSectionIgnored() throws Exception {
    String[] lines = {
        "<INodeSection>",
        "</INodeSection>",
        "<OtherSection>",
        "<inode><id>1</id><type>FILE</type><name>fake-file</name>"
            + "<replication>1</replication>",
        "<blocks><block><id>2</id><genstamp>1</genstamp>"
            + "<numBytes>1</numBytes></block>",
        "</inode>",
        "<replication>3</replication>",
        "</OtherSection>"
    };

    XMLParser parser = new XMLParser();
    for (String line : lines) {
      assertTrue((parser.parseLine(line).isEmpty()));
    }
  }