public final class JsonWriter extends Object implements Closeable
Typical usage:
If there is to much data to keep in memory, or the writing is based on a streaming source, it is possible to append chunks of data to the last JsonLog instance written, like:JsonWriter writer = new JsonWriter(new File("path/to/file.json"), true, 2); writer.write(jsonLog); writer.close();
Note that the pretty print mode of this writer will behave different than a standard JSON writer in that it always writes curve data arrays horizontally, with each curve vertically aligned.JsonWriter writer = new JsonWriter(new File("path/to/file.json"), true, 2); writer.write(jsonLog); writer.append(jsonLog); writer.append(jsonLog); : writer.close();
If the JSON log header contains a valid dataUri property, the curve data will be written in binary form to this location.
Constructor and Description |
---|
JsonWriter(File file)
Create a JSON Well Log Format writer for the specified file.
|
JsonWriter(File file,
boolean isPretty,
int indentation)
Create a JSON Well Log Format writer for the specified disk file.
|
JsonWriter(OutputStream outputStream,
boolean isPretty,
int indentation)
Create a JSON Well Log Format writer for the specified stream.
|
Modifier and Type | Method and Description |
---|---|
void |
append(JsonLog log)
Append the curve data of the specified log.
|
void |
close()
Append closing brackets and close the back-end stream.
|
static String |
toString(JsonLog log)
Convenience method for returning a pretty printed string representation
of the specified log.
|
static String |
toString(JsonLog log,
boolean isPretty,
int indentation)
Convenience method for returning a string representation of the specified log.
|
static String |
toString(List<JsonLog> logs,
boolean isPretty,
int indentation)
Convenience method for returning a string representation of the specified logs.
|
void |
write(JsonLog log)
Write the specified log.
|
public JsonWriter(OutputStream outputStream, boolean isPretty, int indentation)
outputStream
- Stream to write. Non-null.isPretty
- True to write in human readable pretty format, false
to write as dense as possible.indentation
- The white space indentation used in pretty print mode. [0,>.
If isPretty is false, this setting has no effect.IllegalArgumentException
- If outputStream is null or indentation is out of bounds.public JsonWriter(File file, boolean isPretty, int indentation)
file
- Disk file to write. Non-null.isPretty
- True to write in human readable pretty format, false
to write as dense as possible.indentation
- The white space indentation used in pretty print mode. [0,>.
If isPretty is false, this setting has no effect.IllegalArgumentException
- If file is null or indentation is out of bounds.public JsonWriter(File file)
file
- Disk file to write. Non-null.IllegalArgumentException
- If file is null.public void write(JsonLog log) throws IOException
Multiple logs can be written in sequence to the same stream.
Additional data can be appended to the last one by append(no.petroware.logio.json.JsonLog)
.
When writing is done, close the writer with close()
.
If the log header contains a valid dataUri property, the curve data will be written in binary form to this location.
log
- Log to write. Non-null.IllegalArgumentException
- If log is null.IOException
- If the write operation fails for some reason.public void append(JsonLog log) throws IOException
This feature can be used to stream data to a JSON destination. By repeatedly clearing and populating the log curves with new data there is no need for the client to keep the full volume in memory at any point in time.
If the log hedaer contains a valid dataUri property, the curve data will be written in binary form to this location.
NOTE: This method should be called after the
JSON Well Log Format metadata has been written (see write(no.petroware.logio.json.JsonLog)
),
and the JSON log must be compatible with this.
When writing is done, close the stream with close()
.
log
- Log to append to stream. Non-null.IllegalArgumentException
- If log is null.IllegalStateException
- If the writer is not open for writing.IOException
- If the write operation fails for some reason.public void close() throws IOException
close
in interface Closeable
close
in interface AutoCloseable
IOException
public static String toString(List<JsonLog> logs, boolean isPretty, int indentation)
Note: If a log header contains the dataUri property, this will be masked for the present operation so that curve data always appears in the returned JSON string.
logs
- Logs to write. Non-null.isPretty
- True to write in human readable pretty format, false
to write as dense as possible.indentation
- The white space indentation used in pretty print mode. [0,>.
If isPretty is false, this setting has no effect.IllegalArgumentException
- If logs is null or indentation is out of bounds.public static String toString(JsonLog log, boolean isPretty, int indentation)
Note: If a log header contains the dataUri property, this will be masked for the present operation so that curve data always appears in the returned JSON string.
log
- Log to write. Non-null.isPretty
- True to write in human readable pretty format, false
to write as dense as possible.indentation
- The white space indentation used in pretty print mode. [0,>.
If isPretty is false, this setting has no effect.IllegalArgumentException
- If log is null or indentation is out of bounds.public static String toString(JsonLog log)
Note: If a log header contains the dataUri property, this will be masked for the present operation so that curve data always appears in the returned JSON string.
log
- Log to write. Non-null.IllegalArgumentException
- If log is null.Copyright © 2024 Petroware AS - https://petroware.no