Allow POIFSLister to switch between the two different POIFS implementations when listing

git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1053274 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Nick Burch 2010-12-28 07:16:12 +00:00
parent 8d19052b6a
commit bfcc46192c
1 changed files with 66 additions and 51 deletions

View File

@ -17,12 +17,15 @@
package org.apache.poi.poifs.dev;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.util.Iterator;
import org.apache.poi.poifs.filesystem.DirectoryNode;
import org.apache.poi.poifs.filesystem.DocumentNode;
import org.apache.poi.poifs.filesystem.Entry;
import org.apache.poi.poifs.filesystem.NPOIFSFileSystem;
import org.apache.poi.poifs.filesystem.POIFSFileSystem;
/**
@ -43,16 +46,28 @@ public class POIFSLister {
}
boolean withSizes = false;
boolean newPOIFS = true;
for (int j = 0; j < args.length; j++) {
if (args[j].equalsIgnoreCase("-size") || args[j].equalsIgnoreCase("-sizes")) {
withSizes = true;
} else if (args[j].equalsIgnoreCase("-old") || args[j].equalsIgnoreCase("-old-poifs")) {
newPOIFS = false;
} else {
if(newPOIFS) {
viewFile(args[j], withSizes);
} else {
viewFileOld(args[j], withSizes);
}
}
}
}
public static void viewFile(final String filename, boolean withSizes) throws IOException {
NPOIFSFileSystem fs = new NPOIFSFileSystem(new File(filename));
displayDirectory(fs.getRoot(), "", withSizes);
}
public static void viewFileOld(final String filename, boolean withSizes) throws IOException {
POIFSFileSystem fs = new POIFSFileSystem(new FileInputStream(filename));
displayDirectory(fs.getRoot(), "", withSizes);
}
@ -62,9 +77,9 @@ public class POIFSLister {
String newIndent = indent + " ";
boolean hadChildren = false;
for (Iterator it = dir.getEntries(); it.hasNext();) {
for(Iterator<Entry> it = dir.getEntries(); it.hasNext();) {
hadChildren = true;
Object entry = it.next();
Entry entry = it.next();
if (entry instanceof DirectoryNode) {
displayDirectory((DirectoryNode) entry, newIndent, withSizes);
} else {
@ -76,8 +91,8 @@ public class POIFSLister {
name = name.substring(1) + " <" + altname + ">";
}
if (withSizes) {
size = " [" + doc.getSize() + " / 0x" + Integer.toHexString(doc.getSize())
+ "]";
size = " [" + doc.getSize() + " / 0x" +
Integer.toHexString(doc.getSize()) + "]";
}
System.out.println(newIndent + name + size);
}