Package org.apache.tika.io
Class TemporaryResources
java.lang.Object
org.apache.tika.io.TemporaryResources
- All Implemented Interfaces:
- Closeable,- AutoCloseable
Utility class for tracking and ultimately closing or otherwise disposing
 a collection of temporary resources.
 
Note that this class is not thread-safe.
- Since:
- Apache Tika 0.10
- 
Constructor SummaryConstructors
- 
Method SummaryModifier and TypeMethodDescriptionvoidaddResource(Closeable resource) Adds a new resource to the set of tracked resources that will all be closed when theclose()method is called.voidclose()Closes all tracked resources.createTempFile(String suffix) Creates a temporary file that will automatically be deleted when theclose()method is called, returning its path.createTempFile(Metadata metadata) Creates a temporary file that will automatically be deleted when theclose()method is called, returning its path.Creates and returns a temporary file that will automatically be deleted when theclose()method is called.voiddispose()Calls theclose()method and wraps the potentialIOExceptioninto aTikaExceptionfor convenience when used within Tika.<T extends Closeable>
 TgetResource(Class<T> klass) Returns the latest of the tracked resources that implements or extends the given interface or class.voidsetTemporaryFileDirectory(File tempFileDir) Sets the directory to be used for the temporary files created by thecreateTempFile(String)method.voidsetTemporaryFileDirectory(Path tempFileDir) Sets the directory to be used for the temporary files created by thecreateTempFile(String)method.
- 
Constructor Details- 
TemporaryResourcespublic TemporaryResources()
 
- 
- 
Method Details- 
setTemporaryFileDirectorySets the directory to be used for the temporary files created by thecreateTempFile(String)method.- Parameters:
- tempFileDir- temporary file directory, or- nullfor the system default
 
- 
setTemporaryFileDirectorySets the directory to be used for the temporary files created by thecreateTempFile(String)method.- Parameters:
- tempFileDir- temporary file directory, or- nullfor the system default
- See Also:
 
- 
createTempFileCreates a temporary file that will automatically be deleted when theclose()method is called, returning its path.- Parameters:
- suffix- -- the suffix of the file if known, starting with "." as in ".pdf"
- Returns:
- Path to created temporary file that will be deleted after closing
- Throws:
- IOException
 
- 
createTempFile- Throws:
- IOException
 
- 
createTempFileCreates a temporary file that will automatically be deleted when theclose()method is called, returning its path.- Returns:
- Path to created temporary file that will be deleted after closing
- Throws:
- IOException
 
- 
createTemporaryFileCreates and returns a temporary file that will automatically be deleted when theclose()method is called.- Returns:
- Created temporary file that'll be deleted after closing
- Throws:
- IOException
- See Also:
 
- 
addResourceAdds a new resource to the set of tracked resources that will all be closed when theclose()method is called.- Parameters:
- resource- resource to be tracked
 
- 
getResourceReturns the latest of the tracked resources that implements or extends the given interface or class.- Parameters:
- klass- interface or class
- Returns:
- matching resource, or nullif not found
 
- 
closeCloses all tracked resources. The resources are closed in reverse order from how they were added.Any suppressed exceptions from managed resources are collected and then added to the first thrown exception, which is re-thrown once all the resources have been closed. - Specified by:
- closein interface- AutoCloseable
- Specified by:
- closein interface- Closeable
- Throws:
- IOException- if one or more of the tracked resources could not be closed
 
- 
disposeCalls theclose()method and wraps the potentialIOExceptioninto aTikaExceptionfor convenience when used within Tika.- Throws:
- TikaException- if one or more of the tracked resources could not be closed
 
 
-