klute 2003/08/05 13:52:25
Modified: src/testcases/org/apache/poi/hpsf/basic Util.java
Log:
Revision Changes Path
1.6 +71 -4 jakarta-poi/src/testcases/org/apache/poi/hpsf/basic/Util.java
Index: Util.java
===================================================================
RCS file: /home/cvs/jakarta-poi/src/testcases/org/apache/poi/hpsf/basic/Util.java,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- Util.java 28 Jul 2003 17:01:03 -0000 1.5
+++ Util.java 5 Aug 2003 20:52:25 -0000 1.6
@@ -69,6 +69,11 @@
import java.util.List;
import java.util.Properties;
+import org.apache.poi.hpsf.MarkUnsupportedException;
+import org.apache.poi.hpsf.NoPropertySetStreamException;
+import org.apache.poi.hpsf.PropertySet;
+import org.apache.poi.hpsf.PropertySetFactory;
+import org.apache.poi.hpsf.UnexpectedPropertySetTypeException;
import org.apache.poi.poifs.eventfilesystem.POIFSReader;
import org.apache.poi.poifs.eventfilesystem.POIFSReaderEvent;
import org.apache.poi.poifs.eventfilesystem.POIFSReaderListener;
@@ -177,11 +182,11 @@
{
try
{
- POIFile f = new POIFile();
+ final POIFile f = new POIFile();
f.setName(event.getName());
f.setPath(event.getPath());
- InputStream in = event.getStream();
- ByteArrayOutputStream out = new ByteArrayOutputStream();
+ final InputStream in = event.getStream();
+ final ByteArrayOutputStream out = new ByteArrayOutputStream();
Util.copy(in, out);
out.close();
f.setBytes(out.toByteArray());
@@ -202,6 +207,68 @@
* only. */
for (int i = 0; i < poiFiles.length; i++)
r.registerListener(pfl, poiFiles[i]);
+
+ /* Read the POI filesystem. */
+ r.read(new FileInputStream(poiFs));
+ POIFile[] result = new POIFile[files.size()];
+ for (int i = 0; i < result.length; i++)
+ result[i] = (POIFile) files.get(i);
+ return result;
+ }
+
+
+
+ /**
+ * <p>Read all files from a POI filesystem which are property set streams
+ * and returns them as an array of [EMAIL PROTECTED]
org.apache.poi.hpsf.PropertySet}
+ * instances.</p>
+ *
+ * @param poiFs The name of the POI filesystem as seen by the
+ * operating system. (This is the "filename".)
+ *
+ * @return The property sets. The elements are ordered in the same way
+ * as the files in the POI filesystem.
+ *
+ * @exception FileNotFoundException if the file containing the POI
+ * filesystem does not exist
+ *
+ * @exception IOException if an I/O exception occurs
+ */
+ public static POIFile[] readPropertySets(final File poiFs)
+ throws FileNotFoundException, IOException
+ {
+ final List files = new ArrayList(7);
+ final POIFSReader r = new POIFSReader();
+ POIFSReaderListener pfl = new POIFSReaderListener()
+ {
+ public void processPOIFSReaderEvent(final POIFSReaderEvent event)
+ {
+ try
+ {
+ final POIFile f = new POIFile();
+ f.setName(event.getName());
+ f.setPath(event.getPath());
+ final InputStream in = event.getStream();
+ if (PropertySet.isPropertySetStream(in))
+ {
+ final ByteArrayOutputStream out =
+ new ByteArrayOutputStream();
+ Util.copy(in, out);
+ out.close();
+ f.setBytes(out.toByteArray());
+ files.add(f);
+ }
+ }
+ catch (Exception ex)
+ {
+ ex.printStackTrace();
+ throw new RuntimeException(ex.getMessage());
+ }
+ }
+ };
+
+ /* Register the listener for all POI files. */
+ r.registerListener(pfl);
/* Read the POI filesystem. */
r.read(new FileInputStream(poiFs));
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
Mailing List: http://jakarta.apache.org/site/mail2.html#poi
The Apache Jakarta POI Project: http://jakarta.apache.org/poi/