Package net.morimekta.util
Class TemporaryAssetFolder
- java.lang.Object
-
- net.morimekta.util.TemporaryAssetFolder
-
- All Implemented Interfaces:
java.io.Closeable
,java.lang.AutoCloseable
public class TemporaryAssetFolder extends java.lang.Object implements java.io.Closeable
A temporary asset folder where an arbitrary number of files can be added to and should guarantee complete cleanup on close. Example usage:
This will create a temp folder into the base directory for each run, where any number of files or sub-folders can be added. All of it will be removed immediately on close.try (TemporaryAssetFolder tmp = new TemporaryAssetFolder(base)) { // do stuff } // is all deleted.
-
-
Constructor Summary
Constructors Constructor Description TemporaryAssetFolder(java.io.File baseTempDirectory)
TemporaryAssetFolder(java.nio.file.Path baseTempDirectory)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
close()
Binary
getBinary(java.lang.String name)
byte[]
getBytes(java.lang.String name)
java.io.File
getFile()
java.io.InputStream
getInputStream(java.lang.String name)
java.io.OutputStream
getOutputStream(java.lang.String name)
java.io.OutputStream
getOutputStream(java.lang.String name, boolean append)
java.nio.file.Path
getPath()
java.io.Reader
getReader(java.lang.String name)
java.lang.String
getString(java.lang.String name)
java.io.Writer
getWriter(java.lang.String name)
java.io.Writer
getWriter(java.lang.String name, boolean append)
java.util.Collection<java.nio.file.Path>
list()
java.util.Collection<java.nio.file.Path>
list(boolean recursive)
java.nio.file.Path
put(java.lang.String name, byte[] content)
java.nio.file.Path
put(java.lang.String name, java.lang.CharSequence content)
java.nio.file.Path
put(java.lang.String name, Binary content)
java.io.File
resolveFile(java.lang.String name)
java.nio.file.Path
resolvePath(java.lang.String name)
java.nio.file.Path
write(java.lang.String name, java.io.InputStream contentStream)
java.nio.file.Path
write(java.lang.String name, java.io.Reader reader)
-
-
-
Constructor Detail
-
TemporaryAssetFolder
public TemporaryAssetFolder(@Nonnull java.io.File baseTempDirectory) throws java.io.IOException
- Throws:
java.io.IOException
-
TemporaryAssetFolder
public TemporaryAssetFolder(@Nonnull java.nio.file.Path baseTempDirectory) throws java.io.IOException
- Throws:
java.io.IOException
-
-
Method Detail
-
getPath
public java.nio.file.Path getPath()
-
getFile
public java.io.File getFile()
-
resolvePath
public java.nio.file.Path resolvePath(java.lang.String name)
-
resolveFile
public java.io.File resolveFile(java.lang.String name)
-
put
public java.nio.file.Path put(java.lang.String name, byte[] content) throws java.io.IOException
- Throws:
java.io.IOException
-
put
public java.nio.file.Path put(java.lang.String name, Binary content) throws java.io.IOException
- Throws:
java.io.IOException
-
write
public java.nio.file.Path write(java.lang.String name, java.io.InputStream contentStream) throws java.io.IOException
- Throws:
java.io.IOException
-
put
public java.nio.file.Path put(java.lang.String name, java.lang.CharSequence content) throws java.io.IOException
- Throws:
java.io.IOException
-
write
public java.nio.file.Path write(java.lang.String name, java.io.Reader reader) throws java.io.IOException
- Throws:
java.io.IOException
-
getString
public java.lang.String getString(java.lang.String name) throws java.io.IOException
- Throws:
java.io.IOException
-
getBytes
public byte[] getBytes(java.lang.String name) throws java.io.IOException
- Throws:
java.io.IOException
-
getBinary
public Binary getBinary(java.lang.String name) throws java.io.IOException
- Throws:
java.io.IOException
-
getInputStream
@WillNotClose public java.io.InputStream getInputStream(java.lang.String name) throws java.io.FileNotFoundException
- Throws:
java.io.FileNotFoundException
-
getReader
@WillNotClose public java.io.Reader getReader(java.lang.String name) throws java.io.FileNotFoundException
- Throws:
java.io.FileNotFoundException
-
getOutputStream
@WillNotClose public java.io.OutputStream getOutputStream(java.lang.String name) throws java.io.FileNotFoundException
- Throws:
java.io.FileNotFoundException
-
getOutputStream
@WillNotClose public java.io.OutputStream getOutputStream(java.lang.String name, boolean append) throws java.io.FileNotFoundException
- Throws:
java.io.FileNotFoundException
-
getWriter
@WillNotClose public java.io.Writer getWriter(java.lang.String name) throws java.io.FileNotFoundException
- Throws:
java.io.FileNotFoundException
-
getWriter
@WillNotClose public java.io.Writer getWriter(java.lang.String name, boolean append) throws java.io.FileNotFoundException
- Throws:
java.io.FileNotFoundException
-
list
public java.util.Collection<java.nio.file.Path> list() throws java.io.IOException
- Throws:
java.io.IOException
-
list
public java.util.Collection<java.nio.file.Path> list(boolean recursive) throws java.io.IOException
- Throws:
java.io.IOException
-
close
public void close() throws java.io.IOException
- Specified by:
close
in interfacejava.lang.AutoCloseable
- Specified by:
close
in interfacejava.io.Closeable
- Throws:
java.io.IOException
-
-