KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > poi > poifs > dev > POIFSViewer


1
2 /* ====================================================================
3    Copyright 2002-2004 Apache Software Foundation
4
5    Licensed under the Apache License, Version 2.0 (the "License");
6    you may not use this file except in compliance with the License.
7    You may obtain a copy of the License at
8
9        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
19 package org.apache.poi.poifs.dev;
20
21 import java.io.*;
22
23 import java.util.*;
24
25 import org.apache.poi.poifs.filesystem.POIFSFileSystem;
26
27 /**
28  * A simple viewer for POIFS files
29  *
30  * @author Marc Johnson (mjohnson at apache dot org)
31  */

32
33 public class POIFSViewer
34 {
35
36     /**
37      * Display the contents of multiple POIFS files
38      *
39      * @param args the names of the files to be displayed
40      */

41
42     public static void main(final String JavaDoc args[])
43     {
44         if (args.length < 0)
45         {
46             System.err.println("Must specify at least one file to view");
47             System.exit(1);
48         }
49         boolean printNames = (args.length > 1);
50
51         for (int j = 0; j < args.length; j++)
52         {
53             viewFile(args[ j ], printNames);
54         }
55     }
56
57     private static void viewFile(final String JavaDoc filename,
58                                  final boolean printName)
59     {
60         if (printName)
61         {
62             StringBuffer JavaDoc flowerbox = new StringBuffer JavaDoc();
63
64             flowerbox.append(".");
65             for (int j = 0; j < filename.length(); j++)
66             {
67                 flowerbox.append("-");
68             }
69             flowerbox.append(".");
70             System.out.println(flowerbox);
71             System.out.println("|" + filename + "|");
72             System.out.println(flowerbox);
73         }
74         try
75         {
76             POIFSViewable fs =
77                 new POIFSFileSystem(new FileInputStream(filename));
78             List strings = POIFSViewEngine.inspectViewable(fs, true,
79                                         0, " ");
80             Iterator iter = strings.iterator();
81
82             while (iter.hasNext())
83             {
84                 System.out.print(iter.next());
85             }
86         }
87         catch (IOException e)
88         {
89             System.out.println(e.getMessage());
90         }
91     }
92 } // end public class POIFSViewer
93

94
Popular Tags