@Override public boolean loadExisting() { baseGraph.checkInit(); if (properties.loadExisting()) { properties.checkVersions(false); // check encoding for compatiblity String acceptStr = properties.get("graph.flagEncoders"); if (encodingManager == null) { if (acceptStr.isEmpty()) throw new IllegalStateException( "No EncodingManager was configured. And no one was found in the graph: " + dir.getLocation()); int bytesForFlags = 4; if ("8".equals(properties.get("graph.bytesForFlags"))) bytesForFlags = 8; encodingManager = new EncodingManager(acceptStr, bytesForFlags); } else if (!acceptStr.isEmpty() && !encodingManager.toDetailsString().equalsIgnoreCase(acceptStr)) { throw new IllegalStateException( "Encoding does not match:\nGraphhopper config: " + encodingManager.toDetailsString() + "\nGraph: " + acceptStr + ", dir:" + dir.getLocation()); } String byteOrder = properties.get("graph.byteOrder"); if (!byteOrder.equalsIgnoreCase("" + dir.getByteOrder())) throw new IllegalStateException( "Configured graph.byteOrder (" + dir.getByteOrder() + ") is not equal to loaded " + byteOrder + ""); String bytesForFlags = properties.get("graph.bytesForFlags"); if (!bytesForFlags.equalsIgnoreCase("" + encodingManager.getBytesForFlags())) throw new IllegalStateException( "Configured graph.bytesForFlags (" + encodingManager.getBytesForFlags() + ") is not equal to loaded " + bytesForFlags); String dim = properties.get("graph.dimension"); baseGraph.loadExisting(dim); for (CHGraphImpl cg : chGraphs) { if (!cg.loadExisting()) throw new IllegalStateException("Cannot load " + cg); } return true; } return false; }
/** After configuring this storage you need to create it explicitly. */ @Override public GraphHopperStorage create(long byteCount) { baseGraph.checkInit(); if (encodingManager == null) { throw new IllegalStateException("EncodingManager can only be null if you call loadExisting"); } long initSize = Math.max(byteCount, 100); properties.create(100); properties.put("graph.bytesForFlags", encodingManager.getBytesForFlags()); properties.put("graph.flagEncoders", encodingManager.toDetailsString()); properties.put("graph.byteOrder", dir.getByteOrder()); properties.put("graph.dimension", baseGraph.nodeAccess.getDimension()); properties.putCurrentVersions(); baseGraph.create(initSize); for (CHGraphImpl cg : chGraphs) { cg.create(byteCount); } properties.put("graph.chWeightings", getCHWeightings().toString()); return this; }