public class TemporaryResources extends Object implements Closeable
Note that this class is not thread-safe.
Constructor and Description |
---|
TemporaryResources() |
Modifier and Type | Method and Description |
---|---|
void |
addResource(Closeable resource)
Adds a new resource to the set of tracked resources that will all be
closed when the
close() method is called. |
void |
close()
Closes all tracked resources.
|
File |
createTemporaryFile()
Creates and returns a temporary file that will automatically be
deleted when the
close() method is called. |
void |
dispose()
Calls the
close() method and wraps the potential
IOException into a TikaException for convenience
when used within Tika. |
<T extends Closeable> |
getResource(Class<T> klass)
Returns the latest of the tracked resources that implements or
extends the given interface or class.
|
void |
setTemporaryFileDirectory(File tmp)
Sets the directory to be used for the temporary files created by
the
createTemporaryFile() method. |
public void setTemporaryFileDirectory(File tmp)
createTemporaryFile()
method.tmp
- temporary file directory,
or null
for the system defaultpublic File createTemporaryFile() throws IOException
close()
method is called.IOException
public void addResource(Closeable resource)
close()
method is called.resource
- resource to be trackedpublic <T extends Closeable> T getResource(Class<T> klass)
klass
- interface or classnull
if not foundpublic void close() throws IOException
Any thrown exceptions from managed resources are collected and then re-thrown only once all the resources have been closed.
close
in interface Closeable
close
in interface AutoCloseable
IOException
- if one or more of the tracked resources
could not be closedpublic void dispose() throws TikaException
close()
method and wraps the potential
IOException
into a TikaException
for convenience
when used within Tika.TikaException
- if one or more of the tracked resources
could not be closedCopyright © 2007-2015 The Apache Software Foundation. All Rights Reserved.