Search in sources :

Example 1 with MarkUnsupportedException

use of org.apache.poi.hpsf.MarkUnsupportedException in project poi by apache.

the class TestEmptyProperties method testCreatePropertySets.

/**
     * <p>Tests whether property sets can be created from the POI
     * files in the POI file system. This test case expects the first
     * file to be a {@link SummaryInformation}, the second file to be
     * a {@link DocumentSummaryInformation} and the rest to be no
     * property sets. In the latter cases a {@link
     * NoPropertySetStreamException} will be thrown when trying to
     * create a {@link PropertySet}.</p>
     *
     * @exception IOException if an I/O exception occurs.
     *
     * @exception UnsupportedEncodingException if a character encoding is not
     * supported.
     */
@Test
public void testCreatePropertySets() throws UnsupportedEncodingException, IOException {
    Class<?>[] expected = { NoPropertySetStreamException.class, SummaryInformation.class, NoPropertySetStreamException.class };
    for (int i = 0; i < expected.length; i++) {
        InputStream in = new ByteArrayInputStream(poiFiles.get(i).getBytes());
        Object o;
        try {
            o = PropertySetFactory.create(in);
        } catch (NoPropertySetStreamException ex) {
            o = ex;
        } catch (MarkUnsupportedException ex) {
            o = ex;
        }
        in.close();
        assertEquals(o.getClass(), expected[i]);
    }
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) NoPropertySetStreamException(org.apache.poi.hpsf.NoPropertySetStreamException) MarkUnsupportedException(org.apache.poi.hpsf.MarkUnsupportedException) Test(org.junit.Test)

Example 2 with MarkUnsupportedException

use of org.apache.poi.hpsf.MarkUnsupportedException in project poi by apache.

the class TestBasic method testCreatePropertySets.

/**
     * <p>Tests whether property sets can be created from the POI
     * files in the POI file system. This test case expects the first
     * file to be a {@link SummaryInformation}, the second file to be
     * a {@link DocumentSummaryInformation} and the rest to be no
     * property sets. In the latter cases a {@link
     * NoPropertySetStreamException} will be thrown when trying to
     * create a {@link PropertySet}.</p>
     *
     * @exception IOException if an I/O exception occurs.
     *
     * @exception UnsupportedEncodingException if a character encoding is not
     * supported.
     */
@Test
public void testCreatePropertySets() throws UnsupportedEncodingException, IOException {
    Class<?>[] expected = { SummaryInformation.class, DocumentSummaryInformation.class, NoPropertySetStreamException.class, NoPropertySetStreamException.class, NoPropertySetStreamException.class };
    for (int i = 0; i < expected.length; i++) {
        InputStream in = new ByteArrayInputStream(poiFiles.get(i).getBytes());
        Object o;
        try {
            o = PropertySetFactory.create(in);
        } catch (NoPropertySetStreamException ex) {
            o = ex;
        } catch (MarkUnsupportedException ex) {
            o = ex;
        }
        in.close();
        assertEquals(expected[i], o.getClass());
    }
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) NoPropertySetStreamException(org.apache.poi.hpsf.NoPropertySetStreamException) MarkUnsupportedException(org.apache.poi.hpsf.MarkUnsupportedException) Test(org.junit.Test)

Example 3 with MarkUnsupportedException

use of org.apache.poi.hpsf.MarkUnsupportedException in project tika by apache.

the class SummaryExtractor method parseSummaryEntryIfExists.

private void parseSummaryEntryIfExists(DirectoryNode root, String entryName) throws IOException, TikaException {
    try {
        DocumentEntry entry = (DocumentEntry) root.getEntry(entryName);
        PropertySet properties = new PropertySet(new DocumentInputStream(entry));
        if (properties.isSummaryInformation()) {
            parse(new SummaryInformation(properties));
        }
        if (properties.isDocumentSummaryInformation()) {
            parse(new DocumentSummaryInformation(properties));
        }
    } catch (FileNotFoundException e) {
    // entry does not exist, just skip it
    } catch (NoPropertySetStreamException e) {
    // no property stream, just skip it
    } catch (UnexpectedPropertySetTypeException e) {
        throw new TikaException("Unexpected HPSF document", e);
    } catch (MarkUnsupportedException e) {
        throw new TikaException("Invalid DocumentInputStream", e);
    } catch (Exception e) {
        LOG.warn("Ignoring unexpected exception while parsing summary entry {}", entryName, e);
    }
}
Also used : TikaException(org.apache.tika.exception.TikaException) SummaryInformation(org.apache.poi.hpsf.SummaryInformation) DocumentSummaryInformation(org.apache.poi.hpsf.DocumentSummaryInformation) DocumentEntry(org.apache.poi.poifs.filesystem.DocumentEntry) FileNotFoundException(java.io.FileNotFoundException) PropertySet(org.apache.poi.hpsf.PropertySet) DocumentSummaryInformation(org.apache.poi.hpsf.DocumentSummaryInformation) NoPropertySetStreamException(org.apache.poi.hpsf.NoPropertySetStreamException) DocumentInputStream(org.apache.poi.poifs.filesystem.DocumentInputStream) UnexpectedPropertySetTypeException(org.apache.poi.hpsf.UnexpectedPropertySetTypeException) MarkUnsupportedException(org.apache.poi.hpsf.MarkUnsupportedException) NoPropertySetStreamException(org.apache.poi.hpsf.NoPropertySetStreamException) UnexpectedPropertySetTypeException(org.apache.poi.hpsf.UnexpectedPropertySetTypeException) TikaException(org.apache.tika.exception.TikaException) MarkUnsupportedException(org.apache.poi.hpsf.MarkUnsupportedException) IOException(java.io.IOException) FileNotFoundException(java.io.FileNotFoundException)

Aggregations

MarkUnsupportedException (org.apache.poi.hpsf.MarkUnsupportedException)3 NoPropertySetStreamException (org.apache.poi.hpsf.NoPropertySetStreamException)3 ByteArrayInputStream (java.io.ByteArrayInputStream)2 InputStream (java.io.InputStream)2 Test (org.junit.Test)2 FileNotFoundException (java.io.FileNotFoundException)1 IOException (java.io.IOException)1 DocumentSummaryInformation (org.apache.poi.hpsf.DocumentSummaryInformation)1 PropertySet (org.apache.poi.hpsf.PropertySet)1 SummaryInformation (org.apache.poi.hpsf.SummaryInformation)1 UnexpectedPropertySetTypeException (org.apache.poi.hpsf.UnexpectedPropertySetTypeException)1 DocumentEntry (org.apache.poi.poifs.filesystem.DocumentEntry)1 DocumentInputStream (org.apache.poi.poifs.filesystem.DocumentInputStream)1 TikaException (org.apache.tika.exception.TikaException)1