Search in sources :

Example 11 with TransportIndex

use of net.osmand.binary.BinaryMapTransportReaderAdapter.TransportIndex in project Osmand by osmandapp.

the class BinaryMapIndexReader method init.

private void init() throws IOException {
    boolean initCorrectly = false;
    while (true) {
        int t = codedIS.readTag();
        int tag = WireFormat.getTagFieldNumber(t);
        switch(tag) {
            case 0:
                if (!initCorrectly) {
                    // $NON-NLS-1$
                    throw new IOException("Corrupt file, it should have ended as it starts with version: " + file.getName());
                }
                return;
            case OsmandOdb.OsmAndStructure.VERSION_FIELD_NUMBER:
                version = codedIS.readUInt32();
                break;
            case OsmandOdb.OsmAndStructure.DATECREATED_FIELD_NUMBER:
                dateCreated = codedIS.readInt64();
                break;
            case OsmandOdb.OsmAndStructure.MAPINDEX_FIELD_NUMBER:
                MapIndex mapIndex = new MapIndex();
                mapIndex.length = readInt();
                mapIndex.filePointer = codedIS.getTotalBytesRead();
                int oldLimit = codedIS.pushLimit(mapIndex.length);
                readMapIndex(mapIndex, false);
                basemap = basemap || mapIndex.isBaseMap();
                codedIS.popLimit(oldLimit);
                codedIS.seek(mapIndex.filePointer + mapIndex.length);
                mapIndexes.add(mapIndex);
                indexes.add(mapIndex);
                break;
            case OsmandOdb.OsmAndStructure.ADDRESSINDEX_FIELD_NUMBER:
                AddressRegion region = new AddressRegion();
                region.length = readInt();
                region.filePointer = codedIS.getTotalBytesRead();
                if (addressAdapter != null) {
                    oldLimit = codedIS.pushLimit(region.length);
                    addressAdapter.readAddressIndex(region);
                    if (region.name != null) {
                        addressIndexes.add(region);
                        indexes.add(region);
                    }
                    codedIS.popLimit(oldLimit);
                }
                codedIS.seek(region.filePointer + region.length);
                break;
            case OsmandOdb.OsmAndStructure.TRANSPORTINDEX_FIELD_NUMBER:
                TransportIndex ind = new TransportIndex();
                ind.length = readInt();
                ind.filePointer = codedIS.getTotalBytesRead();
                if (transportAdapter != null) {
                    oldLimit = codedIS.pushLimit(ind.length);
                    transportAdapter.readTransportIndex(ind);
                    codedIS.popLimit(oldLimit);
                    transportIndexes.add(ind);
                    indexes.add(ind);
                }
                codedIS.seek(ind.filePointer + ind.length);
                break;
            case OsmandOdb.OsmAndStructure.ROUTINGINDEX_FIELD_NUMBER:
                RouteRegion routeReg = new RouteRegion();
                routeReg.length = readInt();
                routeReg.filePointer = codedIS.getTotalBytesRead();
                if (routeAdapter != null) {
                    oldLimit = codedIS.pushLimit(routeReg.length);
                    routeAdapter.readRouteIndex(routeReg);
                    codedIS.popLimit(oldLimit);
                    routingIndexes.add(routeReg);
                    indexes.add(routeReg);
                }
                codedIS.seek(routeReg.filePointer + routeReg.length);
                break;
            case OsmandOdb.OsmAndStructure.POIINDEX_FIELD_NUMBER:
                PoiRegion poiInd = new PoiRegion();
                poiInd.length = readInt();
                poiInd.filePointer = codedIS.getTotalBytesRead();
                if (poiAdapter != null) {
                    oldLimit = codedIS.pushLimit(poiInd.length);
                    poiAdapter.readPoiIndex(poiInd, false);
                    codedIS.popLimit(oldLimit);
                    poiIndexes.add(poiInd);
                    indexes.add(poiInd);
                }
                codedIS.seek(poiInd.filePointer + poiInd.length);
                break;
            case OsmandOdb.OsmAndStructure.VERSIONCONFIRM_FIELD_NUMBER:
                int cversion = codedIS.readUInt32();
                calculateCenterPointForRegions();
                initCorrectly = cversion == version;
                break;
            default:
                skipUnknownField(t);
                break;
        }
    }
}
Also used : RouteRegion(net.osmand.binary.BinaryMapRouteReaderAdapter.RouteRegion) IOException(java.io.IOException) AddressRegion(net.osmand.binary.BinaryMapAddressReaderAdapter.AddressRegion) TransportIndex(net.osmand.binary.BinaryMapTransportReaderAdapter.TransportIndex) PoiRegion(net.osmand.binary.BinaryMapPoiReaderAdapter.PoiRegion)

Aggregations

TransportIndex (net.osmand.binary.BinaryMapTransportReaderAdapter.TransportIndex)11 PoiRegion (net.osmand.binary.BinaryMapPoiReaderAdapter.PoiRegion)7 RouteRegion (net.osmand.binary.BinaryMapRouteReaderAdapter.RouteRegion)7 AddressRegion (net.osmand.binary.BinaryMapAddressReaderAdapter.AddressRegion)6 MapIndex (net.osmand.binary.BinaryMapIndexReader.MapIndex)6 MapRoot (net.osmand.binary.BinaryMapIndexReader.MapRoot)5 TIntArrayList (gnu.trove.list.array.TIntArrayList)3 FileOutputStream (java.io.FileOutputStream)3 IOException (java.io.IOException)3 RandomAccessFile (java.io.RandomAccessFile)3 CitiesBlock (net.osmand.binary.BinaryMapAddressReaderAdapter.CitiesBlock)3 CodedOutputStream (com.google.protobuf.CodedOutputStream)2 TLongArrayList (gnu.trove.list.array.TLongArrayList)2 TLongObjectHashMap (gnu.trove.map.hash.TLongObjectHashMap)2 File (java.io.File)2 ArrayList (java.util.ArrayList)2 BinaryIndexPart (net.osmand.binary.BinaryIndexPart)2 BinaryMapIndexReader (net.osmand.binary.BinaryMapIndexReader)2 RouteSubregion (net.osmand.binary.BinaryMapRouteReaderAdapter.RouteSubregion)2 AddressPart (net.osmand.binary.OsmandIndex.AddressPart)2