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.
|
Path |
createTempFile() |
Path |
createTempFile(Metadata metadata)
Creates a temporary file that will automatically be deleted when
the
close() method is called, returning its path. |
Path |
createTempFile(String suffix)
Creates a temporary file that will automatically be deleted when
the
close() method is called, returning its path. |
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 tempFileDir)
Sets the directory to be used for the temporary files created by
the
createTempFile(String) method. |
void |
setTemporaryFileDirectory(Path tempFileDir)
Sets the directory to be used for the temporary files created by
the
createTempFile(String) method. |
public void setTemporaryFileDirectory(Path tempFileDir)
createTempFile(String)
method.tempFileDir
- temporary file directory,
or null
for the system defaultpublic void setTemporaryFileDirectory(File tempFileDir)
createTempFile(String)
method.tempFileDir
- temporary file directory,
or null
for the system defaultsetTemporaryFileDirectory(Path)
public Path createTempFile(String suffix) throws IOException
close()
method is called, returning its path.suffix
- -- the suffix of the file if known, starting with "." as in ".pdf"IOException
public Path createTempFile() throws IOException
IOException
public Path createTempFile(Metadata metadata) throws IOException
close()
method is called, returning its path.IOException
public File createTemporaryFile() throws IOException
close()
method is called.IOException
createTempFile(String)
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 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.
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–2023 The Apache Software Foundation. All rights reserved.