corrected lazy crc logic
This commit is contained in:
parent
e4c11e6dbf
commit
0a6ead24a1
5 changed files with 24 additions and 23 deletions
|
|
@ -20,14 +20,12 @@ public final class DirectWeaver extends ByteDataWriter
|
|||
|
||||
private int size = 0;
|
||||
|
||||
public DirectWeaver( DataBuffers dataBuffers, int lonIdx, int latIdx, int divisor, TagValueValidator wayValidator, WaypointMatcher waypointMatcher, OsmNodesMap hollowNodes ) throws Exception
|
||||
public DirectWeaver( StatCoderContext bc, DataBuffers dataBuffers, int lonIdx, int latIdx, int divisor, TagValueValidator wayValidator, WaypointMatcher waypointMatcher, OsmNodesMap hollowNodes ) throws Exception
|
||||
{
|
||||
super( null );
|
||||
int cellsize = 1000000 / divisor;
|
||||
id64Base = ((long)(lonIdx*cellsize))<<32 | (latIdx*cellsize);
|
||||
|
||||
StatCoderContext bc = new StatCoderContext( dataBuffers.iobuffer );
|
||||
|
||||
TagValueCoder wayTagCoder = new TagValueCoder( bc, dataBuffers, wayValidator );
|
||||
TagValueCoder nodeTagCoder = new TagValueCoder( bc, dataBuffers, null );
|
||||
NoisyDiffCoder nodeIdxDiff = new NoisyDiffCoder( bc );
|
||||
|
|
|
|||
|
|
@ -11,6 +11,7 @@ import java.io.RandomAccessFile;
|
|||
import btools.codec.DataBuffers;
|
||||
import btools.codec.MicroCache;
|
||||
import btools.codec.MicroCache2;
|
||||
import btools.codec.StatCoderContext;
|
||||
import btools.codec.TagValueValidator;
|
||||
import btools.codec.WaypointMatcher;
|
||||
import btools.util.ByteDataReader;
|
||||
|
|
@ -142,9 +143,10 @@ final class OsmFile
|
|||
{
|
||||
ab = new byte[asize];
|
||||
asize = getDataInputForSubIdx( subIdx, ab );
|
||||
dataBuffers = new DataBuffers( ab );
|
||||
}
|
||||
|
||||
StatCoderContext bc = new StatCoderContext( ab );
|
||||
|
||||
try
|
||||
{
|
||||
if ( !reallyDecode )
|
||||
|
|
@ -153,25 +155,28 @@ final class OsmFile
|
|||
}
|
||||
if ( hollowNodes == null )
|
||||
{
|
||||
return new MicroCache2( dataBuffers, lonIdx, latIdx, divisor, wayValidator, waypointMatcher );
|
||||
return new MicroCache2( bc, dataBuffers, lonIdx, latIdx, divisor, wayValidator, waypointMatcher );
|
||||
}
|
||||
new DirectWeaver( dataBuffers, lonIdx, latIdx, divisor, wayValidator, waypointMatcher, hollowNodes );
|
||||
new DirectWeaver( bc, dataBuffers, lonIdx, latIdx, divisor, wayValidator, waypointMatcher, hollowNodes );
|
||||
return MicroCache.emptyNonVirgin;
|
||||
}
|
||||
catch( Throwable t )
|
||||
finally
|
||||
{
|
||||
// checksum test now only in case of trouble
|
||||
int crcData = Crc32.crc( ab, 0, asize - 4 );
|
||||
int crcFooter = new ByteDataReader( ab, asize - 4 ).readInt();
|
||||
if ( crcData == crcFooter )
|
||||
// crc check only if the buffer has not been fully read
|
||||
int readBytes = (bc.getReadingBitPosition()+7)>>3;
|
||||
if ( readBytes != asize-4 )
|
||||
{
|
||||
throw new IOException( "old, unsupported data-format" );
|
||||
int crcData = Crc32.crc( ab, 0, asize - 4 );
|
||||
int crcFooter = new ByteDataReader( ab, asize - 4 ).readInt();
|
||||
if ( crcData == crcFooter )
|
||||
{
|
||||
throw new IOException( "old, unsupported data-format" );
|
||||
}
|
||||
else if ( ( crcData ^ 2 ) != crcFooter )
|
||||
{
|
||||
throw new IOException( "checkum error" );
|
||||
}
|
||||
}
|
||||
else if ( ( crcData ^ 2 ) == crcFooter )
|
||||
{
|
||||
throw new IOException( "checkum error" );
|
||||
}
|
||||
throw t instanceof Exception ? (Exception)t : new Exception( t.toString(), t );
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue