Class InMemoryFile
ToFileWriter
and/or
invalid reference
FromFileReaderr
File
.
To dynamically create file contents that only exist in memory (for download): Feed an instance of
InMemoryFile
rather than File
to a ToFileWriter
that support doing so (like the
TextLineWriter
), and keep a reference to the InMemoryFile
instance. When done writing you
get the (file) contents from that instance.
To parse some data you have in memory: Create an instance of InMemoryFile
using one of the
constructors that take byte[]
or String
as input, and feed that to a
FromFileReader
that support doing so (like the TextLineReader
).
Note that you can obtain both OutputStream
and InputStream
instances from an
InMemoryFile
– you can write to AND (later) read from the same instance.
This class is essentially a byte[]
wrapper making use of ByteArrayInputStream
and
ByteArrayOutputStream
.
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate byte[]
private ByteArrayInputStream
private String
private ByteArrayOutputStream
private String
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionbyte[]
getName()
File NamegetType()
MIME TypeCreates a newInputStream
with each invocation (but keeps a reference to it for later internal use).Creates a newOutputStream
with each invocation (but keeps a reference to it for later internal use).void
void
-
Field Details
-
myInitialContents
private byte[] myInitialContents -
myInputStream
-
myName
-
myOutputStream
-
myType
-
-
Constructor Details
-
InMemoryFile
public InMemoryFile() -
InMemoryFile
public InMemoryFile(byte[] contents) -
InMemoryFile
-
-
Method Details
-
getContentsAsByteArray
public byte[] getContentsAsByteArray() -
getContentsAsString
-
getName
File Name -
getType
MIME Type -
name
-
newInputStream
Creates a newInputStream
with each invocation (but keeps a reference to it for later internal use). The actual "input" is taken from the contents provided to the constructor or what was later written to anOutputStream
obtained vianewOutputStream()
. -
newOutputStream
Creates a newOutputStream
with each invocation (but keeps a reference to it for later internal use). Calling this method also clears any/all cached previous contents – you're expected to create new content with this. -
setName
-
setType
-
type
-