2008-02-08 11:55:43 +00:00
|
|
|
/* ====================================================================
|
|
|
|
|
Licensed to the Apache Software Foundation (ASF) under one or more
|
|
|
|
|
contributor license agreements. See the NOTICE file distributed with
|
|
|
|
|
this work for additional information regarding copyright ownership.
|
|
|
|
|
The ASF licenses this file to You under the Apache License, Version 2.0
|
|
|
|
|
(the "License"); you may not use this file except in compliance with
|
|
|
|
|
the License. You may obtain a copy of the License at
|
|
|
|
|
|
|
|
|
|
http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
|
|
|
|
|
|
Unless required by applicable law or agreed to in writing, software
|
|
|
|
|
distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
|
See the License for the specific language governing permissions and
|
|
|
|
|
limitations under the License.
|
|
|
|
|
==================================================================== */
|
|
|
|
|
|
|
|
|
|
package org.apache.poi.hpsf.basic;
|
|
|
|
|
|
|
|
|
|
import java.io.ByteArrayInputStream;
|
|
|
|
|
import java.io.File;
|
|
|
|
|
import java.io.FileFilter;
|
2014-02-16 08:39:47 +00:00
|
|
|
import java.io.IOException;
|
2008-02-08 11:55:43 +00:00
|
|
|
import java.io.InputStream;
|
|
|
|
|
|
|
|
|
|
import junit.framework.TestCase;
|
|
|
|
|
|
2009-08-23 12:34:24 +00:00
|
|
|
import org.apache.poi.POIDataSamples;
|
2014-02-16 08:39:47 +00:00
|
|
|
import org.apache.poi.hpsf.HPSFException;
|
|
|
|
|
import org.apache.poi.hpsf.PropertySetFactory;
|
2008-02-08 11:55:43 +00:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* <p>Tests some HPSF functionality by reading all property sets from all files
|
|
|
|
|
* in the "data" directory. If you want to ensure HPSF can deal with a certain
|
|
|
|
|
* OLE2 file, just add it to the "data" directory and run this test case.</p>
|
|
|
|
|
*
|
|
|
|
|
* @author Rainer Klute (klute@rainer-klute.de)
|
|
|
|
|
*/
|
2009-06-01 21:07:20 +00:00
|
|
|
public class TestReadAllFiles extends TestCase {
|
2014-02-16 08:39:47 +00:00
|
|
|
private static String[] excludes = new String[] {
|
|
|
|
|
"TestZeroLengthCodePage.mpp",
|
|
|
|
|
};
|
2008-02-08 11:55:43 +00:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* <p>This test methods reads all property set streams from all POI
|
|
|
|
|
* filesystems in the "data" directory.</p>
|
2014-02-16 08:39:47 +00:00
|
|
|
*
|
|
|
|
|
* @throws IOException
|
|
|
|
|
* @throws HPSFException
|
2008-02-08 11:55:43 +00:00
|
|
|
*/
|
2014-02-16 08:39:47 +00:00
|
|
|
public void testReadAllFiles() throws IOException, HPSFException
|
2008-02-08 11:55:43 +00:00
|
|
|
{
|
2009-08-23 12:34:24 +00:00
|
|
|
POIDataSamples _samples = POIDataSamples.getHPSFInstance();
|
|
|
|
|
final File dataDir = _samples.getFile("");
|
2008-02-08 11:55:43 +00:00
|
|
|
final File[] fileList = dataDir.listFiles(new FileFilter()
|
|
|
|
|
{
|
2014-02-16 08:39:47 +00:00
|
|
|
@Override
|
2008-02-08 11:55:43 +00:00
|
|
|
public boolean accept(final File f)
|
|
|
|
|
{
|
2014-02-16 08:39:47 +00:00
|
|
|
// exclude files that we know will fail
|
|
|
|
|
for(String exclude : excludes) {
|
|
|
|
|
if(f.getAbsolutePath().endsWith(exclude)) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2008-02-08 11:55:43 +00:00
|
|
|
return f.isFile();
|
|
|
|
|
}
|
|
|
|
|
});
|
2014-02-16 08:39:47 +00:00
|
|
|
|
|
|
|
|
for (int i = 0; i < fileList.length; i++)
|
2008-02-08 11:55:43 +00:00
|
|
|
{
|
2014-02-16 08:39:47 +00:00
|
|
|
final File f = fileList[i];
|
|
|
|
|
/* Read the POI filesystem's property set streams: */
|
|
|
|
|
final POIFile[] psf1 = Util.readPropertySets(f);
|
2008-02-08 11:55:43 +00:00
|
|
|
|
2014-02-16 08:39:47 +00:00
|
|
|
for (int j = 0; j < psf1.length; j++)
|
|
|
|
|
{
|
|
|
|
|
final InputStream in =
|
|
|
|
|
new ByteArrayInputStream(psf1[j].getBytes());
|
|
|
|
|
try {
|
2008-02-08 11:55:43 +00:00
|
|
|
PropertySetFactory.create(in);
|
2014-02-16 08:39:47 +00:00
|
|
|
} catch (Exception e) {
|
|
|
|
|
throw new IOException("While handling file: " + f + " at " + j, e);
|
2008-02-08 11:55:43 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|