Top Description Inners Fields Constructors Methods
org.apache.poi.extractor

public final Class ExtractorFactory

extends Object
Class Inheritance
Annotations
@SuppressWarnings:WeakerAccess, JavadocReference
Static Imports
org.apache.poi.hssf.record.crypto.Biff8EncryptionKey.getCurrentUserPassword, org.apache.poi.poifs.crypt.Decryptor.DEFAULT_POIFS_ENTRY

Figures out the correct POIOLE2TextExtractor for your supplied document, and returns it.

Note 1 - will fail for many file formats if the POI Scratchpad jar is not present on the runtime classpath

Note 2 - for text extractor creation across all formats, use org.apache.poi.ooxml.extractor.POIXMLExtractorFactory contained within the OOXML jar.

Note 3 - rather than using this, for most cases you would be better off switching to Apache Tika instead!

Nested and Inner Type Summary

Modifier and TypeClass and Description
private static interface
private static class

Field Summary

Modifier and TypeField and Description
private static Boolean
allPreferEventExtractors

Should all threads prefer event based over usermodel based extractors?

private static final Logger
public static final String
OOXML_PACKAGE

Some OPCPackages are packed in side an OLE2 container.

private final List<ExtractorProvider>
private static final ThreadLocal<Boolean>
threadPreferEventExtractors

Should this thread prefer event based over usermodel based extractors?

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
public static void
public static POITextExtractor

Returns:

A POITextExtractor that can be used to fetch text-content of the file.
createExtractor
(POIFSFileSystem
The file-system which wraps the data of the file.
fs
)

Create an extractor that can be used to read text from the given file.

public static POITextExtractor

Returns:

A POITextExtractor that can be used to fetch text-content of the file.
createExtractor
(POIFSFileSystem
The file-system which wraps the data of the file.
fs
,
String
The password that is necessary to open the file
password
)

Create an extractor that can be used to read text from the given file.

public static POITextExtractor

Returns:

A POITextExtractor that can be used to fetch text-content of the file.
createExtractor
(InputStream
A stream which wraps the data of the file.
input
)

Create an extractor that can be used to read text from the given file.

public static POITextExtractor

Returns:

A POITextExtractor that can be used to fetch text-content of the file.
createExtractor
(InputStream
A stream which wraps the data of the file.
input
,
String
The password that is necessary to open the file
password
)

Create an extractor that can be used to read text from the given file.

public static POITextExtractor

Returns:

A POITextExtractor that can be used to fetch text-content of the file.
createExtractor
(File
The file to read
file
)

Create an extractor that can be used to read text from the given file.

public static POITextExtractor

Returns:

A POITextExtractor that can be used to fetch text-content of the file.
createExtractor
(File
The file to read
file
,
String
The password that is necessary to open the file
password
)

Create an extractor that can be used to read text from the given file.

public static POITextExtractor

Returns:

The resulting POITextExtractor, an exception is thrown if no TextExtractor can be created for some reason.
createExtractor
(DirectoryNode
The DirectoryNode pointing to a document.
root
)

Create the Extractor, if possible.

public static POITextExtractor

Returns:

The resulting POITextExtractor, an exception is thrown if no TextExtractor can be created for some reason.
createExtractor
(final DirectoryNode
The DirectoryNode pointing to a document.
root
,
String
The password that is necessary to open the file
password
)

Create the Extractor, if possible.

public static Boolean

Returns:

true if event extractors should be preferred in all threads, false otherwise.
getAllThreadsPreferEventExtractors
()

Should all threads prefer event based over usermodel based extractors?

public static POITextExtractor[]

Returns:

An array of resulting extractors. Empty if no embedded documents are found.
getEmbeddedDocsTextExtractors
(POIOLE2TextExtractor
The extractor to look at for embedded documents
ext
)

Returns an array of text extractors, one for each of the embedded documents in the file (if there are any).

public static boolean

Returns:

If the current thread should use event based extractors.
getPreferEventExtractor
()

Should this thread use event based extractors is available?

public static boolean

Returns:

true if event extractors should be preferred in the current thread, false otherwise.
getThreadPrefersEventExtractors
()

Should this thread prefer event based over usermodel based extractors?

public static void
removeProvider(Class<? extends ExtractorProvider> provider)

public static void
public static void
setAllThreadsPreferEventExtractors(Boolean
If all threads should prefer event based extractors.
preferEventExtractors
)

Should all threads prefer event based over usermodel based extractors?

public static void
setThreadPrefersEventExtractors(boolean
If this threads should prefer event based extractors.
preferEventExtractors
)

Should this thread prefer event based over usermodel based extractors?

private static POITextExtractor
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

allPreferEventExtractorsback to summary
private static Boolean allPreferEventExtractors

Should all threads prefer event based over usermodel based extractors?

LOGGERback to summary
private static final Logger LOGGER
OOXML_PACKAGEback to summary
public static final String OOXML_PACKAGE

Some OPCPackages are packed in side an OLE2 container. If encrypted, the DirectoryNode is called "EncryptedPackage", otherwise the node is called "Package"

providerback to summary
private final List<ExtractorProvider> provider
threadPreferEventExtractorsback to summary
private static final ThreadLocal<Boolean> threadPreferEventExtractors

Should this thread prefer event based over usermodel based extractors?

Constructor Detail

ExtractorFactoryback to summary
private ExtractorFactory()

Method Detail

addProviderback to summary
public static void addProvider(ExtractorProvider provider)
createExtractorback to summary
public static POITextExtractor createExtractor(POIFSFileSystem fs) throws IOException

Create an extractor that can be used to read text from the given file.

Parameters
fs:POIFSFileSystem

The file-system which wraps the data of the file.

Returns:POITextExtractor

A POITextExtractor that can be used to fetch text-content of the file.

Exceptions
IOException:
If reading the file-data fails
createExtractorback to summary
public static POITextExtractor createExtractor(POIFSFileSystem fs, String password) throws IOException

Create an extractor that can be used to read text from the given file.

Parameters
fs:POIFSFileSystem

The file-system which wraps the data of the file.

password:String

The password that is necessary to open the file

Returns:POITextExtractor

A POITextExtractor that can be used to fetch text-content of the file.

Exceptions
IOException:
If reading the file-data fails
createExtractorback to summary
public static POITextExtractor createExtractor(InputStream input) throws IOException

Create an extractor that can be used to read text from the given file.

Parameters
input:InputStream

A stream which wraps the data of the file.

Returns:POITextExtractor

A POITextExtractor that can be used to fetch text-content of the file.

Exceptions
IOException:
If reading the file-data fails
EmptyFileException:
If the given file is empty
createExtractorback to summary
public static POITextExtractor createExtractor(InputStream input, String password) throws IOException

Create an extractor that can be used to read text from the given file.

Parameters
input:InputStream

A stream which wraps the data of the file.

password:String

The password that is necessary to open the file

Returns:POITextExtractor

A POITextExtractor that can be used to fetch text-content of the file.

Exceptions
IOException:
If reading the file-data fails
EmptyFileException:
If the given file is empty
createExtractorback to summary
public static POITextExtractor createExtractor(File file) throws IOException

Create an extractor that can be used to read text from the given file.

Parameters
file:File

The file to read

Returns:POITextExtractor

A POITextExtractor that can be used to fetch text-content of the file.

Exceptions
IOException:
If reading the file-data fails
EmptyFileException:
If the given file is empty
createExtractorback to summary
public static POITextExtractor createExtractor(File file, String password) throws IOException

Create an extractor that can be used to read text from the given file.

Parameters
file:File

The file to read

password:String

The password that is necessary to open the file

Returns:POITextExtractor

A POITextExtractor that can be used to fetch text-content of the file.

Annotations
@SuppressWarnings:java:S2095
Exceptions
IOException:
If reading the file-data fails
EmptyFileException:
If the given file is empty
createExtractorback to summary
public static POITextExtractor createExtractor(DirectoryNode root) throws IOException

Create the Extractor, if possible. Generally needs the Scratchpad jar. Note that this won't check for embedded OOXML resources either, use org.apache.poi.ooxml.extractor.POIXMLExtractorFactory for that.

Parameters
root:DirectoryNode

The DirectoryNode pointing to a document.

Returns:POITextExtractor

The resulting POITextExtractor, an exception is thrown if no TextExtractor can be created for some reason.

Exceptions
IOException:
If converting the DirectoryNode into a HSSFWorkbook fails
OldFileFormatException:
If the DirectoryNode points to a format of an unsupported version of Excel.
IllegalArgumentException:
If creating the Extractor fails
createExtractorback to summary
public static POITextExtractor createExtractor(final DirectoryNode root, String password) throws IOException

Create the Extractor, if possible. Generally needs the Scratchpad jar. Note that this won't check for embedded OOXML resources either, use org.apache.poi.ooxml.extractor.POIXMLExtractorFactory for that.

Parameters
root:DirectoryNode

The DirectoryNode pointing to a document.

password:String

The password that is necessary to open the file

Returns:POITextExtractor

The resulting POITextExtractor, an exception is thrown if no TextExtractor can be created for some reason.

Exceptions
IOException:
If converting the DirectoryNode into a HSSFWorkbook fails
OldFileFormatException:
If the DirectoryNode points to a format of an unsupported version of Excel.
IllegalArgumentException:
If creating the Extractor fails
getAllThreadsPreferEventExtractorsback to summary
public static Boolean getAllThreadsPreferEventExtractors()

Should all threads prefer event based over usermodel based extractors? (usermodel extractors tend to be more accurate, but use more memory) Default is to use the thread level setting, which defaults to false.

Returns:Boolean

true if event extractors should be preferred in all threads, false otherwise.

getEmbeddedDocsTextExtractorsback to summary
public static POITextExtractor[] getEmbeddedDocsTextExtractors(POIOLE2TextExtractor ext) throws IOException

Returns an array of text extractors, one for each of the embedded documents in the file (if there are any). If there are no embedded documents, you'll get back an empty array. Otherwise, you'll get one open POITextExtractor for each embedded file.

Parameters
ext:POIOLE2TextExtractor

The extractor to look at for embedded documents

Returns:POITextExtractor[]

An array of resulting extractors. Empty if no embedded documents are found.

Exceptions
IOException:
If converting the DirectoryNode into a HSSFWorkbook fails
OldFileFormatException:
If the DirectoryNode points to a format of an unsupported version of Excel.
IllegalArgumentException:
If creating the Extractor fails
getPreferEventExtractorback to summary
public static boolean getPreferEventExtractor()

Should this thread use event based extractors is available? Checks the all-threads one first, then thread specific.

Returns:boolean

If the current thread should use event based extractors.

getThreadPrefersEventExtractorsback to summary
public static boolean getThreadPrefersEventExtractors()

Should this thread prefer event based over usermodel based extractors? (usermodel extractors tend to be more accurate, but use more memory) Default is false.

Returns:boolean

true if event extractors should be preferred in the current thread, false otherwise.

removeProviderback to summary
public static void removeProvider(Class<? extends ExtractorProvider> provider)
removeThreadPrefersEventExtractorsSettingback to summary
public static void removeThreadPrefersEventExtractorsSetting()

Clears the setting for this thread made by setThreadPrefersEventExtractors(boolean)

Since
POI 5.2.4
See Also
setThreadPrefersEventExtractors(boolean)
setAllThreadsPreferEventExtractorsback to summary
public static void setAllThreadsPreferEventExtractors(Boolean preferEventExtractors)

Should all threads prefer event based over usermodel based extractors? If set, will take preference over the Thread level setting.

Parameters
preferEventExtractors:Boolean

If all threads should prefer event based extractors.

setThreadPrefersEventExtractorsback to summary
public static void setThreadPrefersEventExtractors(boolean preferEventExtractors)

Should this thread prefer event based over usermodel based extractors? Will only be used if the All Threads setting is null.

This uses ThreadLocals and these can leak resources when you have a lot of threads.

You should always try to call removeThreadPrefersEventExtractorsSetting().
Parameters
preferEventExtractors:boolean

If this threads should prefer event based extractors.

wpback to summary
private static POITextExtractor wp(FileMagic fm, ExtractorFactory.ProviderMethod fun) throws IOException
org.apache.poi.extractor back to summary

private Interface ExtractorFactory.ProviderMethod


Method Summary

Modifier and TypeMethod and Description
public POITextExtractor

Method Detail

createback to summary
public POITextExtractor create(ExtractorProvider prov) throws IOException
org.apache.poi.extractor back to summary

private Class ExtractorFactory.Singleton

extends Object
Class Inheritance

Field Summary

Modifier and TypeField and Description
private static final ExtractorFactory

Constructor Summary

AccessConstructor and Description
private

Method Summary

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

INSTANCEback to summary
private static final ExtractorFactory INSTANCE

Constructor Detail

Singletonback to summary
private Singleton()