优化数据安装性能,更换阿里Json库
This commit is contained in:
@@ -120,6 +120,7 @@ dependencies {
|
||||
api 'org.locationtech.jts:jts-core:1.19.0'
|
||||
implementation 'com.squareup.okhttp3:okhttp:5.0.0-alpha.11'
|
||||
implementation 'com.squareup.okio:okio:3.3.0'
|
||||
implementation 'com.alibaba:fastjson:1.2.73'
|
||||
|
||||
implementation "com.fasterxml.jackson.core:jackson-annotations:2.9.9"
|
||||
implementation "com.fasterxml.jackson.core:jackson-core:2.9.9"
|
||||
|
||||
@@ -1558,11 +1558,6 @@
|
||||
<symbol repeat="false" repeat-start="0" repeat-gap="2000"
|
||||
src="@symbol" symbol-height="24" degree="90"></symbol>
|
||||
</m>
|
||||
<!-- 车信CLM -->
|
||||
<m v="OMDB_CLM_LANEINFO" >
|
||||
<symbol repeat="false" repeat-start="0" repeat-gap="2000"
|
||||
src="@symbol" symbol-height="24" degree="90"></symbol>
|
||||
</m>
|
||||
<!-- 杆状物 -->
|
||||
<m v="OMDB_POLE">
|
||||
<symbol src="assets:omdb/icon_pole_3006.svg" symbol-height="56" symbol-width="56"></symbol>
|
||||
|
||||
@@ -25,7 +25,7 @@ open class ReferenceEntity() : RealmObject() {
|
||||
@Ignore
|
||||
lateinit var name: String //要素名
|
||||
lateinit var table: String //要素表名
|
||||
var propertiesDb: ByteArray? = null
|
||||
var propertiesDb: String = ""
|
||||
var code: String = "0" // 要素编码
|
||||
|
||||
@Ignore
|
||||
@@ -80,11 +80,11 @@ open class ReferenceEntity() : RealmObject() {
|
||||
@Ignore
|
||||
var properties: RealmDictionary<String> = RealmDictionary()
|
||||
get() {
|
||||
if (propertiesDb!=null && field.isEmpty()) {
|
||||
if (propertiesDb != null && propertiesDb!!.isNotEmpty() && field.isEmpty()) {
|
||||
try {
|
||||
val gson = Gson()
|
||||
val type = object : TypeToken<RealmDictionary<String>>() {}.type
|
||||
field = gson.fromJson(DeflaterUtil.decompress(propertiesDb).toString(), type)
|
||||
field = gson.fromJson(DeflaterUtil.unzipString(propertiesDb), type)
|
||||
} catch (e: Exception) {
|
||||
Log.e("jingo","ReferenceEntity 转 properties $e")
|
||||
}
|
||||
|
||||
@@ -2,9 +2,9 @@ package com.navinfo.collect.library.data.entity
|
||||
|
||||
import android.os.Parcelable
|
||||
import android.util.Log
|
||||
import com.alibaba.fastjson.JSON
|
||||
import com.google.gson.Gson
|
||||
import com.google.gson.reflect.TypeToken
|
||||
import com.navinfo.collect.library.system.Constant
|
||||
import com.navinfo.collect.library.utils.DeflaterUtil
|
||||
import com.navinfo.collect.library.utils.GeometryTools
|
||||
import com.navinfo.collect.library.utils.GeometryToolsKt
|
||||
@@ -14,13 +14,8 @@ import io.realm.RealmObject
|
||||
import io.realm.RealmSet
|
||||
import io.realm.annotations.Ignore
|
||||
import io.realm.annotations.Index
|
||||
import io.realm.annotations.PrimaryKey
|
||||
import kotlinx.parcelize.Parcelize
|
||||
import org.locationtech.jts.geom.Coordinate
|
||||
import org.locationtech.jts.geom.Geometry
|
||||
import org.oscim.core.MercatorProjection
|
||||
import java.util.*
|
||||
import java.util.zip.GZIPInputStream
|
||||
|
||||
/**
|
||||
* 渲染要素对应的实体
|
||||
@@ -32,7 +27,7 @@ open class RenderEntity() : RealmObject(), Parcelable {
|
||||
lateinit var name: String //要素名
|
||||
lateinit var table: String //要素表名
|
||||
var code: String = "0" // 要素编码
|
||||
var propertiesDb: ByteArray? = null
|
||||
var propertiesDb: String = ""
|
||||
var geometry: String =
|
||||
"" // 要素渲染参考的geometry,该数据可能会在导入预处理环节被修改,原始geometry会保存在properties的geometry字段下
|
||||
get() {
|
||||
@@ -83,11 +78,11 @@ open class RenderEntity() : RealmObject(), Parcelable {
|
||||
@Ignore
|
||||
var properties: RealmDictionary<String> = RealmDictionary()
|
||||
get() {
|
||||
if (propertiesDb != null && field.isEmpty()) {
|
||||
if (propertiesDb != null && propertiesDb!!.isNotEmpty()&& field.isEmpty()) {
|
||||
try {
|
||||
val gson = Gson()
|
||||
val type = object : TypeToken<RealmDictionary<String>>() {}.type
|
||||
field = gson.fromJson(DeflaterUtil.decompress(propertiesDb).toString(), type)
|
||||
field = gson.fromJson(DeflaterUtil.unzipString(propertiesDb), type)
|
||||
} catch (e: Exception) {
|
||||
Log.e("jingo","RenderEntity 转 properties $e")
|
||||
}
|
||||
|
||||
@@ -104,7 +104,7 @@ public class OMDBReferenceDecoder extends TileDecoder {
|
||||
}
|
||||
} else if (geometry instanceof LineString) {
|
||||
//将车道中心进行转化面渲染
|
||||
if(layerName== DataCodeEnum.OMDB_LANE_LINK_LG.name()){
|
||||
if(layerName!=null&&layerName.equals(DataCodeEnum.OMDB_LANE_LINK_LG.name())){
|
||||
Log.e("qj","车道中心线转化开始");
|
||||
processPolygon((Polygon)GeometryTools.createGeometry(GeometryTools.computeLine(0.000035,0.000035,geometry.toString())));
|
||||
Log.e("qj","车道中心线转化结束");
|
||||
|
||||
@@ -4,8 +4,18 @@ import java.io.ByteArrayOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.util.zip.Deflater;
|
||||
import java.util.zip.Inflater;
|
||||
import org.apache.commons.net.util.Base64;
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.zip.DataFormatException;
|
||||
import java.util.zip.Deflater;
|
||||
import java.util.zip.Inflater;
|
||||
|
||||
public class DeflaterUtil {
|
||||
/**
|
||||
* DeflaterUtils 压缩字符串
|
||||
*/
|
||||
|
||||
public class DeflaterUtil{
|
||||
|
||||
private DeflaterUtil() {
|
||||
|
||||
@@ -13,6 +23,138 @@ public class DeflaterUtil {
|
||||
|
||||
private static final int BUFFER_SIZE = 8192;
|
||||
|
||||
/**
|
||||
* 压缩
|
||||
*/
|
||||
|
||||
public static String zipString(String unzipString) {
|
||||
|
||||
/*
|
||||
|
||||
* https://www.yiibai.com/javazip/javazip_deflater.html#article-start
|
||||
|
||||
* 0 ~ 9 压缩等级 低到高
|
||||
|
||||
* public static final int BEST_COMPRESSION = 9; 最佳压缩的压缩级别。
|
||||
|
||||
* public static final int BEST_SPEED = 1; 压缩级别最快的压缩。
|
||||
|
||||
* public static final int DEFAULT_COMPRESSION = -1; 默认压缩级别。
|
||||
|
||||
* public static final int DEFAULT_STRATEGY = 0; 默认压缩策略。
|
||||
|
||||
* public static final int DEFLATED = 8; 压缩算法的压缩方法(目前唯一支持的压缩方法)。
|
||||
|
||||
* public static final int FILTERED = 1; 压缩策略最适用于大部分数值较小且数据分布随机分布的数据。
|
||||
|
||||
* public static final int FULL_FLUSH = 3; 压缩刷新模式,用于清除所有待处理的输出并重置拆卸器。
|
||||
|
||||
* public static final int HUFFMAN_ONLY = 2; 仅用于霍夫曼编码的压缩策略。
|
||||
|
||||
* public static final int NO_COMPRESSION = 0; 不压缩的压缩级别。
|
||||
|
||||
* public static final int NO_FLUSH = 0; 用于实现最佳压缩结果的压缩刷新模式。
|
||||
|
||||
* public static final int SYNC_FLUSH = 2; 用于清除所有未决输出的压缩刷新模式; 可能会降低某些压缩算法的压缩率。
|
||||
|
||||
*/
|
||||
|
||||
//使用指定的压缩级别创建一个新的压缩器。
|
||||
|
||||
Deflater deflater = new Deflater(Deflater.BEST_COMPRESSION);
|
||||
|
||||
//设置压缩输入数据。
|
||||
|
||||
deflater.setInput(unzipString.getBytes(StandardCharsets.UTF_8));
|
||||
|
||||
//当被调用时,表示压缩应该以输入缓冲区的当前内容结束。
|
||||
|
||||
deflater.finish();
|
||||
|
||||
final byte[] bytes = new byte[256];
|
||||
|
||||
ByteArrayOutputStream outputStream = new ByteArrayOutputStream(256);
|
||||
|
||||
while (!deflater.finished()) {
|
||||
|
||||
//压缩输入数据并用压缩数据填充指定的缓冲区。
|
||||
|
||||
int length = deflater.deflate(bytes);
|
||||
|
||||
outputStream.write(bytes, 0, length);
|
||||
|
||||
}
|
||||
|
||||
deflater.end();
|
||||
|
||||
return Base64.encodeBase64String(outputStream.toByteArray());
|
||||
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 解压缩
|
||||
*/
|
||||
|
||||
public static String unzipString(String zipString) {
|
||||
|
||||
byte[] decode = Base64.decodeBase64(zipString);
|
||||
|
||||
//创建一个新的解压缩器 https://www.yiibai.com/javazip/javazip_inflater.html
|
||||
|
||||
Inflater inflater = new Inflater();
|
||||
|
||||
//设置解压缩的输入数据。
|
||||
|
||||
inflater.setInput(decode);
|
||||
|
||||
final byte[] bytes = new byte[256];
|
||||
|
||||
ByteArrayOutputStream outputStream = new ByteArrayOutputStream(256);
|
||||
|
||||
try {
|
||||
|
||||
//finished() 如果已到达压缩数据流的末尾,则返回true。
|
||||
|
||||
while (!inflater.finished()) {
|
||||
|
||||
//将字节解压缩到指定的缓冲区中。
|
||||
|
||||
int length = inflater.inflate(bytes);
|
||||
|
||||
outputStream.write(bytes, 0, length);
|
||||
|
||||
}
|
||||
|
||||
} catch (DataFormatException e) {
|
||||
|
||||
e.printStackTrace();
|
||||
|
||||
return null;
|
||||
|
||||
} finally {
|
||||
|
||||
//关闭解压缩器并丢弃任何未处理的输入。
|
||||
|
||||
inflater.end();
|
||||
|
||||
}
|
||||
|
||||
try {
|
||||
|
||||
return outputStream.toString("UTF-8");
|
||||
|
||||
} catch (UnsupportedEncodingException e) {
|
||||
|
||||
e.printStackTrace();
|
||||
|
||||
return null;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
public static byte[] compress(byte[] bytes) {
|
||||
if (bytes == null) {
|
||||
throw new NullPointerException("bytes is null");
|
||||
|
||||
Reference in New Issue
Block a user