public class SerializableFileReference extends Object implements Serializable, AutoCloseable
Path
that can be serialized. When serialized it will write all the file data to
the serialization stream.
When deserialized, it will copy all file-data to a new temporary file.Constructor and Description |
---|
SerializableFileReference(Path path)
Create a binary
SerializableFileReference for the file at given path. |
SerializableFileReference(Path path,
boolean deleteOnClose)
Create a binary
SerializableFileReference for the file at given path. |
SerializableFileReference(String charset,
Path path)
Create a character-data
SerializableFileReference for the file at given path. |
Modifier and Type | Method and Description |
---|---|
void |
close() |
void |
delete() |
protected void |
finalize() |
InputStream |
getInputStream() |
BufferedReader |
getReader() |
long |
getSize() |
static SerializableFileReference |
of(byte[] data)
Create a new
SerializableFileReference from the given byte[] . |
static SerializableFileReference |
of(InputStream in)
Create a new
SerializableFileReference from the given InputStream . |
static SerializableFileReference |
of(Reader in,
String charset)
Create a new
SerializableFileReference from the given Reader . |
static SerializableFileReference |
of(String data,
String charset)
Create a new
SerializableFileReference from the given String . |
public SerializableFileReference(Path path)
SerializableFileReference
for the file at given path.
The file will be not deleted on calling close()
.
path
- Path
to the file being referenced.public SerializableFileReference(Path path, boolean deleteOnClose)
SerializableFileReference
for the file at given path.public SerializableFileReference(String charset, Path path)
SerializableFileReference
for the file at given path.
The file will be not deleted on calling close()
.
charset
- Character set to be used when reading the file.path
- Path
to the file being referenced.public static SerializableFileReference of(InputStream in) throws IOException
SerializableFileReference
from the given InputStream
. The InputStream
will be copied
to a temporary file on disk and will be closed afterward. The SerializableFileReference
will be treated as binary data.
The temporary file will be deleted on calling close()
.
in
- The InputStream
from which to create the SerializableFileReference
. Will be closed after completion of this method.SerializableFileReference
.IOException
- If the InputStream
cannot be read or a temporary file cannot be created / written to.public static SerializableFileReference of(byte[] data) throws IOException
SerializableFileReference
from the given byte[]
. The byte[]
will be copied
to a temporary file on disk. The SerializableFileReference
will be treated as binary data.
The temporary file will be deleted on calling close()
.
data
- The byte[]
from which to create the SerializableFileReference
.SerializableFileReference
.IOException
- If the byte[]
cannot be written to a temporary file.public static SerializableFileReference of(Reader in, String charset) throws IOException
SerializableFileReference
from the given Reader
. The Reader
will be copied
to a temporary file on disk and will be closed afterward. The SerializableFileReference
will be treated as character data.
The temporary file will be deleted on calling close()
.
in
- The Reader
from which to create the SerializableFileReference
. Will be closed after completion of this method.charset
- Character set of the data in the Reader
.SerializableFileReference
.IOException
- If the Reader
cannot be read or a temporary file cannot be created / written to.public static SerializableFileReference of(String data, String charset) throws IOException
SerializableFileReference
from the given String
. The String
will be copied
to a temporary file on disk. The SerializableFileReference
will be treated as character data.
The temporary file will be deleted on calling close()
.
data
- The String
from which to create the SerializableFileReference
.charset
- Character used for writing out and reading back the data.SerializableFileReference
.IOException
- If the String
data cannot be written to a temporary file.public long getSize()
public BufferedReader getReader() throws IOException
IOException
public InputStream getInputStream() throws IOException
IOException
public void delete()
public void close() throws Exception
close
in interface AutoCloseable
Exception
Copyright © 2023 Frank!Framework. All rights reserved.