public final class JsonReader extends Object
Typical usage:
If the curve data is not needed, it is possible to read only the metadata. The curve data may be filled in later:JsonReader reader = new JsonReader(new File("path/to/file.json")); List<JsonLog> logs = reader.read(true, true, null);
Note that even if only metadata is read, all curve information are properly established as this information comes from metadata. Only the curve values will be missing.JsonReader reader = new JsonReader(new File("path/to/file.json")); List<JsonLog> logs = reader.read(false, false, null); : reader.readData(logs);
If the JSON content is larger than physical memory, it is possible
to stream (process than throw away) the data during read.
See JsonDataListener
. The same mechanism may be used
to abort the reading process during the operation.
Constructor and Description |
---|
JsonReader(File file)
Create a JSON reader for the specified disk file.
|
JsonReader(InputStream inputStream)
Create a JSON reader for the specified stream.
|
JsonReader(javax.json.JsonArray jsonArray)
Create a JSON reader from a populated JSON array of JsonLogs.
|
JsonReader(String text)
Create a JSON reader for the specified text.
|
Modifier and Type | Method and Description |
---|---|
static double |
isJsonFile(File file,
byte[] content)
Get the probability that the specified file is a
JSON Well Log Format file.
|
List<JsonLog> |
read()
Read all logs from the content of this reader.
|
List<JsonLog> |
read(boolean shouldReadBulkData,
boolean shouldCaptureStatistics,
JsonDataListener dataListener)
Read all logs from the content of this reader.
|
void |
readData(List<JsonLog> logs,
boolean shouldCaptureStatistics,
JsonDataListener dataListener)
Read data for a set of JSON logs where the metadata has
already been read.
|
JsonLog |
readOne()
Read all logs from the content of this reader and return
the first one.
|
public JsonReader(InputStream inputStream)
inputStream
- Stream to read. Non-null.IllegalArgumentException
- If inputStream is null.public JsonReader(File file)
file
- Disk file to read. Non-null.IllegalArgumentException
- If file is null.public JsonReader(String text)
text
- Text to read. Non-null.IllegalArgumentException
- If text is null.public JsonReader(javax.json.JsonArray jsonArray)
jsonArray
- Array constituting the JSON Well Log Format logs. Non-null.IllegalArgumentException
- If jsonArray is null.public static double isJsonFile(File file, byte[] content)
The check can be done with or without considering the content of the file. In the latter case, only the file name (typically its extension) is considered. In the former case a portion from the start of the file is used to match for known patterns. By passing the portion as an argument, the client code can read this once and then pass it to different classifiers in order to determine its most likely type.
Getting a portion of a file can be done by:
File file = ...; BufferedInputStream stream = new BufferedInputStream(new FileInputStream(file)); byte[] content = new byte[2000]; stream.read(content, 0, content.length); stream.close();
file
- File to check. Null to classify on content only.content
- A number of bytes from the start of the file.
Null to classify on file name only.public void readData(List<JsonLog> logs, boolean shouldCaptureStatistics, JsonDataListener dataListener) throws IOException, InterruptedException
// Read meta data List<JsonLog> logs = reader.read(false, ...); // Read the curve data reader.readData(logs);There is nothing to gain in performance with this approach so in case the result is not cached, the following will be equivalent:
// Read metadata List<JsonLog> logs = reader.read(false, ...); // Read all the data logs = reader.read(true, ...);
logs
- The logs to populate. These must be the
exact same list as retrieved by calling the
#read(false,...) on the same JsonReader instance.
Otherwise the behavior is unpredictable.shouldCaptureStatistics
- True to capture statistics per curve during read.
Statistics capture will reduce read performance slightly,
so set this to false if the statistics are not needed.dataListener
- Listener that will be notified when new data has been read.
Null if not used.IllegalArgumentException
- If logs is null.IOException
- If the read operation fails for some reason.InterruptedException
- If the client returns false from
the JsonDataListener.dataRead(no.petroware.logio.json.JsonLog)
method.public List<JsonLog> read(boolean shouldReadBulkData, boolean shouldCaptureStatistics, JsonDataListener dataListener) throws IOException, InterruptedException
shouldReadBulkData
- True if bulk data should be read, false
if only metadata should be read.shouldCaptureStatistics
- True if curve statistics should be
captures, false otherwise,dataListener
- Client data listener. Null if not used.IOException
- If the read operation fails for some reason.InterruptedException
- If the client returns false from
the JsonDataListener.dataRead(no.petroware.logio.json.JsonLog)
method.public List<JsonLog> read() throws IOException
IOException
- If the read operation fails for some reason.public JsonLog readOne() throws IOException
IOException
- If the read operation fails for some reason.Copyright © 2024 Petroware AS - https://petroware.no