src/test/java/de/blau/android/osm/XmlTest.java
/**
     * Read an osm file into a Storage object, write the object to OSC and compare hash
     */
Read an osm file into a Storage object, write the object to OSC and compare hash
Read an osm file into a Storage object write the object to OSC and compare hash
@Test
    public void oscWrite() {
        InputStream input = getClass().getResourceAsStream("/test2.osm");
        OsmParser parser = new OsmParser();
        try {
            parser.start(input);
            Storage storage = parser.getStorage();
            assertFalse(storage.isEmpty());
            File file = File.createTempFile("test.osm", ".osc");
            file.deleteOnExit();
            OsmXml.writeOsmChange(storage, new FileOutputStream(file), 123456789L, 10000, "Vespucci Unit Tests");
            try (DigestInputStream hashStream = new DigestInputStream(new FileInputStream(file), MessageDigest.getInstance("SHA-256"))) {
                byte[] buffer = new byte[1024];
                while (hashStream.read(buffer, 0, buffer.length) != -1) {
                }
                String hashValue = Hash.toHex(hashStream.getMessageDigest().digest());
                System.out.println(hashValue);
                assertEquals("f5bb3f1f27b4f7e9061d514d726424bf822691f5645af00731936733e3f8c01f", hashValue);
            } catch (NoSuchAlgorithmException e) {
                fail(e.getMessage());
            }
        } catch (SAXException | IOException | ParserConfigurationException | IllegalArgumentException | IllegalStateException | XmlPullParserException e) {
            fail(e.getMessage());
        }
    }
@ Test public void oscWrite ( ) { InputStream input = getClass ( ) . getResourceAsStream ( "/test2.osm" ) ; OsmParser parser = new OsmParser ( ) ; try { parser . start ( input ) ; Storage storage = parser . getStorage ( ) ; assertFalse ( storage . isEmpty ( ) ) ; File file = File . createTempFile ( "test.osm" , ".osc" ) ; file . deleteOnExit ( ) ; OsmXml . writeOsmChange ( storage , new FileOutputStream ( file ) , 123456789L , 10000 , "Vespucci Unit Tests" ) ; try ( DigestInputStream hashStream = new DigestInputStream ( new FileInputStream ( file ) , MessageDigest . getInstance ( "SHA-256" ) ) ) { byte [ ] buffer = new byte [ 1024 ] ; while ( hashStream . read ( buffer , 0 , buffer . length ) != - 1 ) { } String hashValue = Hash . toHex ( hashStream . getMessageDigest ( ) . digest ( ) ) ; System . out . println ( hashValue ) ; assertEquals ( "f5bb3f1f27b4f7e9061d514d726424bf822691f5645af00731936733e3f8c01f" , hashValue ) ; } catch ( NoSuchAlgorithmException e ) { fail ( e . getMessage ( ) ) ; } } catch ( SAXException | IOException | ParserConfigurationException | IllegalArgumentException | IllegalStateException | XmlPullParserException e ) { fail ( e . getMessage ( ) ) ; } }
Read an osm file into a Storage object, write the object to OSC and compare hash
Read an osm file into a Storage object write the object to OSC and compare hash
// do nothing // Finish hash