- New test case to read all files from the HPSF data directory.
git-svn-id: https://svn.apache.org/repos/asf/jakarta/poi/trunk@353308 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
4e855eadb1
commit
4bb4a4157f
@ -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 junit.framework.TestCase;
|
||||
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;
|
||||
|
||||
|
||||
|
||||
@ -223,8 +232,53 @@ public class TestBasic extends TestCase
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* <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
|
||||
{
|
||||
|
@ -62,6 +62,8 @@ import java.io.FileNotFoundException;
|
||||
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.LinkedList;
|
||||
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 @@ public class Util
|
||||
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());
|
||||
@ -300,4 +299,36 @@ public class Util
|
||||
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();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user