Throw Exception in checkFileIntegrity on failure

DownloadWorker didn't check the string return value which should detect
failed downloads. Throwing (checked) exceptions simplifies error
handling in DownloadWorker.
This commit is contained in:
Manuel Fuhr 2022-04-04 13:09:34 +02:00
parent f0df9f94d4
commit 02eddeff81
3 changed files with 13 additions and 22 deletions

View file

@ -20,7 +20,7 @@ public final class DirectWeaver extends ByteDataWriter
private int size = 0;
public DirectWeaver( StatCoderContext bc, 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 )
{
super( null );
int cellsize = 1000000 / divisor;

View file

@ -35,7 +35,7 @@ final class OsmFile
private int ncaches;
private int indexsize;
public OsmFile( PhysicalFile rafile, int lonDegree, int latDegree, DataBuffers dataBuffers ) throws Exception
public OsmFile( PhysicalFile rafile, int lonDegree, int latDegree, DataBuffers dataBuffers ) throws IOException
{
this.lonDegree = lonDegree;
this.latDegree = latDegree;
@ -111,7 +111,7 @@ final class OsmFile
return idx == -1 ? indexsize : posIdx[idx];
}
public int getDataInputForSubIdx( int subIdx, byte[] iobuffer ) throws Exception
public int getDataInputForSubIdx( int subIdx, byte[] iobuffer ) throws IOException
{
int startPos = getPosIdx( subIdx - 1 );
int endPos = getPosIdx( subIdx );
@ -128,7 +128,7 @@ final class OsmFile
}
public MicroCache createMicroCache( int lonIdx, int latIdx, DataBuffers dataBuffers, TagValueValidator wayValidator,
WaypointMatcher waypointMatcher, boolean reallyDecode, OsmNodesMap hollowNodes ) throws Exception
WaypointMatcher waypointMatcher, boolean reallyDecode, OsmNodesMap hollowNodes ) throws IOException
{
int subIdx = ( latIdx - divisor * latDegree ) * divisor + ( lonIdx - divisor * lonDegree );

View file

@ -31,13 +31,12 @@ final public class PhysicalFile
{
MicroCache.debug = true;
String message = checkFileIntegrity( new File( args[0] ) );
if ( message != null )
{
System.out.println( "************************************" );
System.out.println( message );
System.out.println( "************************************" );
try {
checkFileIntegrity( new File( args[0] ) );
} catch (IOException e) {
System.err.println( "************************************" );
e.printStackTrace();
System.err.println( "************************************" );
}
}
@ -46,7 +45,7 @@ final public class PhysicalFile
*
* @return the error message if file corrupt, else null
*/
public static String checkFileIntegrity( File f )
public static String checkFileIntegrity( File f ) throws IOException
{
PhysicalFile pf = null;
try
@ -66,14 +65,6 @@ final public class PhysicalFile
}
}
}
catch (IllegalArgumentException iae)
{
return iae.getMessage();
}
catch (Exception e)
{
return e.toString();
}
finally
{
if ( pf != null )
@ -88,7 +79,7 @@ final public class PhysicalFile
return null;
}
public PhysicalFile( File f, DataBuffers dataBuffers, int lookupVersion, int lookupMinorVersion ) throws Exception
public PhysicalFile( File f, DataBuffers dataBuffers, int lookupVersion, int lookupMinorVersion ) throws IOException
{
fileName = f.getName();
byte[] iobuffer = dataBuffers.iobuffer;
@ -102,7 +93,7 @@ final public class PhysicalFile
short readVersion = (short)(lv >> 48);
if ( i == 0 && lookupVersion != -1 && readVersion != lookupVersion )
{
throw new IllegalArgumentException( "lookup version mismatch (old rd5?) lookups.dat="
throw new IOException( "lookup version mismatch (old rd5?) lookups.dat="
+ lookupVersion + " " + f. getAbsolutePath() + "=" + readVersion );
}
fileIndex[i] = lv & 0xffffffffffffL;