de.innovationgate.utils
public class TemporaryFile extends java.lang.Object
The file and directory will NOT be automatically deleted on VM termination anymore (see B000048C2). They should be manually
deleted by calling delete()
when you are finished with them, or be bound to the eviction of a context object by
using deleteOnEviction(Object)
.
Constructor and Description |
---|
TemporaryFile(java.lang.String name,
java.io.InputStream in,
java.io.File tempFolder)
Constructs a temporary file object and initializes it with the data from an input stream
If the input stream that is providing data is a java.util.zip.ZipInputStream it is NOT closed after
the file data is read (to allow further reading of other file entries in the zip data)!
|
Modifier and Type | Method and Description |
---|---|
java.io.OutputStream |
createOutputStream()
Creates an output stream to write binary data to the file.
|
java.io.PrintWriter |
createWriter()
Creates a writer to write UTF-8 character data to the file.
|
java.io.PrintWriter |
createWriter(java.lang.String charset)
Creates a writer to write character data to the file.
|
void |
delete()
Manually delete the temporary file and it's temporary directory
|
void |
deleteOnEviction(java.lang.Object obj)
Will keep the file alive until the given object is garbage-collected.
|
java.io.File |
getFile()
The temporary file as Java file object
|
static void |
stopEviction()
Stops the eviction thread
|
public TemporaryFile(java.lang.String name, java.io.InputStream in, java.io.File tempFolder) throws java.io.IOException
If the input stream that is providing data is a java.util.zip.ZipInputStream it is NOT closed after the file data is read (to allow further reading of other file entries in the zip data)! All other stream types are closed automatically after object creation.
name
- The name that file should have in file systemin
- The input stream providing data for the temporary file. Omit to leave the file emptytempFolder
- The temp folder containing temporary filesjava.io.IOException
public static void stopEviction()
public void delete()
public void deleteOnEviction(java.lang.Object obj)
obj
- public java.io.File getFile()
public java.io.PrintWriter createWriter(java.lang.String charset) throws java.io.UnsupportedEncodingException, java.io.FileNotFoundException
charset
- Target charset of the filejava.io.FileNotFoundException
java.io.UnsupportedEncodingException
public java.io.PrintWriter createWriter() throws java.io.UnsupportedEncodingException, java.io.FileNotFoundException
java.io.FileNotFoundException
java.io.UnsupportedEncodingException
public java.io.OutputStream createOutputStream() throws java.io.FileNotFoundException
java.io.FileNotFoundException