- java.lang.Object
-
- org.ojalgo.netio.InMemoryFile
-
public class InMemoryFile extends java.lang.ObjectAn in-memory "file" that can be used with someToFileWriterand/orFromFileReaderrimplementations instead of aFile.To dynamically create file contents that only exist in memory (for download): Feed an instance of
InMemoryFilerather thanFileto aToFileWriterthat support doing so (like theTextLineWriter), and keep a reference to theInMemoryFileinstance. When done writing you get the (file) contents from that instance.To parse some data you have in memory: Create an instance of
InMemoryFileusing one of the constructors that takebyte[]orStringas input, and feed that to aFromFileReaderthat support doing so (like theTextLineReader).Note that you can obtain both
OutputStreamandInputStreaminstances from anInMemoryFile– you can write to AND (later) read from the same instance.This class is essentially a
byte[]wrapper making use ofByteArrayInputStreamandByteArrayOutputStream.
-
-
Field Summary
Fields Modifier and Type Field Description private byte[]myInitialContentsprivate java.io.ByteArrayInputStreammyInputStreamprivate java.lang.StringmyNameprivate java.io.ByteArrayOutputStreammyOutputStreamprivate java.lang.StringmyType
-
Constructor Summary
Constructors Constructor Description InMemoryFile()InMemoryFile(byte[] contents)InMemoryFile(java.lang.String contents)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description byte[]getContentsAsByteArray()java.lang.StringgetContentsAsString()java.util.Optional<java.lang.String>getName()File Namejava.util.Optional<java.lang.String>getType()Media (content) TypeInMemoryFilename(java.lang.String name)java.io.InputStreamnewInputStream()Creates a newInputStreamwith each invocation (but keeps a reference to it for later internal use).java.io.OutputStreamnewOutputStream()Creates a newOutputStreamwith each invocation (but keeps a reference to it for later internal use).voidsetName(java.lang.String name)voidsetType(java.lang.String type)InMemoryFiletype(java.lang.String type)
-
-
-
Method Detail
-
getContentsAsByteArray
public byte[] getContentsAsByteArray()
-
getContentsAsString
public java.lang.String getContentsAsString()
-
getName
public java.util.Optional<java.lang.String> getName()
File Name
-
getType
public java.util.Optional<java.lang.String> getType()
Media (content) Type
-
name
public InMemoryFile name(java.lang.String name)
-
newInputStream
public java.io.InputStream newInputStream()
Creates a newInputStreamwith 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 anOutputStreamobtained vianewOutputStream().
-
newOutputStream
public java.io.OutputStream newOutputStream()
Creates a newOutputStreamwith 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
public void setName(java.lang.String name)
-
setType
public void setType(java.lang.String type)
-
type
public InMemoryFile type(java.lang.String type)
-
-