Package com.helger.as2lib.util
Class AS2ResourceHelper
- java.lang.Object
-
- com.helger.as2lib.util.AS2ResourceHelper
-
- All Implemented Interfaces:
Closeable,AutoCloseable
public class AS2ResourceHelper extends Object implements Closeable
A resource manager that keeps track of temporary files and other closables that will be closed when this manager is closed. When callingcreateTempFile()a new filename is created and added to the list. When usingaddCloseable(Closeable)the Closable is added for postponed closing.- Since:
- 4.5.3
- Author:
- Philip Helger
-
-
Constructor Summary
Constructors Constructor Description AS2ResourceHelper()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddCloseable(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.FilecreateTempFile()com.helger.commons.collection.impl.ICommonsList<Closeable>getAllCloseables()com.helger.commons.collection.impl.ICommonsList<File>getAllTempFiles()static FilegetTempDir()static voidsetTempDir(File aTempDir)Set a temporary directory to use.
-
-
-
Method Detail
-
getTempDir
@Nullable public static File getTempDir()
- Returns:
- The temp file directory to use, or
nullfor the system default.
-
setTempDir
public static void setTempDir(@Nullable File aTempDir)
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
@Nonnull public File createTempFile() throws IOException
- 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.
-
addCloseable
public void addCloseable(@Nonnull Closeable aCloseable)
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.
-
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
-
-