Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ public void checkFile(String filepath) {
// get existed properties from system_properties.txt
File inputFile = SystemFileFactory.INSTANCE.getFile(filepath + File.separator + PROPERTIES_FILE_NAME);
try (FileInputStream inputStream = new FileInputStream(inputFile.toString())) {
properties.load(new InputStreamReader(inputStream, TSFileConfig.STRING_ENCODING));
properties.load(new InputStreamReader(inputStream, TSFileConfig.STRING_CHARSET));
if (!properties.getProperty("timestamp_precision").equals(TIMESTAMP_PRECISION)) {
logger.error("Wrong timestamp precision, please set as: " + properties
.getProperty("timestamp_precision") + " !");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
*/
package org.apache.iotdb.tsfile.common.conf;

import java.nio.charset.Charset;
import org.apache.iotdb.tsfile.fileSystem.FSType;

/**
Expand Down Expand Up @@ -49,6 +50,7 @@ public class TSFileConfig {
*/
public static final int BYTE_SIZE_PER_CHAR = 4;
public static final String STRING_ENCODING = "UTF-8";
public static final Charset STRING_CHARSET = Charset.forName(STRING_ENCODING);
public static final String CONFIG_FILE_NAME = "tsfile-format.properties";
public static final String MAGIC_STRING = "TsFilev0.8.0";
/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public ChunkGroupFooter(String deviceID, long dataSize, int numberOfChunks) thro
this.dataSize = dataSize;
this.numberOfChunks = numberOfChunks;
this.serializedSize =
Byte.BYTES + Integer.BYTES + deviceID.getBytes(TSFileConfig.STRING_ENCODING).length + Long.BYTES + Integer.BYTES;
Byte.BYTES + Integer.BYTES + deviceID.getBytes(TSFileConfig.STRING_CHARSET).length + Long.BYTES + Integer.BYTES;
}

public static int getSerializedSize(String deviceID) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,12 +76,7 @@ private ChunkHeader(String measurementID, int dataSize, TSDataType dataType,
}

public static int getSerializedSize(String measurementID) {
try {
return Byte.BYTES + Integer.BYTES + getSerializedSize(measurementID.getBytes(TSFileConfig.STRING_ENCODING).length);
} catch (UnsupportedEncodingException e) {
LOG.error("{} encoding is not supported", TSFileConfig.STRING_ENCODING);
return Byte.BYTES + Integer.BYTES + getSerializedSize(measurementID.getBytes().length);
}
return Byte.BYTES + Integer.BYTES + getSerializedSize(measurementID.getBytes(TSFileConfig.STRING_CHARSET).length);
}

private static int getSerializedSize(int measurementIdLength) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

package org.apache.iotdb.tsfile.file.metadata;

import java.io.UnsupportedEncodingException;
import org.apache.iotdb.tsfile.common.conf.TSFileConfig;
import org.apache.iotdb.tsfile.utils.ReadWriteIOUtils;

Expand All @@ -28,11 +29,14 @@
import java.nio.ByteBuffer;
import java.util.ArrayList;
import java.util.List;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
* Metadata of ChunkGroup.
*/
public class ChunkGroupMetaData {
private static final Logger logger = LoggerFactory.getLogger(ChunkGroupMetaData.class);

/**
* Name of device, this field is not serialized.
Expand Down Expand Up @@ -104,7 +108,7 @@ public static ChunkGroupMetaData deserializeFrom(InputStream inputStream) throws

int size = ReadWriteIOUtils.readInt(inputStream);
chunkGroupMetaData.serializedSize = Integer.BYTES
+ chunkGroupMetaData.deviceID.getBytes(TSFileConfig.STRING_ENCODING).length
+ chunkGroupMetaData.deviceID.getBytes(TSFileConfig.STRING_CHARSET).length
+ Integer.BYTES + Long.BYTES + Long.BYTES + Long.BYTES;

List<ChunkMetaData> chunkMetaDataList = new ArrayList<>();
Expand Down Expand Up @@ -135,7 +139,7 @@ public static ChunkGroupMetaData deserializeFrom(ByteBuffer buffer) throws IOExc

int size = ReadWriteIOUtils.readInt(buffer);

chunkGroupMetaData.serializedSize = Integer.BYTES + chunkGroupMetaData.deviceID.getBytes(TSFileConfig.STRING_ENCODING).length
chunkGroupMetaData.serializedSize = Integer.BYTES + chunkGroupMetaData.deviceID.getBytes(TSFileConfig.STRING_CHARSET).length
+ Integer.BYTES + Long.BYTES + Long.BYTES + Long.BYTES;

List<ChunkMetaData> chunkMetaDataList = new ArrayList<>();
Expand All @@ -154,8 +158,8 @@ public int getSerializedSize() {
}

void reCalculateSerializedSize() {
serializedSize = Integer.BYTES + deviceID.length() + Integer.BYTES
+ Long.BYTES + Long.BYTES + Long.BYTES; // size of chunkMetaDataList
serializedSize = Integer.BYTES + deviceID.getBytes(TSFileConfig.STRING_CHARSET).length + Integer.BYTES
+ Long.BYTES + Long.BYTES + Long.BYTES; // size of chunkMetaDataList
for (ChunkMetaData chunk : chunkMetaDataList) {
serializedSize += chunk.getSerializedSize();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -146,13 +146,7 @@ public int getSerializedSize() {
TSDataType.getSerializedSize() + // TSDataType
(valuesStatistics == null ? TsDigest.getNullDigestSize()
: valuesStatistics.getSerializedSize()));
try {
serializedSize += measurementUid.getBytes(TSFileConfig.STRING_ENCODING).length; // measurementUid
} catch (UnsupportedEncodingException e) {
// use the system default encoding
serializedSize += measurementUid.getBytes().length; // measurementUid
LOG.error("{} encoding is not supported", TSFileConfig.STRING_ENCODING);
}
serializedSize += measurementUid.getBytes(TSFileConfig.STRING_CHARSET).length; // measurementUid
return serializedSize;
}

Expand Down
10 changes: 3 additions & 7 deletions tsfile/src/main/java/org/apache/iotdb/tsfile/utils/Binary.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ public class Binary implements Comparable<Binary>, Serializable {
private static final long serialVersionUID = 6394197743397020735L;

private byte[] values;
private String textEncodingType = TSFileConfig.STRING_ENCODING;

/**
* if the bytes v is modified, the modification is visible to this binary.
Expand All @@ -44,7 +43,7 @@ public Binary(byte[] v) {
}

public Binary(String s) {
this.values = (s == null) ? null : s.getBytes(Charset.forName(this.textEncodingType));
this.values = (s == null) ? null : s.getBytes(TSFileConfig.STRING_CHARSET);
}

public static Binary valueOf(String value) {
Expand Down Expand Up @@ -105,16 +104,13 @@ public int getLength() {
}

public String getStringValue() {
return new String(this.values, Charset.forName(this.textEncodingType));
return new String(this.values, TSFileConfig.STRING_CHARSET);
}

public String getTextEncodingType() {
return textEncodingType;
return TSFileConfig.STRING_ENCODING;
}

public void setTextEncodingType(String textEncodingType) {
this.textEncodingType = textEncodingType;
}

@Override
public String toString() {
Expand Down
14 changes: 2 additions & 12 deletions tsfile/src/main/java/org/apache/iotdb/tsfile/utils/BytesUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -567,12 +567,7 @@ public static long bytesToLongFromOffset(byte[] byteNum, int len, int offset) {
* @return byte array
*/
public static byte[] stringToBytes(String str) {
try {
return str.getBytes(TSFileConfig.STRING_ENCODING);
} catch (UnsupportedEncodingException e) {
LOG.error("catch UnsupportedEncodingException {}", str, e);
return null;
}
return str.getBytes(TSFileConfig.STRING_CHARSET);
}

/**
Expand All @@ -582,12 +577,7 @@ public static byte[] stringToBytes(String str) {
* @return string
*/
public static String bytesToString(byte[] byteStr) {
try {
return new String(byteStr, TSFileConfig.STRING_ENCODING);
} catch (UnsupportedEncodingException e) {
LOG.error("catch UnsupportedEncodingException {}", byteStr, e);
return null;
}
return new String(byteStr, TSFileConfig.STRING_CHARSET);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

import java.util.ArrayList;
import java.util.List;
import org.apache.iotdb.tsfile.common.conf.TSFileConfig;

/**
* this class is used to contact String effectively.It contains a StringBuider and initialize it
Expand Down