Package com.helger.as2lib.util
Class AS2ResourceHelper
java.lang.Object
com.helger.as2lib.util.AS2ResourceHelper
- All Implemented Interfaces:
Closeable
,AutoCloseable
A resource manager that keeps track of temporary files and other closables
that will be closed when this manager is closed. When calling
createTempFile()
a new filename is created and added to the list.
When using addCloseable(Closeable)
the Closable is added for
postponed closing.- Since:
- 4.5.3
- Author:
- Philip Helger
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionvoid
addCloseable
(Closeable aCloseable) Add a new closable for later closing.void
close()
org.apache.hc.core5.http.HttpEntity
createRepeatableHttpEntity
(org.apache.hc.core5.http.HttpEntity aSrcEntity) Ensure the providedHttpEntity
can be read more than once.com.helger.commons.collection.impl.ICommonsList<Closeable>
com.helger.commons.collection.impl.ICommonsList<File>
static File
static void
setTempDir
(File aTempDir) Set a temporary directory to use.
-
Constructor Details
-
AS2ResourceHelper
public AS2ResourceHelper()
-
-
Method Details
-
getTempDir
- Returns:
- The temp file directory to use, or
null
for the system default.
-
setTempDir
Set a temporary directory to use.- Parameters:
aTempDir
- The directory to use. It must be an existing directory. May benull
to use the system default.- Throws:
IllegalArgumentException
- If the directory does not exist
-
createTempFile
- Returns:
- A new temporary
File
that will be deleted whenclose()
is called. - Throws:
IOException
- When temp file creation fails.IllegalStateException
- Ifclose()
was already called before
-
getAllTempFiles
@Nonnull @ReturnsMutableCopy public com.helger.commons.collection.impl.ICommonsList<File> getAllTempFiles()- Returns:
- A list of all known temp files. Never
null
but maybe empty.
-
addCloseable
Add a new closable for later closing.- Parameters:
aCloseable
- The closable to be closed later. May not benull
.- Throws:
IllegalStateException
- Ifclose()
was already called before
-
getAllCloseables
@Nonnull @ReturnsMutableCopy public com.helger.commons.collection.impl.ICommonsList<Closeable> getAllCloseables()- Returns:
- A list of all known closables. Never
null
but maybe empty.
-
close
public void close()- Specified by:
close
in interfaceAutoCloseable
- Specified by:
close
in interfaceCloseable
-
createRepeatableHttpEntity
@Nonnull public org.apache.hc.core5.http.HttpEntity createRepeatableHttpEntity(@Nonnull org.apache.hc.core5.http.HttpEntity aSrcEntity) throws IOException Ensure the providedHttpEntity
can be read more than once. If the provided entity is not repeatable a temporary file is created and a new file-based Http Entity is created.- Parameters:
aSrcEntity
- The source Http entity. May not benull
.- Returns:
- A non-
null
Http entity that can be read more than once. - Throws:
IOException
- on IO error
-