use of org.apache.poi.POIDataSamples in project poi by apache.
the class TestSharedStringsTable method readStrings.
private List<String> readStrings(String filename) throws IOException {
List<String> strs = new ArrayList<String>();
POIDataSamples samples = POIDataSamples.getSpreadSheetInstance();
BufferedReader br = new BufferedReader(new InputStreamReader(samples.openResourceAsStream(filename), "UTF-8"));
String s;
while ((s = br.readLine()) != null) {
if (s.trim().length() > 0) {
strs.add(s.trim());
}
}
br.close();
return strs;
}
use of org.apache.poi.POIDataSamples in project poi by apache.
the class TestUnicode method setUp.
/**
* Read a the test file from the "data" directory.
*
* @exception FileNotFoundException if the file to be read does not exist.
* @exception IOException if any other I/O exception occurs
*/
@Before
public void setUp() {
POIDataSamples samples = POIDataSamples.getHPSFInstance();
data = samples.getFile(POI_FS);
}
use of org.apache.poi.POIDataSamples in project poi by apache.
the class TestWriteWellKnown method testWriteWellKnown.
/**
* <p>This test method test the writing of properties in the well-known
* property set streams "SummaryInformation" and
* "DocumentSummaryInformation" by performing the following steps:</p>
*
* <ol>
*
* <li><p>Read a test document <em>doc1</em> into a POI filesystem.</p></li>
*
* <li><p>Read the summary information stream and the document summary
* information stream from the POI filesystem.</p></li>
*
* <li><p>Write all properties supported by HPSF to the summary
* information (e.g. author, edit date, application name) and to the
* document summary information (e.g. company, manager).</p></li>
*
* <li><p>Write the summary information stream and the document summary
* information stream to the POI filesystem.</p></li>
*
* <li><p>Write the POI filesystem to a (temporary) file <em>doc2</em>
* and close the latter.</p></li>
*
* <li><p>Open <em>doc2</em> for reading and check summary information
* and document summary information. All properties written before must be
* found in the property streams of <em>doc2</em> and have the correct
* values.</p></li>
*
* <li><p>Remove all properties supported by HPSF from the summary
* information (e.g. author, edit date, application name) and from the
* document summary information (e.g. company, manager).</p></li>
*
* <li><p>Write the summary information stream and the document summary
* information stream to the POI filesystem.</p></li>
*
* <li><p>Write the POI filesystem to a (temporary) file <em>doc3</em>
* and close the latter.</p></li>
*
* <li><p>Open <em>doc3</em> for reading and check summary information
* and document summary information. All properties removed before must not
* be found in the property streams of <em>doc3</em>.</p></li> </ol>
*
* @throws IOException if some I/O error occurred.
* @throws MarkUnsupportedException
* @throws NoPropertySetStreamException
* @throws UnexpectedPropertySetTypeException
* @throws WritingNotSupportedException
*/
@Test
public void testWriteWellKnown() throws Exception {
POIDataSamples _samples = POIDataSamples.getHPSFInstance();
final File doc1 = TempFile.createTempFile("POI_HPSF_Test1.", ".tmp");
final File doc2 = TempFile.createTempFile("POI_HPSF_Test2.", ".tmp");
final File doc3 = TempFile.createTempFile("POI_HPSF_Test3.", ".tmp");
FileInputStream fis = new FileInputStream(_samples.getFile(POI_FS));
FileOutputStream fos = new FileOutputStream(doc1);
IOUtils.copy(fis, fos);
fos.close();
fis.close();
CustomProperties cps1 = write1stFile(doc1, doc2);
CustomProperties cps2 = write2ndFile(doc2, doc3);
write3rdFile(doc3, null);
assertEquals(cps1, cps2);
}
use of org.apache.poi.POIDataSamples in project poi by apache.
the class AllDataFilesTester method runTests.
/**
* <p>Tests the simplified custom properties.</p>
*
* @param task the task to execute
* @throws Throwable
*/
public void runTests(final TestTask task) throws Throwable {
POIDataSamples _samples = POIDataSamples.getHPSFInstance();
final File dataDir = _samples.getFile("");
final File[] docs = dataDir.listFiles(new FileFilter() {
@Override
public boolean accept(final File file) {
return file.isFile() && file.getName().startsWith("Test");
}
});
for (final File doc : docs) {
final Logger logger = Logger.getLogger(getClass().getName());
logger.info("Processing file \" " + doc + "\".");
/* Execute the test task. */
task.runTest(doc);
}
}
use of org.apache.poi.POIDataSamples in project poi by apache.
the class TestDocumentInputStream method testReadMultipleTreeLevels.
/**
* Test that we can read files at multiple levels down the tree
*/
public void testReadMultipleTreeLevels() throws Exception {
final POIDataSamples _samples = POIDataSamples.getPublisherInstance();
File sample = _samples.getFile("Sample.pub");
DocumentInputStream stream;
NPOIFSFileSystem npoifs = new NPOIFSFileSystem(sample);
try {
OPOIFSFileSystem opoifs = new OPOIFSFileSystem(new FileInputStream(sample));
// Ensure we have what we expect on the root
assertEquals(npoifs, npoifs.getRoot().getNFileSystem());
assertEquals(npoifs, npoifs.getRoot().getFileSystem());
assertEquals(null, npoifs.getRoot().getOFileSystem());
assertEquals(null, opoifs.getRoot().getFileSystem());
assertEquals(opoifs, opoifs.getRoot().getOFileSystem());
assertEquals(null, opoifs.getRoot().getNFileSystem());
// Check inside
for (DirectoryNode root : new DirectoryNode[] { opoifs.getRoot(), npoifs.getRoot() }) {
// Top Level
Entry top = root.getEntry("Contents");
assertEquals(true, top.isDocumentEntry());
stream = root.createDocumentInputStream(top);
stream.read();
// One Level Down
DirectoryNode escher = (DirectoryNode) root.getEntry("Escher");
Entry one = escher.getEntry("EscherStm");
assertEquals(true, one.isDocumentEntry());
stream = escher.createDocumentInputStream(one);
stream.read();
// Two Levels Down
DirectoryNode quill = (DirectoryNode) root.getEntry("Quill");
DirectoryNode quillSub = (DirectoryNode) quill.getEntry("QuillSub");
Entry two = quillSub.getEntry("CONTENTS");
assertEquals(true, two.isDocumentEntry());
stream = quillSub.createDocumentInputStream(two);
stream.read();
}
} finally {
npoifs.close();
}
}
Aggregations