public static int write(Map<String, String> map, DataOutputStream stream) throws IOException {
    if (map == null) {
      return write(-1, stream);
    }

    int length = 0;
    byte[] bytes;
    stream.writeInt(map.size());
    length += 4;
    for (Map.Entry<String, String> entry : map.entrySet()) {
      bytes = entry.getKey().getBytes();
      stream.writeInt(bytes.length);
      length += 4;
      stream.write(bytes);
      length += bytes.length;
      bytes = entry.getValue().getBytes();
      stream.writeInt(bytes.length);
      length += 4;
      stream.write(bytes);
      length += bytes.length;
    }
    return length;
  }
write a map to dataOutputStream

@return length
iotdb-core/node-commons/src/main/java/org/apache/iotdb/commons/utils/BasicStructureSerDeUtil.java