/** * Create the EncodingManager from the provided GraphHopper location. Throws an * IllegalStateException if it fails. Used if no EncodingManager specified on load. */ public static EncodingManager create(FlagEncoderFactory factory, String ghLoc) { Directory dir = new RAMDirectory(ghLoc, true); StorableProperties properties = new StorableProperties(dir); if (!properties.loadExisting()) throw new IllegalStateException("Cannot load properties to fetch EncodingManager configuration at: " + dir.getLocation()); // check encoding for compatibility properties.checkVersions(false); String acceptStr = properties.get("graph.flag_encoders"); if (acceptStr.isEmpty()) throw new IllegalStateException("EncodingManager was not configured. And no one was found in the graph: " + dir.getLocation()); int bytesForFlags = 4; if ("8".equals(properties.get("graph.bytes_for_flags"))) bytesForFlags = 8; return new EncodingManager(factory, acceptStr, bytesForFlags); }
@Override public boolean loadExisting() { baseGraph.checkInit(); if (properties.loadExisting()) { properties.checkVersions(false); // check encoding for compatibility String flagEncodersStr = properties.get("graph.flag_encoders"); if (!flagEncodersStr.isEmpty() && !encodingManager.toDetailsString().equalsIgnoreCase(flagEncodersStr)) { throw new IllegalStateException("Encoding does not match:" + "\nGraphhopper config: " + encodingManager.toDetailsString() + "\nGraph: " + flagEncodersStr + "\nChange configuration to match the graph or delete " + dir.getLocation()); } String byteOrder = properties.get("graph.byte_order"); if (!byteOrder.equalsIgnoreCase("" + dir.getByteOrder())) throw new IllegalStateException("Configured graph.byte_order (" + dir.getByteOrder() + ") is not equal to loaded " + byteOrder + ""); String bytesForFlags = properties.get("graph.bytes_for_flags"); if (!bytesForFlags.equalsIgnoreCase("" + encodingManager.getBytesForFlags())) throw new IllegalStateException("Configured graph.bytes_for_flags (" + encodingManager.getBytesForFlags() + ") is not equal to loaded " + bytesForFlags); String dim = properties.get("graph.dimension"); baseGraph.loadExisting(dim); checkIfConfiguredAndLoadedWeightingsCompatible(); for (CHGraphImpl cg : chGraphs) { if (!cg.loadExisting()) throw new IllegalStateException("Cannot load " + cg); } return true; } return false; }
@Test public void testLoad() { StorableProperties instance = new StorableProperties(createDir("", false)); // an in-memory storage does not load anything assertFalse(instance.loadExisting()); instance = new StorableProperties(createDir("", true)); assertFalse(instance.loadExisting()); instance.close(); }
@Test public void testStore() { String dir = "./target/test"; Helper.removeDir(new File(dir)); StorableProperties instance = new StorableProperties(createDir(dir, true)); instance.create(1000); instance.put("test.min", 123); instance.put("test.max", 321); instance.flush(); instance.close(); instance = new StorableProperties(createDir(dir, true)); assertTrue(instance.loadExisting()); assertEquals("123", instance.get("test.min")); assertEquals("321", instance.get("test.max")); instance.close(); Helper.removeDir(new File(dir)); }
/** * Create the EncodingManager from the provided GraphHopper location. Throws an * IllegalStateException if it fails. Used if no EncodingManager specified on load. */ public static EncodingManager create(FlagEncoderFactory factory, String ghLoc) { Directory dir = new RAMDirectory(ghLoc, true); StorableProperties properties = new StorableProperties(dir); if (!properties.loadExisting()) throw new IllegalStateException("Cannot load properties to fetch EncodingManager configuration at: " + dir.getLocation()); // check encoding for compatibility properties.checkVersions(false); String acceptStr = properties.get("graph.flag_encoders"); if (acceptStr.isEmpty()) throw new IllegalStateException("EncodingManager was not configured. And no one was found in the graph: " + dir.getLocation()); int bytesForFlags = 4; if ("8".equals(properties.get("graph.bytes_for_flags"))) bytesForFlags = 8; return new EncodingManager(factory, acceptStr, bytesForFlags); }
/** * Create the EncodingManager from the provided GraphHopper location. Throws an * IllegalStateException if it fails. Used if no EncodingManager specified on load. */ public static EncodingManager create(FlagEncoderFactory factory, String ghLoc) { Directory dir = new RAMDirectory(ghLoc, true); StorableProperties properties = new StorableProperties(dir); if (!properties.loadExisting()) throw new IllegalStateException("Cannot load properties to fetch EncodingManager configuration at: " + dir.getLocation()); // check encoding for compatibility properties.checkVersions(false); String acceptStr = properties.get("graph.flag_encoders"); if (acceptStr.isEmpty()) throw new IllegalStateException("EncodingManager was not configured. And no one was found in the graph: " + dir.getLocation()); int bytesForFlags = 4; if ("8".equals(properties.get("graph.bytes_for_flags"))) bytesForFlags = 8; return new EncodingManager(factory, acceptStr, bytesForFlags); }
/** * Create the EncodingManager from the provided GraphHopper location. Throws an * IllegalStateException if it fails. Used if no EncodingManager specified on load. */ public static EncodingManager create( FlagEncoderFactory factory, String ghLoc ) { Directory dir = new RAMDirectory(ghLoc, true); StorableProperties properties = new StorableProperties(dir); if (!properties.loadExisting()) throw new IllegalStateException("Cannot load properties to fetch EncodingManager configuration at: " + dir.getLocation()); // check encoding for compatibility properties.checkVersions(false); String acceptStr = properties.get("graph.flag_encoders"); if (acceptStr.isEmpty()) throw new IllegalStateException("EncodingManager was not configured. And no one was found in the graph: " + dir.getLocation()); int bytesForFlags = 4; if ("8".equals(properties.get("graph.bytes_for_flags"))) bytesForFlags = 8; return new EncodingManager(factory, acceptStr, bytesForFlags); } }
Directory dir = new RAMDirectory(directory, true); StorableProperties properties = new StorableProperties(dir); if (!properties.loadExisting()) { properties.close(); throw new RuntimeException("Cannot find properties file");
@Override public boolean loadExisting() { baseGraph.checkInit(); if (properties.loadExisting()) { properties.checkVersions(false);
if (properties.loadExisting())
@Override public boolean loadExisting() { baseGraph.checkInit(); if (properties.loadExisting()) { properties.checkVersions(false); // check encoding for compatibility String flagEncodersStr = properties.get("graph.flag_encoders"); if (!flagEncodersStr.isEmpty() && !encodingManager.toDetailsString().equalsIgnoreCase(flagEncodersStr)) { throw new IllegalStateException("Encoding does not match:" + "\nGraphhopper config: " + encodingManager.toDetailsString() + "\nGraph: " + flagEncodersStr + "\nChange configuration to match the graph or delete " + dir.getLocation()); } String byteOrder = properties.get("graph.byte_order"); if (!byteOrder.equalsIgnoreCase("" + dir.getByteOrder())) throw new IllegalStateException("Configured graph.byte_order (" + dir.getByteOrder() + ") is not equal to loaded " + byteOrder + ""); String bytesForFlags = properties.get("graph.bytes_for_flags"); if (!bytesForFlags.equalsIgnoreCase("" + encodingManager.getBytesForFlags())) throw new IllegalStateException("Configured graph.bytes_for_flags (" + encodingManager.getBytesForFlags() + ") is not equal to loaded " + bytesForFlags); String dim = properties.get("graph.dimension"); baseGraph.loadExisting(dim); checkIfConfiguredAndLoadedWeightingsCompatible(); for (CHGraphImpl cg : chGraphs) { if (!cg.loadExisting()) throw new IllegalStateException("Cannot load " + cg); } return true; } return false; }