Support optionally dumping the properties stream
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1688091 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
efc96e1d8e
commit
8eae3df77e
@ -16,22 +16,43 @@
|
|||||||
==================================================================== */
|
==================================================================== */
|
||||||
package org.apache.poi.poifs.dev;
|
package org.apache.poi.poifs.dev;
|
||||||
|
|
||||||
import org.apache.poi.poifs.filesystem.*;
|
|
||||||
|
|
||||||
import java.io.FileInputStream;
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.FileInputStream;
|
||||||
import java.io.FileOutputStream;
|
import java.io.FileOutputStream;
|
||||||
|
import java.io.IOException;
|
||||||
import java.io.OutputStream;
|
import java.io.OutputStream;
|
||||||
|
import java.lang.reflect.Field;
|
||||||
|
import java.nio.ByteBuffer;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
|
|
||||||
|
import org.apache.poi.poifs.filesystem.DirectoryEntry;
|
||||||
|
import org.apache.poi.poifs.filesystem.DocumentInputStream;
|
||||||
|
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.NPOIFSStream;
|
||||||
|
import org.apache.poi.poifs.storage.HeaderBlock;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Dump internal structure of a OLE2 file into file system
|
* Dump internal structure of a OLE2 file into file system
|
||||||
*/
|
*/
|
||||||
public class POIFSDump {
|
public class POIFSDump {
|
||||||
|
|
||||||
public static void main(String[] args) throws Exception {
|
public static void main(String[] args) throws Exception {
|
||||||
|
if (args.length == 0) {
|
||||||
|
System.err.println("Must specify at least one file to dump");
|
||||||
|
System.exit(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
boolean withProps = false;
|
||||||
for (int i = 0; i < args.length; i++) {
|
for (int i = 0; i < args.length; i++) {
|
||||||
|
if (args[i].equalsIgnoreCase("-dumprops") ||
|
||||||
|
args[i].equalsIgnoreCase("-dump-props") ||
|
||||||
|
args[i].equalsIgnoreCase("-dump-properties")) {
|
||||||
|
withProps = true;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
System.out.println("Dumping " + args[i]);
|
System.out.println("Dumping " + args[i]);
|
||||||
FileInputStream is = new FileInputStream(args[i]);
|
FileInputStream is = new FileInputStream(args[i]);
|
||||||
NPOIFSFileSystem fs = new NPOIFSFileSystem(is);
|
NPOIFSFileSystem fs = new NPOIFSFileSystem(is);
|
||||||
@ -42,6 +63,13 @@ public class POIFSDump {
|
|||||||
file.mkdir();
|
file.mkdir();
|
||||||
|
|
||||||
dump(root, file);
|
dump(root, file);
|
||||||
|
|
||||||
|
if (withProps) {
|
||||||
|
Field headerF = NPOIFSFileSystem.class.getDeclaredField("_header");
|
||||||
|
headerF.setAccessible(true);
|
||||||
|
HeaderBlock header = (HeaderBlock)headerF.get(fs);
|
||||||
|
dump(fs, header.getPropertyStart(), file);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -72,4 +100,17 @@ public class POIFSDump {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
public static void dump(NPOIFSFileSystem fs, int startBlock, File parent) throws IOException {
|
||||||
|
File file = new File(parent, "properties");
|
||||||
|
FileOutputStream out = new FileOutputStream(file);
|
||||||
|
NPOIFSStream stream = new NPOIFSStream(fs, startBlock);
|
||||||
|
|
||||||
|
byte[] b = new byte[fs.getBigBlockSize()];
|
||||||
|
for (ByteBuffer bb : stream) {
|
||||||
|
int len = bb.remaining();
|
||||||
|
bb.get(b);
|
||||||
|
out.write(b, 0, len);
|
||||||
|
}
|
||||||
|
out.close();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user