You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@poi.apache.org by kl...@apache.org on 2003/08/23 17:14:39 UTC
cvs commit: jakarta-poi/src/testcases/org/apache/poi/hpsf/basic TestBasic.java Util.java
klute 2003/08/23 08:14:39
Modified: src/testcases/org/apache/poi/hpsf/basic TestBasic.java
Util.java
Log:
- New test case to read all files from the HPSF data directory.
Revision Changes Path
1.5 +55 -1 jakarta-poi/src/testcases/org/apache/poi/hpsf/basic/TestBasic.java
Index: TestBasic.java
===================================================================
RCS file: /home/cvs/jakarta-poi/src/testcases/org/apache/poi/hpsf/basic/TestBasic.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- TestBasic.java 26 Jul 2003 06:57:33 -0000 1.4
+++ TestBasic.java 23 Aug 2003 15:14:39 -0000 1.5
@@ -55,10 +55,16 @@
package org.apache.poi.hpsf.basic;
import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
import java.io.File;
+import java.io.FileFilter;
import java.io.FileNotFoundException;
+import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
+import java.io.OutputStream;
+import java.io.PrintWriter;
+import java.io.StringWriter;
import junit.framework.Assert;
import junit.framework.TestCase;
@@ -66,11 +72,14 @@
import org.apache.poi.hpsf.DocumentSummaryInformation;
import org.apache.poi.hpsf.HPSFException;
import org.apache.poi.hpsf.MarkUnsupportedException;
+import org.apache.poi.hpsf.MutablePropertySet;
import org.apache.poi.hpsf.NoPropertySetStreamException;
import org.apache.poi.hpsf.PropertySet;
import org.apache.poi.hpsf.PropertySetFactory;
import org.apache.poi.hpsf.SummaryInformation;
import org.apache.poi.hpsf.UnexpectedPropertySetTypeException;
+import org.apache.poi.poifs.filesystem.DocumentEntry;
+import org.apache.poi.poifs.filesystem.POIFSFileSystem;
@@ -224,7 +233,52 @@
/**
+ * <p>This test methods reads all property set streams from all POI
+ * filesystems in the "data" directory.</p>
+ */
+ public void testReadAllFiles()
+ {
+ final File dataDir =
+ new File(System.getProperty("HPSF.testdata.path"));
+ final File[] fileList = dataDir.listFiles(new FileFilter()
+ {
+ public boolean accept(final File f)
+ {
+ return f.isFile();
+ }
+ });
+ try
+ {
+ for (int i = 0; i < fileList.length; i++)
+ {
+ File f = fileList[i];
+ System.out.println("Reading file " + f);
+ /* Read the POI filesystem's property set streams: */
+ final POIFile[] psf1 = Util.readPropertySets(f);
+
+ for (int j = 0; j < psf1.length; j++)
+ {
+ final InputStream in =
+ new ByteArrayInputStream(psf1[j].getBytes());
+ final PropertySet psIn = PropertySetFactory.create(in);
+ }
+ }
+ }
+ catch (Throwable t)
+ {
+ final String s = Util.toString(t);
+ System.err.println(s);
+ }
+ }
+
+
+
+ /**
* <p>Runs the test cases stand-alone.</p>
+ *
+ * @param args Command-line arguments (ignored)
+ *
+ * @exception Throwable if any sort of exception or error occurs
*/
public static void main(final String[] args) throws Throwable
{
1.7 +37 -6 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.6
retrieving revision 1.7
diff -u -r1.6 -r1.7
--- Util.java 5 Aug 2003 20:52:25 -0000 1.6
+++ Util.java 23 Aug 2003 15:14:39 -0000 1.7
@@ -62,6 +62,8 @@
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
+import java.io.PrintWriter;
+import java.io.StringWriter;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Iterator;
@@ -69,11 +71,7 @@
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;
@@ -186,7 +184,8 @@
f.setName(event.getName());
f.setPath(event.getPath());
final InputStream in = event.getStream();
- final ByteArrayOutputStream out = new ByteArrayOutputStream();
+ final ByteArrayOutputStream out =
+ new ByteArrayOutputStream();
Util.copy(in, out);
out.close();
f.setBytes(out.toByteArray());
@@ -298,6 +297,38 @@
}
System.out.println("Current directory: " +
System.getProperty("user.dir"));
+ }
+
+
+
+ /**
+ * <p>Returns a textual representation of a {@link Throwable}, including a
+ * stacktrace.</p>
+ *
+ * @param t The {@link Throwable}
+ *
+ * @return a string containing the output of a call to
+ * <code>t.printStacktrace()</code>.
+ */
+ public static String toString(final Throwable t)
+ {
+ final StringWriter sw = new StringWriter();
+ final PrintWriter pw = new PrintWriter(sw);
+ t.printStackTrace(pw);
+ pw.close();
+ try
+ {
+ sw.close();
+ return sw.toString();
+ }
+ catch (IOException e)
+ {
+ final StringBuffer b = new StringBuffer(t.getMessage());
+ b.append("\n");
+ b.append("Could not create a stacktrace. Reason: ");
+ b.append(e.getMessage());
+ return b.toString();
+ }
}
}
---------------------------------------------------------------------
To unsubscribe, e-mail: poi-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: poi-dev-help@jakarta.apache.org