private static void dumpTree ( PrintWriter pw , DirectoryEntry dir , String prefix , boolean showData , boolean hex , String indent ) throws Exception { long byteCount ; for ( Iterator < Entry > iter = dir . getEntries ( ) ; iter . hasNext ( ) ; ) { Entry entry = iter . next ( ) ; if ( entry instanceof DirectoryEntry ) { String childIndent = indent ; if ( childIndent != null ) { childIndent += " " ; } String childPrefix = prefix + "[" + entry . getName ( ) + "]." ; pw . println ( "start dir: " + prefix + entry . getName ( ) ) ; dumpTree ( pw , ( DirectoryEntry ) entry , childPrefix , showData , hex , childIndent ) ; pw . println ( "end dir: " + prefix + entry . getName ( ) ) ; } else if ( entry instanceof DocumentEntry ) { if ( showData ) { pw . println ( "start doc: " + prefix + entry . getName ( ) ) ; if ( hex == true ) { byteCount = hexdump ( new DocumentInputStream ( ( DocumentEntry ) entry ) , pw ) ; } else { byteCount = asciidump ( new DocumentInputStream ( ( DocumentEntry ) entry ) , pw ) ; } pw . println ( "end doc: " + prefix + entry . getName ( ) + " (" + byteCount + " bytes read)" ) ; } else { if ( indent != null ) { pw . print ( indent ) ; } pw . println ( "doc: " + prefix + entry . getName ( ) ) ; } } else { pw . println ( "found unknown: " + prefix + entry . getName ( ) ) ; } } }
This method recursively descends the directory structure dumping details of any files it finds to the output file .