Пример #1
0
  /**
   * Parses the FileChannel, in the range [start, end) and prints the elements found
   *
   * <p>Elements are printed, indented by "level" number of spaces. If an element is a container,
   * then its contents will be, recursively, printed, with a greater indentation.
   *
   * @param fc
   * @param level
   * @param start
   * @param end
   * @throws IOException
   */
  private void print(FileChannel fc, int level, long start, long end) throws IOException {
    fc.position(start);
    if (end <= 0) {
      end = start + fc.size();
      System.out.println("Setting END to " + end);
    }
    while (end - fc.position() > 8) {
      long begin = fc.position();
      ByteBuffer bb = ByteBuffer.allocate(8);
      fc.read(bb);
      bb.rewind();
      long size = IsoTypeReader.readUInt32(bb);
      String type = IsoTypeReader.read4cc(bb);
      long fin = begin + size;
      // indent by the required number of spaces
      for (int i = 0; i < level; i++) {
        System.out.print(" ");
      }

      System.out.println(type + "@" + (begin) + " size: " + size);
      if (containers.contains(type)) {
        print(fc, level + 1, begin + 8, fin);
        if (fc.position() != fin) {
          System.out.println("End of container contents at " + fc.position());
          System.out.println("  FIN = " + fin);
        }
      } else {

      }

      fc.position(fin);
    }
  }