01: /* ====================================================================
02: Licensed to the Apache Software Foundation (ASF) under one or more
03: contributor license agreements. See the NOTICE file distributed with
04: this work for additional information regarding copyright ownership.
05: The ASF licenses this file to You under the Apache License, Version 2.0
06: (the "License"); you may not use this file except in compliance with
07: the License. You may obtain a copy of the License at
08:
09: http://www.apache.org/licenses/LICENSE-2.0
10:
11: Unless required by applicable law or agreed to in writing, software
12: distributed under the License is distributed on an "AS IS" BASIS,
13: WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14: See the License for the specific language governing permissions and
15: limitations under the License.
16: ==================================================================== */
17:
18: package org.apache.poi.poifs.dev;
19:
20: import java.io.*;
21:
22: import java.util.*;
23:
24: import org.apache.poi.poifs.filesystem.POIFSFileSystem;
25:
26: /**
27: * A simple viewer for POIFS files
28: *
29: * @author Marc Johnson (mjohnson at apache dot org)
30: */
31:
32: public class POIFSViewer {
33:
34: /**
35: * Display the contents of multiple POIFS files
36: *
37: * @param args the names of the files to be displayed
38: */
39:
40: public static void main(final String args[]) {
41: if (args.length < 0) {
42: System.err
43: .println("Must specify at least one file to view");
44: System.exit(1);
45: }
46: boolean printNames = (args.length > 1);
47:
48: for (int j = 0; j < args.length; j++) {
49: viewFile(args[j], printNames);
50: }
51: }
52:
53: private static void viewFile(final String filename,
54: final boolean printName) {
55: if (printName) {
56: StringBuffer flowerbox = new StringBuffer();
57:
58: flowerbox.append(".");
59: for (int j = 0; j < filename.length(); j++) {
60: flowerbox.append("-");
61: }
62: flowerbox.append(".");
63: System.out.println(flowerbox);
64: System.out.println("|" + filename + "|");
65: System.out.println(flowerbox);
66: }
67: try {
68: POIFSViewable fs = new POIFSFileSystem(new FileInputStream(
69: filename));
70: List strings = POIFSViewEngine.inspectViewable(fs, true, 0,
71: " ");
72: Iterator iter = strings.iterator();
73:
74: while (iter.hasNext()) {
75: System.out.print(iter.next());
76: }
77: } catch (IOException e) {
78: System.out.println(e.getMessage());
79: }
80: }
81: } // end public class POIFSViewer
|