Search in sources :

Example 16 with POIDataSamples

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;
}
Also used : InputStreamReader(java.io.InputStreamReader) ArrayList(java.util.ArrayList) POIDataSamples(org.apache.poi.POIDataSamples) BufferedReader(java.io.BufferedReader) XSSFRichTextString(org.apache.poi.xssf.usermodel.XSSFRichTextString)

Example 17 with POIDataSamples

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);
}
Also used : POIDataSamples(org.apache.poi.POIDataSamples) Before(org.junit.Before)

Example 18 with POIDataSamples

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);
}
Also used : FileOutputStream(java.io.FileOutputStream) POIDataSamples(org.apache.poi.POIDataSamples) TempFile(org.apache.poi.util.TempFile) File(java.io.File) FileInputStream(java.io.FileInputStream) CustomProperties(org.apache.poi.hpsf.CustomProperties) Test(org.junit.Test)

Example 19 with POIDataSamples

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);
    }
}
Also used : POIDataSamples(org.apache.poi.POIDataSamples) FileFilter(java.io.FileFilter) Logger(java.util.logging.Logger) File(java.io.File)

Example 20 with POIDataSamples

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();
    }
}
Also used : POIDataSamples(org.apache.poi.POIDataSamples) File(java.io.File) FileInputStream(java.io.FileInputStream)

Aggregations

POIDataSamples (org.apache.poi.POIDataSamples)27 Test (org.junit.Test)13 File (java.io.File)7 Before (org.junit.Before)7 HSLFSlideShow (org.apache.poi.hslf.usermodel.HSLFSlideShow)4 TempFile (org.apache.poi.util.TempFile)4 HSLFSlideShowImpl (org.apache.poi.hslf.usermodel.HSLFSlideShowImpl)3 POIFSFileSystem (org.apache.poi.poifs.filesystem.POIFSFileSystem)3 BeforeClass (org.junit.BeforeClass)3 ByteArrayInputStream (java.io.ByteArrayInputStream)2 ByteArrayOutputStream (java.io.ByteArrayOutputStream)2 FileInputStream (java.io.FileInputStream)2 InputStream (java.io.InputStream)2 ArrayList (java.util.ArrayList)2 MAPIAttribute (org.apache.poi.hmef.attribute.MAPIAttribute)2 BufferedReader (java.io.BufferedReader)1 FileFilter (java.io.FileFilter)1 FileOutputStream (java.io.FileOutputStream)1 InputStreamReader (java.io.InputStreamReader)1 SimpleDateFormat (java.text.SimpleDateFormat)1