Package com.helger.phase4.util
Class AS4ResourceHelper
java.lang.Object
com.helger.phase4.util.AS4ResourceHelper
- 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.- Author:
- Philip Helger
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidaddCloseable(Closeable aCloseable) Add a new closable for later closing.voidclose()org.apache.hc.core5.http.HttpEntitycreateRepeatableHttpEntity(org.apache.hc.core5.http.HttpEntity aSrcEntity) Ensure the providedHttpEntitycan be read more than once.com.helger.commons.collection.impl.ICommonsList<Closeable>com.helger.commons.collection.impl.ICommonsList<File>static Filestatic voidsetTempDir(File aTempDir) Set a temporary directory to use.
-
Constructor Details
-
AS4ResourceHelper
public AS4ResourceHelper()
-
-
Method Details
-
getTempDir
- Returns:
- The temp file directory to use, or
nullfor the system default.
-
setTempDir
Set a temporary directory to use.- Parameters:
aTempDir- The directory to use. It must be an existing directory. May benullto use the system default.- Throws:
IllegalArgumentException- If the directory does not exist
-
createTempFile
- Returns:
- A new temporary
Filethat 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
nullbut maybe empty. - Since:
- 0.8.3
-
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
nullbut maybe empty. - Since:
- 0.8.3
-
close
public void close()- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable
-
createRepeatableHttpEntity
@Nonnull public org.apache.hc.core5.http.HttpEntity createRepeatableHttpEntity(@Nonnull org.apache.hc.core5.http.HttpEntity aSrcEntity) throws IOException Ensure the providedHttpEntitycan 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-
nullHttp entity that can be read more than once. - Throws:
IOException- on IO error- Since:
- v0.9.9
-