Replaces instances of getBytes() in core classes

This commit is contained in:
z3r0fox
2015-12-20 01:18:38 +00:00
parent 0b94d866f0
commit c60f3970d1
26 changed files with 57 additions and 49 deletions

View File

@@ -9,6 +9,8 @@ import java.security.SecureRandom;
import java.text.SimpleDateFormat;
import java.security.NoSuchAlgorithmException;
import net.i2p.data.DataHelper;
/**
* Class for generation and parsing of <a href="http://www.hashcash.org/">HashCash</a><br>
* Copyright 2006 Gregory Rubin <a href="mailto:grrubin@gmail.com">grrubin@gmail.com</a><br>
@@ -61,7 +63,7 @@ public class HashCash implements Comparable<HashCash> {
myExtensions = deserializeExtensions(parts[index++]);
MessageDigest md = MessageDigest.getInstance("SHA1");
md.update(cash.getBytes());
md.update(DataHelper.getUTF8(cash));
byte[] tempBytes = md.digest();
int tempValue = numberOfLeadingZeros(tempBytes);
@@ -190,7 +192,7 @@ public class HashCash implements Comparable<HashCash> {
serializeExtensions(extensions) + ":";
result.myToken = generateCash(prefix, value, md);
md.reset();
md.update(result.myToken.getBytes());
md.update(DataHelper.getUTF8(result.myToken));
result.myValue = numberOfLeadingZeros(md.digest());
break;
@@ -294,7 +296,7 @@ public class HashCash implements Comparable<HashCash> {
counter++;
temp = prefix + Long.toHexString(counter);
md.reset();
md.update(temp.getBytes());
md.update(DataHelper.getUTF8(temp));
bArray = md.digest();
tempValue = numberOfLeadingZeros(bArray);
} while ( tempValue < value);

View File

@@ -10,6 +10,7 @@ import java.io.IOException;
import java.util.Locale;
import net.i2p.I2PAppContext;
import net.i2p.data.DataHelper;
import net.i2p.data.Destination;
/**
@@ -57,7 +58,7 @@ public class EepGetAndAddNamingService extends EepGetNamingService {
try {
fos = new FileOutputStream(f, true);
String line = hostname + '=' + rv.toBase64() + System.getProperty("line.separator");
fos.write(line.getBytes());
fos.write(DataHelper.getASCII(line));
} catch (IOException ioe) {
System.err.println("Error appending: " + ioe);
} finally {

View File

@@ -72,7 +72,7 @@ public class Base32 {
private static void runApp(String args[]) {
String cmd = args[0].toLowerCase(Locale.US);
if ("encodestring".equals(cmd)) {
System.out.println(encode(args[1].getBytes()));
System.out.println(encode(DataHelper.getUTF8(args[1])));
return;
}
InputStream in = System.in;
@@ -143,7 +143,7 @@ public class Base32 {
* @param source if null will return ""
*/
public static String encode(String source) {
return (source != null ? encode(source.getBytes()) : "");
return (source != null ? encode(DataHelper.getUTF8(source)) : "");
}
/**
@@ -210,7 +210,7 @@ public class Base32 {
* @return decoded data, null on error
*/
public static byte[] decode(String s) {
return decode(s.getBytes());
return decode(DataHelper.getASCII(s));
}
private final static byte[] dmask = { (byte) 0xf8, (byte) 0x7c, (byte) 0x3e, (byte) 0x1f,

View File

@@ -385,7 +385,7 @@ public class PrivateKeyFile {
hcs = hcs.substring(0, end1) + hcs.substring(start2);
System.out.println("Short Hashcash is: " + hcs);
c.setPayload(hcs.getBytes());
c.setPayload(DataHelper.getUTF8(hcs));
return c;
}

View File

@@ -114,7 +114,7 @@ public class HexDump {
}
}
out.write(" |".getBytes());
out.write(DataHelper.getASCII(" |"));
for (i = 0; i < FORMAT_BYTES_PER_ROW; ++i) {
if (i >= nextbytes) {