Function

The example is to show how to write and read a TsFile File.

Usage

Dependencies with Maven

<dependencies>
    <dependency>
        <groupId>org.apache.iotdb</groupId>
        <artifactId>tsfile</artifactId>
     	  <version>1.0.0</version>
    </dependency>
</dependencies>

Run TsFileWrite.java

This class is to show how to write a TsFile. It provided two ways:

The first one is using a JSON string for measurement(s). The JSON string is an array of JSON objects(schema). The object must include the measurement_id, datatype, encoding, and compressor.

An example JSON string is provided in the comments in the method

    public static void tsFileWriteWithJson() throws IOException,WriteProcessException

It uses this interface

    public void addMeasurementByJson(JSONObject measurement) throws WriteProcessException  

An alternative way is to add these measurements directly(manually) by the second interface:

     public void addMeasurement(MeasurementSchema measurementSchema) throws WriteProcessException

The method

     public static void tsFileWriteDirect() throws IOException,WriteProcessException

shows how to use that interface.

Note that the measurements in the two methods are the same therefore there output TsFile should also be identical.

Run TsFileRead.java

This class is to show how to read TsFile file named “testDirect.tsfile”.

The TsFile file “testDirect.tsfile” is generated from class TsFileWrite.

It generates the same TsFile(testDirect.tsfile and testWithJson.tsfile) file by two different ways

Run TsFileWrite to generate the testDirect.tsfile first

Run TsFileSequenceRead.java

This class is to show the structure of a TsFile.

Notice

 For detail, please refer to https://github.com/apache/iotdb/blob/master/tsfile/README.md.