make md5sum calculation available everywhere

I want to log sums to see when they arrive on relay. And also add some
missing @Overrides I noticed.
This commit is contained in:
Eric House 2019-02-01 17:01:32 -08:00
parent 236be21a78
commit 9f7899cd7c
4 changed files with 41 additions and 26 deletions

View file

@ -347,9 +347,10 @@ public class CommsTransport implements TransportProcs,
} }
// TransportProcs interface // TransportProcs interface
@Override
public int getFlags() { return COMMS_XPORT_FLAGS_NONE; } public int getFlags() { return COMMS_XPORT_FLAGS_NONE; }
@Override
public int transportSend( byte[] buf, String msgNo, CommsAddrRec addr, public int transportSend( byte[] buf, String msgNo, CommsAddrRec addr,
CommsConnType conType, int gameID ) CommsConnType conType, int gameID )
{ {
@ -386,17 +387,20 @@ public class CommsTransport implements TransportProcs,
return nSent; return nSent;
} }
@Override
public void relayConnd( String room, int devOrder, boolean allHere, public void relayConnd( String room, int devOrder, boolean allHere,
int nMissing ) int nMissing )
{ {
m_tpHandler.tpmRelayConnd( room, devOrder, allHere, nMissing ); m_tpHandler.tpmRelayConnd( room, devOrder, allHere, nMissing );
} }
@Override
public void relayErrorProc( XWRELAY_ERROR relayErr ) public void relayErrorProc( XWRELAY_ERROR relayErr )
{ {
m_tpHandler.tpmRelayErrorProc( relayErr ); m_tpHandler.tpmRelayErrorProc( relayErr );
} }
@Override
public boolean relayNoConnProc( byte[] buf, String msgNo, String relayID ) public boolean relayNoConnProc( byte[] buf, String msgNo, String relayID )
{ {
Assert.fail(); Assert.fail();

View file

@ -84,9 +84,10 @@ public class MultiMsgSink implements TransportProcs {
} }
/***** TransportProcs interface *****/ /***** TransportProcs interface *****/
@Override
public int getFlags() { return COMMS_XPORT_FLAGS_HASNOCONN; } public int getFlags() { return COMMS_XPORT_FLAGS_HASNOCONN; }
@Override
public int transportSend( byte[] buf, String msgNo, CommsAddrRec addr, public int transportSend( byte[] buf, String msgNo, CommsAddrRec addr,
CommsConnType typ, int gameID ) CommsConnType typ, int gameID )
{ {
@ -118,15 +119,18 @@ public class MultiMsgSink implements TransportProcs {
return nSent; return nSent;
} }
@Override
public void relayErrorProc( XWRELAY_ERROR relayErr ) public void relayErrorProc( XWRELAY_ERROR relayErr )
{ {
} }
@Override
public void relayConnd( String room, int devOrder, boolean allHere, public void relayConnd( String room, int devOrder, boolean allHere,
int nMissing ) int nMissing )
{ {
} }
@Override
public boolean relayNoConnProc( byte[] buf, String msgNo, String relayID ) public boolean relayNoConnProc( byte[] buf, String msgNo, String relayID )
{ {
// Assert.fail(); // Assert.fail();

View file

@ -68,13 +68,13 @@ import java.io.InputStreamReader;
import java.io.ObjectInputStream; import java.io.ObjectInputStream;
import java.io.ObjectOutputStream; import java.io.ObjectOutputStream;
import java.io.Serializable; import java.io.Serializable;
import java.security.MessageDigest;
import java.util.Date; import java.util.Date;
import java.util.HashMap; import java.util.HashMap;
import java.util.Iterator; import java.util.Iterator;
import java.util.List; import java.util.List;
import java.util.Random; import java.util.Random;
import org.eehouse.android.xw4.Perms23.Perm; import org.eehouse.android.xw4.Perms23.Perm;
import org.eehouse.android.xw4.jni.CommonPrefs; import org.eehouse.android.xw4.jni.CommonPrefs;
import org.eehouse.android.xw4.loc.LocUtils; import org.eehouse.android.xw4.loc.LocUtils;
@ -359,6 +359,32 @@ public class Utils {
return str; return str;
} }
public static String getMD5SumFor( byte[] bytes )
{
String result = null;
if ( bytes != null ) {
byte[] digest = null;
try {
MessageDigest md = MessageDigest.getInstance("MD5");
byte[] buf = new byte[128];
int nLeft = bytes.length;
int offset = 0;
while ( 0 < nLeft ) {
int len = Math.min( buf.length, nLeft );
System.arraycopy( bytes, offset, buf, 0, len );
md.update( buf, 0, len );
nLeft -= len;
offset += len;
}
digest = md.digest();
} catch ( java.security.NoSuchAlgorithmException nsae ) {
Log.ex( TAG, nsae );
}
result = Utils.digestToString( digest );
}
return result;
}
public static void setChecked( View parent, int id, boolean value ) public static void setChecked( View parent, int id, boolean value )
{ {
CheckBox cbx = (CheckBox)parent.findViewById( id ); CheckBox cbx = (CheckBox)parent.findViewById( id );

View file

@ -30,7 +30,6 @@ import org.eehouse.android.xw4.Utils;
import java.io.ByteArrayInputStream; import java.io.ByteArrayInputStream;
import java.io.InputStreamReader; import java.io.InputStreamReader;
import java.security.MessageDigest;
import java.util.ArrayList; import java.util.ArrayList;
public class JNIUtilsImpl implements JNIUtils { public class JNIUtilsImpl implements JNIUtils {
@ -62,6 +61,7 @@ public class JNIUtilsImpl implements JNIUtils {
* <letter>[<delim><letter]*, so for each loop until the delim * <letter>[<delim><letter]*, so for each loop until the delim
* isn't found. * isn't found.
*/ */
@Override
public String[][] splitFaces( byte[] chars, boolean isUTF8 ) public String[][] splitFaces( byte[] chars, boolean isUTF8 )
{ {
ArrayList<String[]> faces = new ArrayList<String[]>(); ArrayList<String[]> faces = new ArrayList<String[]>();
@ -130,32 +130,13 @@ public class JNIUtilsImpl implements JNIUtils {
faces.add( face.toArray( new String[face.size()] ) ); faces.add( face.toArray( new String[face.size()] ) );
} }
@Override
public String getMD5SumFor( byte[] bytes ) public String getMD5SumFor( byte[] bytes )
{ {
String result = null; return Utils.getMD5SumFor( bytes );
if ( bytes != null ) {
byte[] digest = null;
try {
MessageDigest md = MessageDigest.getInstance("MD5");
byte[] buf = new byte[128];
int nLeft = bytes.length;
int offset = 0;
while ( 0 < nLeft ) {
int len = Math.min( buf.length, nLeft );
System.arraycopy( bytes, offset, buf, 0, len );
md.update( buf, 0, len );
nLeft -= len;
offset += len;
}
digest = md.digest();
} catch ( java.security.NoSuchAlgorithmException nsae ) {
Log.ex( TAG, nsae );
}
result = Utils.digestToString( digest );
}
return result;
} }
@Override
public String getMD5SumFor( String dictName, byte[] bytes ) public String getMD5SumFor( String dictName, byte[] bytes )
{ {
String result = null; String result = null;