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