Package com.trafficparrot.sdk.file
Class FileMessage
java.lang.Object
com.trafficparrot.sdk.file.FileMessage
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionbyte[]bytes()The content to write: the exact bytes this message was built from withofBytes(java.lang.String, byte[], long), otherwise the UTF-8 encoding oftext, or no bytes whentextis null.The file holding this message's content, for a message built withofFile(java.lang.String, java.nio.file.Path, long); empty for every other message.static FileMessageA message whose content is written back exactly as given, binary included.static FileMessageA message whose content stays incontent, for a file larger thantrafficparrot.file.body.inMemory.max.size.mb: reading it into memory could exhaust the heap.toString()A binary message is described by its size: its text is a lossy decoding that can run to megabytes.
-
Field Details
-
fileName
-
text
-
timestamp
public final long timestamp
-
-
Constructor Details
-
FileMessage
-
-
Method Details
-
ofBytes
A message whose content is written back exactly as given, binary included. A static factory rather than a constructor overload, so an existingnew FileMessage(name, null, timestamp)still compiles. -
ofFile
A message whose content stays incontent, for a file larger thantrafficparrot.file.body.inMemory.max.size.mb: reading it into memory could exhaust the heap. Itstextis null, andcontentFile()gives the file.- Throws:
UncheckedIOException- when the file's size cannot be read
-
contentFile
The file holding this message's content, for a message built withofFile(java.lang.String, java.nio.file.Path, long); empty for every other message. It is valid only while the message is being handled: Traffic Parrot deletes or replaces it afterwards. Read it, do not modify it, and close any stream opened on it before returning, since an open file cannot be deleted on Windows. -
bytes
public byte[] bytes()The content to write: the exact bytes this message was built from withofBytes(java.lang.String, byte[], long), otherwise the UTF-8 encoding oftext, or no bytes whentextis null. Always a fresh array, so the caller may modify it. For a message built withofFile(java.lang.String, java.nio.file.Path, long)this reads the whole file into memory, which is what that message exists to avoid: prefer readingcontentFile()as a stream.- Throws:
UncheckedIOException- when the content file cannot be read
-
toString
A binary message is described by its size: its text is a lossy decoding that can run to megabytes. A long text is given by its start and length, since every file received and every reply sent is logged at INFO.
-