From c60f3970d1be606bc1c176c9d8a4b0db39f278b4 Mon Sep 17 00:00:00 2001 From: z3r0fox <z3r0fox@mail.i2p> Date: Sun, 20 Dec 2015 01:18:38 +0000 Subject: [PATCH] Replaces instances of getBytes() in core classes --- .../src/com/nettgryppa/security/HashCash.java | 8 +++++--- .../client/naming/EepGetAndAddNamingService.java | 3 ++- core/java/src/net/i2p/data/Base32.java | 6 +++--- core/java/src/net/i2p/data/PrivateKeyFile.java | 2 +- core/java/src/net/i2p/util/HexDump.java | 2 +- .../net/i2p/client/datagram/DatagramTest.java | 8 ++++---- .../net/i2p/client/impl/I2PSessionTest.java | 9 +++++---- .../test/junit/net/i2p/crypto/AES256Bench.java | 2 +- .../junit/net/i2p/crypto/AESInputStream.java | 4 ++-- .../junit/net/i2p/crypto/AESInputStreamTest.java | 4 ++-- .../test/junit/net/i2p/crypto/ElGamalTest.java | 16 ++++++++-------- .../junit/net/i2p/crypto/HMACSHA256Bench.java | 5 +++-- .../test/junit/net/i2p/crypto/SHA256Bench.java | 9 +++++---- .../test/junit/net/i2p/crypto/SHA256Test.java | 3 ++- .../java/test/junit/net/i2p/data/Base64Test.java | 2 +- .../net/i2p/data/DataStructureImplTest.java | 2 +- .../test/junit/net/i2p/data/PayloadTest.java | 2 +- .../test/junit/net/i2p/data/PrivateKeyTest.java | 2 +- .../test/junit/net/i2p/data/PublicKeyTest.java | 2 +- .../net/i2p/data/SigningPrivateKeyTest.java | 2 +- .../junit/net/i2p/data/SigningPublicKeyTest.java | 2 +- core/java/test/junit/net/i2p/stat/RateTest.java | 3 ++- .../i2p/util/ResettableGZIPInputStreamTest.java | 2 +- .../i2p/util/ResettableGZIPOutputStreamTest.java | 2 +- .../i2p/util/ReusableGZIPInputStreamTest.java | 2 +- .../i2p/util/ReusableGZIPOutputStreamTest.java | 2 +- 26 files changed, 57 insertions(+), 49 deletions(-) diff --git a/core/java/src/com/nettgryppa/security/HashCash.java b/core/java/src/com/nettgryppa/security/HashCash.java index 3f3a85f7a5..fccf86ded1 100644 --- a/core/java/src/com/nettgryppa/security/HashCash.java +++ b/core/java/src/com/nettgryppa/security/HashCash.java @@ -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); diff --git a/core/java/src/net/i2p/client/naming/EepGetAndAddNamingService.java b/core/java/src/net/i2p/client/naming/EepGetAndAddNamingService.java index d7ab373560..25a65c5320 100644 --- a/core/java/src/net/i2p/client/naming/EepGetAndAddNamingService.java +++ b/core/java/src/net/i2p/client/naming/EepGetAndAddNamingService.java @@ -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 { diff --git a/core/java/src/net/i2p/data/Base32.java b/core/java/src/net/i2p/data/Base32.java index 8270aa9328..704c79312e 100644 --- a/core/java/src/net/i2p/data/Base32.java +++ b/core/java/src/net/i2p/data/Base32.java @@ -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, diff --git a/core/java/src/net/i2p/data/PrivateKeyFile.java b/core/java/src/net/i2p/data/PrivateKeyFile.java index b77fd13500..7559db7d7d 100644 --- a/core/java/src/net/i2p/data/PrivateKeyFile.java +++ b/core/java/src/net/i2p/data/PrivateKeyFile.java @@ -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; } diff --git a/core/java/src/net/i2p/util/HexDump.java b/core/java/src/net/i2p/util/HexDump.java index 9765f3317b..69adacf7c2 100644 --- a/core/java/src/net/i2p/util/HexDump.java +++ b/core/java/src/net/i2p/util/HexDump.java @@ -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) { diff --git a/core/java/test/junit/net/i2p/client/datagram/DatagramTest.java b/core/java/test/junit/net/i2p/client/datagram/DatagramTest.java index 92a8e0b666..7063113247 100644 --- a/core/java/test/junit/net/i2p/client/datagram/DatagramTest.java +++ b/core/java/test/junit/net/i2p/client/datagram/DatagramTest.java @@ -43,15 +43,15 @@ public class DatagramTest extends TestCase { I2PSession session = client.createSession(new ByteArrayInputStream(out.toByteArray()), null); I2PDatagramMaker dm = new I2PDatagramMaker(session); - byte[] dg = dm.makeI2PDatagram("What's the deal with 42?".getBytes()); + byte[] dg = dm.makeI2PDatagram(DataHelper.getASCII("What's the deal with 42?")); I2PDatagramDissector dd = new I2PDatagramDissector(); dd.loadI2PDatagram(dg); byte[] x = dd.getPayload(); - assertTrue(DataHelper.eq(x, "What's the deal with 42?".getBytes())); + assertTrue(DataHelper.eq(x, DataHelper.getASCII("What's the deal with 42?"))); x = dd.extractPayload(); - assertTrue(DataHelper.eq(x, "What's the deal with 42?".getBytes())); + assertTrue(DataHelper.eq(x, DataHelper.getASCII("What's the deal with 42?"))); assertEquals(d, dd.getSender()); assertEquals(d, dd.extractSender()); @@ -67,7 +67,7 @@ public class DatagramTest extends TestCase { ByteArrayOutputStream dout = new ByteArrayOutputStream(); d.writeBytes(dout); dsaEng.sign(Hash.FAKE_HASH.toByteArray(), session.getPrivateKey()).writeBytes(dout); - dout.write("blah".getBytes()); + dout.write(DataHelper.getASCII("blah")); byte[] data = dout.toByteArray(); I2PDatagramDissector dd = new I2PDatagramDissector(); diff --git a/core/java/test/junit/net/i2p/client/impl/I2PSessionTest.java b/core/java/test/junit/net/i2p/client/impl/I2PSessionTest.java index 14fbab6763..769a4a058c 100644 --- a/core/java/test/junit/net/i2p/client/impl/I2PSessionTest.java +++ b/core/java/test/junit/net/i2p/client/impl/I2PSessionTest.java @@ -19,6 +19,7 @@ import net.i2p.client.I2PClientFactory; import net.i2p.client.I2PSession; import net.i2p.client.I2PSessionException; import net.i2p.client.I2PSessionListener; +import net.i2p.data.DataHelper; import net.i2p.data.Destination; @@ -66,10 +67,10 @@ public class I2PSessionTest extends TestCase implements I2PSessionListener{ _s.add("c"); _s.add("d"); - session.sendMessage(d, "a".getBytes()); - session.sendMessage(d, "b".getBytes()); - session.sendMessage(d, "c".getBytes()); - session.sendMessage(d, "d".getBytes()); + session.sendMessage(d, DataHelper.getASCII("a")); + session.sendMessage(d, DataHelper.getASCII("b")); + session.sendMessage(d, DataHelper.getASCII("c")); + session.sendMessage(d, DataHelper.getASCII("d")); for(int i = 0; (i < 20)&&(!_s.isEmpty()); i++){ Thread.sleep(1000); diff --git a/core/java/test/junit/net/i2p/crypto/AES256Bench.java b/core/java/test/junit/net/i2p/crypto/AES256Bench.java index c5e718d477..59c4a342be 100644 --- a/core/java/test/junit/net/i2p/crypto/AES256Bench.java +++ b/core/java/test/junit/net/i2p/crypto/AES256Bench.java @@ -86,7 +86,7 @@ public class AES256Bench { System.out.println("Standard test D(E(value)) == value? " + same); if (!same) throw new RuntimeException("moo"); - plain = "1234567890123456".getBytes(); + plain = DataHelper.getASCII("1234567890123456"); e = new byte[plain.length]; _context.aes().encrypt(plain, 0, e, 0, key, iv, plain.length); d = new byte[e.length]; diff --git a/core/java/test/junit/net/i2p/crypto/AESInputStream.java b/core/java/test/junit/net/i2p/crypto/AESInputStream.java index 09446b2222..c489cae7cf 100644 --- a/core/java/test/junit/net/i2p/crypto/AESInputStream.java +++ b/core/java/test/junit/net/i2p/crypto/AESInputStream.java @@ -287,9 +287,9 @@ public class AESInputStream extends FilterInputStream { log.setMinimumPriority(Log.DEBUG); byte orig[] = new byte[1024 * 32]; RandomSource.getInstance().nextBytes(orig); - //byte orig[] = "you are my sunshine, my only sunshine".getBytes(); + //byte orig[] = DataHelper.getASCII("you are my sunshine, my only sunshine"); SessionKey key = KeyGenerator.getInstance().generateSessionKey(); - byte iv[] = "there once was a".getBytes(); + byte iv[] = DataHelper.getASCII("there once was a"); for (int i = 0; i < 20; i++) { runTest(ctx, orig, key, iv); diff --git a/core/java/test/junit/net/i2p/crypto/AESInputStreamTest.java b/core/java/test/junit/net/i2p/crypto/AESInputStreamTest.java index 961dad91c4..716aa6ef09 100644 --- a/core/java/test/junit/net/i2p/crypto/AESInputStreamTest.java +++ b/core/java/test/junit/net/i2p/crypto/AESInputStreamTest.java @@ -23,7 +23,7 @@ import net.i2p.util.RandomSource; public class AESInputStreamTest extends TestCase { public void testMultiple() throws Exception{ SessionKey key = KeyGenerator.getInstance().generateSessionKey(); - byte iv[] = "there once was a".getBytes(); + byte iv[] = DataHelper.getASCII("there once was a"); int[] sizes = {1024 * 32, 20, 3, 0}; @@ -70,7 +70,7 @@ public class AESInputStreamTest extends TestCase { RandomSource.getInstance().nextBytes(orig); SessionKey key = KeyGenerator.getInstance().generateSessionKey(); - byte iv[] = "there once was a".getBytes(); + byte iv[] = DataHelper.getASCII("there once was a"); ByteArrayOutputStream origStream = new ByteArrayOutputStream(512); AESOutputStream out = new AESOutputStream(ctx, origStream, key, iv); diff --git a/core/java/test/junit/net/i2p/crypto/ElGamalTest.java b/core/java/test/junit/net/i2p/crypto/ElGamalTest.java index 2bb886338b..46b5da7b6d 100644 --- a/core/java/test/junit/net/i2p/crypto/ElGamalTest.java +++ b/core/java/test/junit/net/i2p/crypto/ElGamalTest.java @@ -136,11 +136,11 @@ public class ElGamalTest extends TestCase{ System.arraycopy(h.getData(), 0, iv, 0, 16); String msg = "Hello world01234012345678901234501234567890123450123456789012345"; - h = SHA256Generator.getInstance().calculateHash(msg.getBytes()); + h = SHA256Generator.getInstance().calculateHash(DataHelper.getASCII(msg)); - byte aesEncr[] = new byte[msg.getBytes().length]; + byte aesEncr[] = new byte[DataHelper.getASCII(msg).length]; byte aesDecr[] = new byte[aesEncr.length]; - _context.aes().encrypt(msg.getBytes(), 0, aesEncr, 0, sessionKey, iv, aesEncr.length); + _context.aes().encrypt(DataHelper.getASCII(msg), 0, aesEncr, 0, sessionKey, iv, aesEncr.length); _context.aes().decrypt(aesEncr, 0, aesDecr, 0, sessionKey, iv, aesEncr.length); h = SHA256Generator.getInstance().calculateHash(aesDecr); @@ -155,7 +155,7 @@ public class ElGamalTest extends TestCase{ String msg = "Hello world"; - byte encrypted[] = _context.elGamalAESEngine().encryptAESBlock(msg.getBytes(), sessionKey, iv, null, null, 64); + byte encrypted[] = _context.elGamalAESEngine().encryptAESBlock(DataHelper.getASCII(msg), sessionKey, iv, null, null, 64); Set<SessionTag> foundTags = new HashSet<SessionTag>(); SessionKey foundKey = new SessionKey(); byte decrypted[] = null; @@ -180,7 +180,7 @@ public class ElGamalTest extends TestCase{ SessionKey key = _context.sessionKeyManager().getCurrentKey(pubKey); if (key == null) key = _context.sessionKeyManager().createSession(pubKey); - byte[] encrypted = _context.elGamalAESEngine().encrypt(msg.getBytes(), pubKey, key, 64); + byte[] encrypted = _context.elGamalAESEngine().encrypt(DataHelper.getASCII(msg), pubKey, key, 64); byte[] decrypted = null; try{ decrypted = _context.elGamalAESEngine().decrypt(encrypted, privKey); @@ -286,7 +286,7 @@ public class ElGamalTest extends TestCase{ PrivateKey priv = (PrivateKey)keypair[1]; for (int i = 0; i < UNENCRYPTED.length; i++) { - byte orig[] = UNENCRYPTED[i].getBytes(); + byte orig[] = DataHelper.getASCII(UNENCRYPTED[i]); byte encrypted[] = _context.elGamalEngine().encrypt(orig, pub); byte decrypted[] = _context.elGamalEngine().decrypt(encrypted, priv); @@ -310,7 +310,7 @@ public class ElGamalTest extends TestCase{ byte enc[] = Base64.decode(ENCRYPTED[i]); byte decrypted[] = _context.elGamalEngine().decrypt(enc, priv); - assertTrue(DataHelper.eq(decrypted, UNENCRYPTED[i].getBytes())); + assertTrue(DataHelper.eq(decrypted, DataHelper.getASCII(UNENCRYPTED[i]))); } } @@ -343,7 +343,7 @@ public class ElGamalTest extends TestCase{ for (int j = 0; j < 5; j++) tags.add(new SessionTag(true)); } - byte encrypted[] = e.encrypt("blah".getBytes(), pubKey, sessionKey, tags, 1024); + byte encrypted[] = e.encrypt(DataHelper.getASCII("blah"), pubKey, sessionKey, tags, 1024); byte decrypted[] = e.decrypt(encrypted, privKey); assertEquals("blah", new String(decrypted)); diff --git a/core/java/test/junit/net/i2p/crypto/HMACSHA256Bench.java b/core/java/test/junit/net/i2p/crypto/HMACSHA256Bench.java index 11981c985a..dd5ff0b9e8 100644 --- a/core/java/test/junit/net/i2p/crypto/HMACSHA256Bench.java +++ b/core/java/test/junit/net/i2p/crypto/HMACSHA256Bench.java @@ -32,6 +32,7 @@ package net.i2p.crypto; import java.util.Properties; import net.i2p.I2PAppContext; +import net.i2p.data.DataHelper; import net.i2p.data.Hash; import net.i2p.data.SessionKey; @@ -74,12 +75,12 @@ public class HMACSHA256Bench { for (int x = 0; x < 2*1024; x++) { buf.append("a"); } - byte[] mmess = buf.toString().getBytes(); // new String("abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq").getBytes(); + byte[] mmess = DataHelper.getASCII(buf.toString()); // new String("abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq").getBytes(); buf = new StringBuilder(); for (int x = 0; x < 10000; x++) { buf.append("a"); } - byte[] lmess = buf.toString().getBytes(); + byte[] lmess = DataHelper.getASCII(buf.toString()); // warm up the engines ctx.hmac().calculate(key, smess); diff --git a/core/java/test/junit/net/i2p/crypto/SHA256Bench.java b/core/java/test/junit/net/i2p/crypto/SHA256Bench.java index 0988fde34f..fc9ccc2211 100644 --- a/core/java/test/junit/net/i2p/crypto/SHA256Bench.java +++ b/core/java/test/junit/net/i2p/crypto/SHA256Bench.java @@ -29,11 +29,12 @@ package net.i2p.crypto; * POSSIBILITY OF SUCH DAMAGE. */ +import net.i2p.data.DataHelper; import net.i2p.data.Hash; public class SHA256Bench { public static void main(String args[]) { - Hash asdfs = SHA256Generator.getInstance().calculateHash("qwerty".getBytes()); + Hash asdfs = SHA256Generator.getInstance().calculateHash(DataHelper.getASCII("qwerty")); int times = 100; long shorttime = 0; @@ -56,17 +57,17 @@ public class SHA256Bench { long minLong1 = 0; long maxLong1 = 0; - byte[] smess = new String("abc").getBytes(); + byte[] smess = DataHelper.getASCII(new String("abc")); StringBuilder buf = new StringBuilder(); for (int x = 0; x < 10*1024; x++) { buf.append("a"); } - byte[] mmess = buf.toString().getBytes(); // new String("abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq").getBytes(); + byte[] mmess = DataHelper.getASCII(buf.toString()); // new String("abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq").getBytes(); buf = new StringBuilder(); for (int x = 0; x < 1000000; x++) { buf.append("a"); } - byte[] lmess = buf.toString().getBytes(); + byte[] lmess = DataHelper.getASCII(buf.toString()); // warm up the engines SHA256Generator.getInstance().calculateHash(smess); diff --git a/core/java/test/junit/net/i2p/crypto/SHA256Test.java b/core/java/test/junit/net/i2p/crypto/SHA256Test.java index fd612b5d0f..3dc78b078c 100644 --- a/core/java/test/junit/net/i2p/crypto/SHA256Test.java +++ b/core/java/test/junit/net/i2p/crypto/SHA256Test.java @@ -10,6 +10,7 @@ package net.i2p.crypto; import junit.framework.TestCase; import net.i2p.I2PAppContext; +import net.i2p.data.DataHelper; import net.i2p.data.Hash; /** * @author Comwiz @@ -36,7 +37,7 @@ public class SHA256Test extends TestCase{ * Check if the behaviour remains the same. */ public void testMultipleEquality(){ - byte[] data = "blahblah".getBytes(); + byte[] data = DataHelper.getASCII("blahblah"); Hash firstHash = SHA256Generator.getInstance().calculateHash(data); diff --git a/core/java/test/junit/net/i2p/data/Base64Test.java b/core/java/test/junit/net/i2p/data/Base64Test.java index fc7dbea215..b8c57db00d 100644 --- a/core/java/test/junit/net/i2p/data/Base64Test.java +++ b/core/java/test/junit/net/i2p/data/Base64Test.java @@ -13,7 +13,7 @@ import junit.framework.TestCase; public class Base64Test extends TestCase{ public void testBase64(){ String orig = "you smell"; - String encoded = Base64.encode(orig.getBytes()); + String encoded = Base64.encode(DataHelper.getASCII(orig)); byte decoded[] = Base64.decode(encoded); String transformed = new String(decoded); assertTrue(orig.equals(transformed)); diff --git a/core/java/test/junit/net/i2p/data/DataStructureImplTest.java b/core/java/test/junit/net/i2p/data/DataStructureImplTest.java index f0d30f5eef..b03cac488a 100644 --- a/core/java/test/junit/net/i2p/data/DataStructureImplTest.java +++ b/core/java/test/junit/net/i2p/data/DataStructureImplTest.java @@ -60,7 +60,7 @@ public class DataStructureImplTest extends TestCase{ public void testErrors() throws Exception{ boolean error = false; try{ - _struct.fromByteArray("water is poison".getBytes()); + _struct.fromByteArray(DataHelper.getASCII("water is poison")); }catch(DataFormatException dfe){ error = true; } diff --git a/core/java/test/junit/net/i2p/data/PayloadTest.java b/core/java/test/junit/net/i2p/data/PayloadTest.java index 143c794b3b..074f4691d9 100644 --- a/core/java/test/junit/net/i2p/data/PayloadTest.java +++ b/core/java/test/junit/net/i2p/data/PayloadTest.java @@ -20,7 +20,7 @@ package net.i2p.data; Payload payload = new Payload(); SessionKey key = (SessionKey)(new SessionKeyTest()).createDataStructure(); - byte data[] = "Hello, I2P".getBytes(); + byte data[] = DataHelper.getASCII("Hello, I2P"); // This causes equals() to fail unless we override the test // to set the unencrypted data after reading. // Unencrypted data is deprecated, just use encrypted data for the test. diff --git a/core/java/test/junit/net/i2p/data/PrivateKeyTest.java b/core/java/test/junit/net/i2p/data/PrivateKeyTest.java index 9d25fb449a..f2581b3d1a 100644 --- a/core/java/test/junit/net/i2p/data/PrivateKeyTest.java +++ b/core/java/test/junit/net/i2p/data/PrivateKeyTest.java @@ -81,7 +81,7 @@ public class PrivateKeyTest extends StructureTest { public void testShortRead() throws Exception{ PrivateKey privateKey = new PrivateKey(); - ByteArrayInputStream in = new ByteArrayInputStream("six times nine equals forty-two".getBytes()); + ByteArrayInputStream in = new ByteArrayInputStream(DataHelper.getASCII("six times nine equals forty-two")); boolean error = false; try{ privateKey.readBytes(in); diff --git a/core/java/test/junit/net/i2p/data/PublicKeyTest.java b/core/java/test/junit/net/i2p/data/PublicKeyTest.java index 8fed332bd5..4e404a9555 100644 --- a/core/java/test/junit/net/i2p/data/PublicKeyTest.java +++ b/core/java/test/junit/net/i2p/data/PublicKeyTest.java @@ -81,7 +81,7 @@ public class PublicKeyTest extends StructureTest { public void testShortRead() throws Exception{ PublicKey publicKey = new PublicKey(); - ByteArrayInputStream in = new ByteArrayInputStream("six times nine equals forty-two".getBytes()); + ByteArrayInputStream in = new ByteArrayInputStream(DataHelper.getASCII("six times nine equals forty-two")); boolean error = false; try{ publicKey.readBytes(in); diff --git a/core/java/test/junit/net/i2p/data/SigningPrivateKeyTest.java b/core/java/test/junit/net/i2p/data/SigningPrivateKeyTest.java index baa038812d..4ccfc10c93 100644 --- a/core/java/test/junit/net/i2p/data/SigningPrivateKeyTest.java +++ b/core/java/test/junit/net/i2p/data/SigningPrivateKeyTest.java @@ -81,7 +81,7 @@ public class SigningPrivateKeyTest extends StructureTest { public void testShortRead() throws Exception{ SigningPrivateKey signingPrivateKey = new SigningPrivateKey(); - ByteArrayInputStream in = new ByteArrayInputStream("short".getBytes()); + ByteArrayInputStream in = new ByteArrayInputStream(DataHelper.getASCII("short")); boolean error = false; try{ signingPrivateKey.readBytes(in); diff --git a/core/java/test/junit/net/i2p/data/SigningPublicKeyTest.java b/core/java/test/junit/net/i2p/data/SigningPublicKeyTest.java index b97099e6e2..1e5718b42a 100644 --- a/core/java/test/junit/net/i2p/data/SigningPublicKeyTest.java +++ b/core/java/test/junit/net/i2p/data/SigningPublicKeyTest.java @@ -82,7 +82,7 @@ public class SigningPublicKeyTest extends StructureTest { public void testShortRead() throws Exception{ SigningPublicKey publicKey = new SigningPublicKey(); - ByteArrayInputStream in = new ByteArrayInputStream("six times nine equals forty-two".getBytes()); + ByteArrayInputStream in = new ByteArrayInputStream(DataHelper.getASCII("six times nine equals forty-two")); boolean error = false; try{ publicKey.readBytes(in); diff --git a/core/java/test/junit/net/i2p/stat/RateTest.java b/core/java/test/junit/net/i2p/stat/RateTest.java index 45d9278a81..2fbca7eb41 100644 --- a/core/java/test/junit/net/i2p/stat/RateTest.java +++ b/core/java/test/junit/net/i2p/stat/RateTest.java @@ -2,6 +2,7 @@ package net.i2p.stat; import java.io.ByteArrayInputStream; import java.util.Properties; +import net.i2p.data.DataHelper; import org.junit.Test; @@ -21,7 +22,7 @@ public class RateTest extends TestCase { StringBuilder buf = new StringBuilder(1024); rate.store("rate.test", buf); - byte data[] = buf.toString().getBytes(); + byte data[] = DataHelper.getUTF8(buf.toString()); Properties props = new Properties(); props.load(new ByteArrayInputStream(data)); diff --git a/core/java/test/junit/net/i2p/util/ResettableGZIPInputStreamTest.java b/core/java/test/junit/net/i2p/util/ResettableGZIPInputStreamTest.java index d78166654f..d4ea56708b 100644 --- a/core/java/test/junit/net/i2p/util/ResettableGZIPInputStreamTest.java +++ b/core/java/test/junit/net/i2p/util/ResettableGZIPInputStreamTest.java @@ -45,7 +45,7 @@ public class ResettableGZIPInputStreamTest extends TestCase { } - byte orig[] = "ho ho ho, merry christmas".getBytes(); + byte orig[] = DataHelper.getASCII("ho ho ho, merry christmas"); ByteArrayOutputStream baos = new ByteArrayOutputStream(64); GZIPOutputStream o = new GZIPOutputStream(baos); o.write(orig); diff --git a/core/java/test/junit/net/i2p/util/ResettableGZIPOutputStreamTest.java b/core/java/test/junit/net/i2p/util/ResettableGZIPOutputStreamTest.java index 58c2dd9ee3..37cad3f3e8 100644 --- a/core/java/test/junit/net/i2p/util/ResettableGZIPOutputStreamTest.java +++ b/core/java/test/junit/net/i2p/util/ResettableGZIPOutputStreamTest.java @@ -18,7 +18,7 @@ import net.i2p.data.DataHelper; public class ResettableGZIPOutputStreamTest extends TestCase { public void testResettableGZIPOutputStream() throws Exception{ - byte b[] = "hi, how are you today?".getBytes(); + byte b[] = DataHelper.getASCII("hi, how are you today?"); ByteArrayOutputStream baos = new ByteArrayOutputStream(); ResettableGZIPOutputStream o = new ResettableGZIPOutputStream(baos); o.write(b); diff --git a/core/java/test/junit/net/i2p/util/ReusableGZIPInputStreamTest.java b/core/java/test/junit/net/i2p/util/ReusableGZIPInputStreamTest.java index 7f10a25fa3..ec3ad7a483 100644 --- a/core/java/test/junit/net/i2p/util/ReusableGZIPInputStreamTest.java +++ b/core/java/test/junit/net/i2p/util/ReusableGZIPInputStreamTest.java @@ -20,7 +20,7 @@ import net.i2p.data.DataHelper; public class ReusableGZIPInputStreamTest extends TestCase { public void testReusableGZIPInputStream() throws Exception{ { - byte b[] = "hi, how are you today?".getBytes(); + byte b[] = DataHelper.getASCII("hi, how are you today?"); ByteArrayOutputStream baos = new ByteArrayOutputStream(64); GZIPOutputStream o = new GZIPOutputStream(baos); o.write(b); diff --git a/core/java/test/junit/net/i2p/util/ReusableGZIPOutputStreamTest.java b/core/java/test/junit/net/i2p/util/ReusableGZIPOutputStreamTest.java index b48d267fe5..537108e138 100644 --- a/core/java/test/junit/net/i2p/util/ReusableGZIPOutputStreamTest.java +++ b/core/java/test/junit/net/i2p/util/ReusableGZIPOutputStreamTest.java @@ -19,7 +19,7 @@ import net.i2p.data.DataHelper; public class ReusableGZIPOutputStreamTest extends TestCase { public void testReusableGZIPOutputStream() throws Exception{ { - byte b[] = "hi, how are you today?".getBytes(); + byte b[] = DataHelper.getASCII("hi, how are you today?"); ReusableGZIPOutputStream o = ReusableGZIPOutputStream.acquire(); o.write(b); o.finish(); -- GitLab