public class TemporaryResources
extends java.lang.Object
implements java.io.Closeable
Note that this class is not thread-safe.
Constructor and Description |
---|
TemporaryResources() |
Modifier and Type | Method and Description |
---|---|
void |
addResource(java.io.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.
|
java.nio.file.Path |
createTempFile()
Creates a temporary file that will automatically be deleted when
the
close() method is called, returning its path. |
java.io.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 java.io.Closeable> |
getResource(java.lang.Class<T> klass)
Returns the latest of the tracked resources that implements or
extends the given interface or class.
|
void |
setTemporaryFileDirectory(java.io.File tempFileDir)
Sets the directory to be used for the temporary files created by
the
createTempFile() method. |
void |
setTemporaryFileDirectory(java.nio.file.Path tempFileDir)
Sets the directory to be used for the temporary files created by
the
createTempFile() method. |
public void setTemporaryFileDirectory(java.nio.file.Path tempFileDir)
createTempFile()
method.tempFileDir
- temporary file directory,
or null
for the system defaultpublic void setTemporaryFileDirectory(java.io.File tempFileDir)
createTempFile()
method.tempFileDir
- temporary file directory,
or null
for the system defaultsetTemporaryFileDirectory(Path)
public java.nio.file.Path createTempFile() throws java.io.IOException
close()
method is called, returning its path.java.io.IOException
public java.io.File createTemporaryFile() throws java.io.IOException
close()
method is called.java.io.IOException
createTempFile()
public void addResource(java.io.Closeable resource)
close()
method is called.resource
- resource to be trackedpublic <T extends java.io.Closeable> T getResource(java.lang.Class<T> klass)
klass
- interface or classnull
if not foundpublic void close() throws java.io.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 java.io.Closeable
close
in interface java.lang.AutoCloseable
java.io.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 closed"Copyright © 2010 - 2020 Adobe Systems Incorporated. All Rights Reserved"