Write and read TsFile in java
What is TsFile
TsFile is a kind of file format which supports for columnar database storage.
Click link http://iotdb.incubator.apache.org/#/ for more information.
maven dependencies
<dependency>
<groupId>cn.edu.tsinghua</groupId>
<artifactId>tsfile</artifactId>
<version>0.7.0</version>
</dependency>
<dependency>
<groupId>org.apache.hadoop</groupId>
<artifactId>hadoop-client</artifactId>
<version>2.7.7</version>
</dependency>
Create a package, hadoop. In this package we have two Classes, HDFSInputStream and HDFSOutputStream.
HDFSInputStream
package hadoop;
import cn.edu.tsinghua.tsfile.common.utils.ITsRandomAccessFileReader;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.FSDataInputStream;
import org.apache.hadoop.fs.FileStatus;
import org.apache.hadoop.fs.FileSystem;
import org.apache.hadoop.fs.Path;
import java.io.IOException;
public class HDFSInputStream implements ITsRandomAccessFileReader {
private FSDataInputStream fsDataInputStream;
private FileStatus fileStatus;
public HDFSInputStream(String filePath) throws IOException {
this(filePath, new Configuration());
}
public HDFSInputStream(String filePath, Configuration configuration) throws IOException {
this(new Path(filePath), configuration);
}
public HDFSInputStream(Path path, Configuration configuration) throws IOException {
FileSystem fs = FileSystem.get(configuration);
fsDataInputStream = fs.open(path);
fileStatus = fs.getFileStatus(path);
}
public void seek(long offset) throws IOException {
fsDataInputStream.seek(offset);
}
public int read() throws I