From b3e01c3fca313c88a5db4532a8432a6da9259197 Mon Sep 17 00:00:00 2001 From: Victor Shcherb Date: Fri, 22 May 2015 19:05:38 +0300 Subject: [PATCH] Support ziping text --- .../binary/BinaryMapPoiReaderAdapter.java | 29 +++++++++++++++++++ .../src/net/osmand/osm/MapRenderingTypes.java | 14 ++++++--- 2 files changed, 39 insertions(+), 4 deletions(-) diff --git a/OsmAnd-java/src/net/osmand/binary/BinaryMapPoiReaderAdapter.java b/OsmAnd-java/src/net/osmand/binary/BinaryMapPoiReaderAdapter.java index fb16882d3f..fa207898dc 100644 --- a/OsmAnd-java/src/net/osmand/binary/BinaryMapPoiReaderAdapter.java +++ b/OsmAnd-java/src/net/osmand/binary/BinaryMapPoiReaderAdapter.java @@ -5,12 +5,16 @@ import gnu.trove.list.array.TIntArrayList; import gnu.trove.map.hash.TIntLongHashMap; import gnu.trove.set.hash.TLongHashSet; +import java.io.BufferedReader; +import java.io.ByteArrayInputStream; import java.io.IOException; +import java.io.InputStreamReader; import java.util.ArrayList; import java.util.Arrays; import java.util.Comparator; import java.util.LinkedList; import java.util.List; +import java.util.zip.GZIPInputStream; import net.osmand.Collator; import net.osmand.CollatorStringMatcher; @@ -701,6 +705,31 @@ public class BinaryMapPoiReaderAdapter { case OsmandOdb.OsmAndPoiBoxDataAtom.TEXTVALUES_FIELD_NUMBER : String str = codedIS.readString(); if(textTags != null && !textTags.isEmpty()) { + if(str.startsWith(" gz ")) { + int ind = 4; + byte[] bytes = new byte[str.length() - ind]; + for(int i = ind; i < str.length(); i++ ) { + char ch = str.charAt(i) ; + if(ch < 0 || ch >= 256) { + throw new IllegalStateException(); + } + if(ch >= 128) { + bytes[i - ind] = (byte) (ch - 256); + } else if(ch >= 0){ + bytes[i - ind] = (byte) ch; + } + + } + GZIPInputStream gzn = new GZIPInputStream(new ByteArrayInputStream( + bytes)); + BufferedReader br = new BufferedReader(new InputStreamReader(gzn, "UTF-8")); + StringBuilder bld = new StringBuilder(); + String s; + while((s = br.readLine()) != null) { + bld.append(s); + } + str = bld.toString(); + } am.setAdditionalInfo(textTags.poll(), str); } break; diff --git a/OsmAnd-java/src/net/osmand/osm/MapRenderingTypes.java b/OsmAnd-java/src/net/osmand/osm/MapRenderingTypes.java index c6dcda3470..2e39dc4f22 100644 --- a/OsmAnd-java/src/net/osmand/osm/MapRenderingTypes.java +++ b/OsmAnd-java/src/net/osmand/osm/MapRenderingTypes.java @@ -315,7 +315,7 @@ public class MapRenderingTypes { if (name.equals("category")) { //$NON-NLS-1$ parentCategory = parseCategoryFromXml(parser); } else if (name.equals("type")) { - parseTypeFromXML(parser, parentCategory); + parseAndRegisterTypeFromXML(parser, parentCategory); } else if (name.equals("routing_type")) { parseRouteTagFromXML(parser); } else if (name.equals("entity_convert")) { @@ -347,12 +347,17 @@ public class MapRenderingTypes { protected void parseRouteTagFromXML(XmlPullParser parser) { } - protected MapRulType parseTypeFromXML(XmlPullParser parser, MapRulType parentCategory) { - return parseBaseRuleType(parser, parentCategory, true); + protected void parseAndRegisterTypeFromXML(XmlPullParser parser, MapRulType parentCategory) { + parseBaseRuleType(parser, parentCategory, true); } - + protected MapRulType parseBaseRuleType(XmlPullParser parser, MapRulType parentCategory, boolean filterOnlyMap) { String tag = lc(parser.getAttributeValue("", "tag")); + return parseBaseRuleType(parser, parentCategory, filterOnlyMap, tag); + } + + protected MapRulType parseBaseRuleType(XmlPullParser parser, MapRulType parentCategory, boolean filterOnlyMap, + String tag) { String value = lc(parser.getAttributeValue("", "value")); String additional = parser.getAttributeValue("", "additional"); if (value != null && value.length() == 0) { //$NON-NLS-1$ @@ -624,6 +629,7 @@ public class MapRenderingTypes { // creation of only section protected boolean onlyMap; protected boolean onlyPoi; + protected boolean lang; // Needed only for map rules protected int minzoom;