Rd5Diff: Specify IOException instead of generic Exception

This commit is contained in:
Manuel Fuhr 2022-01-11 08:04:03 +01:00
parent 13f5ad0bcf
commit 0a8d4dd1f2
3 changed files with 34 additions and 30 deletions

View file

@ -15,7 +15,7 @@ public final class MicroCache2 extends MicroCache
private int latBase; private int latBase;
private int cellsize; private int cellsize;
public MicroCache2( int size, byte[] databuffer, int lonIdx, int latIdx, int divisor ) throws Exception public MicroCache2( int size, byte[] databuffer, int lonIdx, int latIdx, int divisor )
{ {
super( databuffer ); // sets ab=databuffer, aboffset=0 super( databuffer ); // sets ab=databuffer, aboffset=0
@ -34,7 +34,7 @@ public final class MicroCache2 extends MicroCache
return b; return b;
} }
public MicroCache2( StatCoderContext bc, DataBuffers dataBuffers, int lonIdx, int latIdx, int divisor, TagValueValidator wayValidator, WaypointMatcher waypointMatcher ) throws Exception public MicroCache2( StatCoderContext bc, DataBuffers dataBuffers, int lonIdx, int latIdx, int divisor, TagValueValidator wayValidator, WaypointMatcher waypointMatcher )
{ {
super( null ); super( null );
cellsize = 1000000 / divisor; cellsize = 1000000 / divisor;

View file

@ -8,8 +8,10 @@ package btools.mapaccess;
import java.io.BufferedInputStream; import java.io.BufferedInputStream;
import java.io.File; import java.io.File;
import java.io.FileInputStream; import java.io.FileInputStream;
import java.io.IOException;
import java.security.DigestInputStream; import java.security.DigestInputStream;
import java.security.MessageDigest; import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
final public class Rd5DiffManager final public class Rd5DiffManager
{ {
@ -93,17 +95,16 @@ final public class Rd5DiffManager
} }
} }
public static String getMD5( File f ) throws Exception public static String getMD5( File f ) throws IOException
{ {
try {
MessageDigest md = MessageDigest.getInstance("MD5"); MessageDigest md = MessageDigest.getInstance("MD5");
BufferedInputStream bis = new BufferedInputStream( new FileInputStream( f ) ); BufferedInputStream bis = new BufferedInputStream(new FileInputStream(f));
DigestInputStream dis = new DigestInputStream(bis, md); DigestInputStream dis = new DigestInputStream(bis, md);
byte[] buf = new byte[8192]; byte[] buf = new byte[8192];
for(;;) for (; ; ) {
{ int len = dis.read(buf);
int len = dis.read( buf ); if (len <= 0) {
if ( len <= 0 )
{
break; break;
} }
} }
@ -111,12 +112,14 @@ final public class Rd5DiffManager
byte[] bytes = md.digest(); byte[] bytes = md.digest();
StringBuilder sb = new StringBuilder(); StringBuilder sb = new StringBuilder();
for (int j = 0; j < bytes.length; j++) for (int j = 0; j < bytes.length; j++) {
{
int v = bytes[j] & 0xff; int v = bytes[j] & 0xff;
sb.append( hexChar( v >>> 4 ) ).append( hexChar( v & 0xf ) ); sb.append(hexChar(v >>> 4)).append(hexChar(v & 0xf));
} }
return sb.toString(); return sb.toString();
} catch (NoSuchAlgorithmException e) {
throw new IOException("MD5 algorithm not available", e);
}
} }
private static char hexChar( int v ) private static char hexChar( int v )

View file

@ -12,6 +12,7 @@ import java.io.DataOutputStream;
import java.io.File; import java.io.File;
import java.io.FileInputStream; import java.io.FileInputStream;
import java.io.FileOutputStream; import java.io.FileOutputStream;
import java.io.IOException;
import java.util.Arrays; import java.util.Arrays;
import btools.codec.DataBuffers; import btools.codec.DataBuffers;
@ -60,7 +61,7 @@ final public class Rd5DiffTool implements ProgressListener
return false; return false;
} }
private static long[] readFileIndex( DataInputStream dis, DataOutputStream dos ) throws Exception private static long[] readFileIndex( DataInputStream dis, DataOutputStream dos ) throws IOException
{ {
long[] fileIndex = new long[25]; long[] fileIndex = new long[25];
for( int i=0; i<25; i++ ) for( int i=0; i<25; i++ )
@ -85,7 +86,7 @@ final public class Rd5DiffTool implements ProgressListener
return index[tileIndex]; return index[tileIndex];
} }
private static int[] readPosIndex( DataInputStream dis, DataOutputStream dos ) throws Exception private static int[] readPosIndex( DataInputStream dis, DataOutputStream dos ) throws IOException
{ {
int[] posIndex = new int[1024]; int[] posIndex = new int[1024];
for( int i=0; i<1024; i++ ) for( int i=0; i<1024; i++ )
@ -105,7 +106,7 @@ final public class Rd5DiffTool implements ProgressListener
return idx == -1 ? 4096 : posIdx[idx]; return idx == -1 ? 4096 : posIdx[idx];
} }
private static byte[] createMicroCache( int[] posIdx, int tileIdx, DataInputStream dis, boolean deltaMode ) throws Exception private static byte[] createMicroCache( int[] posIdx, int tileIdx, DataInputStream dis, boolean deltaMode ) throws IOException
{ {
if ( posIdx == null ) if ( posIdx == null )
{ {
@ -125,7 +126,7 @@ final public class Rd5DiffTool implements ProgressListener
return ab; return ab;
} }
private static MicroCache createMicroCache( byte[] ab, DataBuffers dataBuffers ) throws Exception private static MicroCache createMicroCache( byte[] ab, DataBuffers dataBuffers )
{ {
if ( ab == null || ab.length == 0 ) if ( ab == null || ab.length == 0 )
{ {
@ -286,7 +287,7 @@ final public class Rd5DiffTool implements ProgressListener
} }
public static void recoverFromDelta( File f1, File f2, File outFile, ProgressListener progress /* , File cmpFile */ ) throws Exception public static void recoverFromDelta( File f1, File f2, File outFile, ProgressListener progress /* , File cmpFile */ ) throws IOException
{ {
if ( f2.length() == 0L ) if ( f2.length() == 0L )
{ {
@ -468,7 +469,7 @@ final public class Rd5DiffTool implements ProgressListener
} }
} }
public static void copyFile( File f1, File outFile, ProgressListener progress ) throws Exception public static void copyFile( File f1, File outFile, ProgressListener progress ) throws IOException
{ {
boolean canceled = false; boolean canceled = false;
DataInputStream dis1 = new DataInputStream( new BufferedInputStream( new FileInputStream( f1 ) ) ); DataInputStream dis1 = new DataInputStream( new BufferedInputStream( new FileInputStream( f1 ) ) );
@ -756,7 +757,7 @@ final public class Rd5DiffTool implements ProgressListener
this.dataBuffers = dataBuffers; this.dataBuffers = dataBuffers;
} }
public MicroCache readMC() throws Exception public MicroCache readMC() throws IOException
{ {
if (skips < 0 ) if (skips < 0 )
{ {
@ -775,7 +776,7 @@ final public class Rd5DiffTool implements ProgressListener
return mc; return mc;
} }
public void finish() throws Exception public void finish()
{ {
skips = -1; skips = -1;
} }