3
0
mirror of https://github.com/Qortal/altcoinj.git synced 2025-02-13 02:35:52 +00:00

Migrate from Guava Charsets to Java7 StandardCharsets constants.

This commit is contained in:
Andreas Schildbach 2018-03-09 17:05:09 +01:00
parent faf58ac9a2
commit 5b008f90e0
16 changed files with 44 additions and 47 deletions

View File

@ -20,12 +20,11 @@ package org.bitcoinj.core;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import com.google.common.base.Charsets;
import java.io.IOException; import java.io.IOException;
import java.io.OutputStream; import java.io.OutputStream;
import java.nio.BufferUnderflowException; import java.nio.BufferUnderflowException;
import java.nio.ByteBuffer; import java.nio.ByteBuffer;
import java.nio.charset.StandardCharsets;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
@ -366,7 +365,7 @@ public class BitcoinSerializer extends MessageSerializer {
for (; header[cursor] != 0 && cursor < COMMAND_LEN; cursor++) ; for (; header[cursor] != 0 && cursor < COMMAND_LEN; cursor++) ;
byte[] commandBytes = new byte[cursor]; byte[] commandBytes = new byte[cursor];
System.arraycopy(header, 0, commandBytes, 0, cursor); System.arraycopy(header, 0, commandBytes, 0, cursor);
command = new String(commandBytes, Charsets.US_ASCII); command = new String(commandBytes, StandardCharsets.US_ASCII);
cursor = COMMAND_LEN; cursor = COMMAND_LEN;
size = (int) readUint32(header, cursor); size = (int) readUint32(header, cursor);

View File

@ -19,7 +19,6 @@ package org.bitcoinj.core;
import org.bitcoinj.store.BlockStore; import org.bitcoinj.store.BlockStore;
import org.bitcoinj.store.BlockStoreException; import org.bitcoinj.store.BlockStoreException;
import org.bitcoinj.store.FullPrunedBlockStore; import org.bitcoinj.store.FullPrunedBlockStore;
import com.google.common.base.Charsets;
import com.google.common.hash.HashCode; import com.google.common.hash.HashCode;
import com.google.common.hash.Hasher; import com.google.common.hash.Hasher;
import com.google.common.hash.Hashing; import com.google.common.hash.Hashing;
@ -37,6 +36,7 @@ import java.io.InputStream;
import java.io.InputStreamReader; import java.io.InputStreamReader;
import java.nio.ByteBuffer; import java.nio.ByteBuffer;
import java.nio.ByteOrder; import java.nio.ByteOrder;
import java.nio.charset.StandardCharsets;
import java.security.DigestInputStream; import java.security.DigestInputStream;
import java.security.MessageDigest; import java.security.MessageDigest;
import java.util.Arrays; import java.util.Arrays;
@ -155,7 +155,7 @@ public class CheckpointManager {
Hasher hasher = Hashing.sha256().newHasher(); Hasher hasher = Hashing.sha256().newHasher();
BufferedReader reader = null; BufferedReader reader = null;
try { try {
reader = new BufferedReader(new InputStreamReader(inputStream, Charsets.US_ASCII)); reader = new BufferedReader(new InputStreamReader(inputStream, StandardCharsets.US_ASCII));
String magic = reader.readLine(); String magic = reader.readLine();
if (!TEXTUAL_MAGIC.equals(magic)) if (!TEXTUAL_MAGIC.equals(magic))
throw new IOException("unexpected magic: " + magic); throw new IOException("unexpected magic: " + magic);

View File

@ -20,7 +20,6 @@ package org.bitcoinj.core;
import org.bitcoinj.crypto.*; import org.bitcoinj.crypto.*;
import com.google.common.annotations.VisibleForTesting; import com.google.common.annotations.VisibleForTesting;
import com.google.common.base.Charsets;
import com.google.common.base.MoreObjects; import com.google.common.base.MoreObjects;
import com.google.common.base.Objects; import com.google.common.base.Objects;
import com.google.common.base.Preconditions; import com.google.common.base.Preconditions;
@ -54,6 +53,7 @@ import javax.annotation.Nullable;
import java.io.ByteArrayOutputStream; import java.io.ByteArrayOutputStream;
import java.io.IOException; import java.io.IOException;
import java.math.BigInteger; import java.math.BigInteger;
import java.nio.charset.StandardCharsets;
import java.security.SecureRandom; import java.security.SecureRandom;
import java.security.SignatureException; import java.security.SignatureException;
import java.util.Arrays; import java.util.Arrays;
@ -881,7 +881,7 @@ public class ECKey implements EncryptableItem {
sigData[0] = (byte)headerByte; sigData[0] = (byte)headerByte;
System.arraycopy(Utils.bigIntegerToBytes(sig.r, 32), 0, sigData, 1, 32); System.arraycopy(Utils.bigIntegerToBytes(sig.r, 32), 0, sigData, 1, 32);
System.arraycopy(Utils.bigIntegerToBytes(sig.s, 32), 0, sigData, 33, 32); System.arraycopy(Utils.bigIntegerToBytes(sig.s, 32), 0, sigData, 33, 32);
return new String(Base64.encode(sigData), Charsets.UTF_8); return new String(Base64.encode(sigData), StandardCharsets.UTF_8);
} }
/** /**
@ -1290,7 +1290,7 @@ public class ECKey implements EncryptableItem {
/** The string that prefixes all text messages signed using Bitcoin keys. */ /** The string that prefixes all text messages signed using Bitcoin keys. */
private static final String BITCOIN_SIGNED_MESSAGE_HEADER = "Bitcoin Signed Message:\n"; private static final String BITCOIN_SIGNED_MESSAGE_HEADER = "Bitcoin Signed Message:\n";
private static final byte[] BITCOIN_SIGNED_MESSAGE_HEADER_BYTES = BITCOIN_SIGNED_MESSAGE_HEADER.getBytes(Charsets.UTF_8); private static final byte[] BITCOIN_SIGNED_MESSAGE_HEADER_BYTES = BITCOIN_SIGNED_MESSAGE_HEADER.getBytes(StandardCharsets.UTF_8);
/** /**
* <p>Given a textual message, returns a byte buffer formatted as follows:</p> * <p>Given a textual message, returns a byte buffer formatted as follows:</p>
@ -1301,7 +1301,7 @@ public class ECKey implements EncryptableItem {
ByteArrayOutputStream bos = new ByteArrayOutputStream(); ByteArrayOutputStream bos = new ByteArrayOutputStream();
bos.write(BITCOIN_SIGNED_MESSAGE_HEADER_BYTES.length); bos.write(BITCOIN_SIGNED_MESSAGE_HEADER_BYTES.length);
bos.write(BITCOIN_SIGNED_MESSAGE_HEADER_BYTES); bos.write(BITCOIN_SIGNED_MESSAGE_HEADER_BYTES);
byte[] messageBytes = message.getBytes(Charsets.UTF_8); byte[] messageBytes = message.getBytes(StandardCharsets.UTF_8);
VarInt size = new VarInt(messageBytes.length); VarInt size = new VarInt(messageBytes.length);
bos.write(size.encode()); bos.write(size.encode());
bos.write(messageBytes); bos.write(messageBytes);

View File

@ -20,10 +20,9 @@ package org.bitcoinj.core;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import com.google.common.base.Charsets;
import java.io.*; import java.io.*;
import java.math.BigInteger; import java.math.BigInteger;
import java.nio.charset.StandardCharsets;
import java.util.Arrays; import java.util.Arrays;
import static com.google.common.base.Preconditions.checkState; import static com.google.common.base.Preconditions.checkState;
@ -349,7 +348,7 @@ public abstract class Message {
protected String readStr() throws ProtocolException { protected String readStr() throws ProtocolException {
long length = readVarInt(); long length = readVarInt();
return length == 0 ? "" : new String(readBytes((int) length), Charsets.UTF_8); // optimization for empty strings return length == 0 ? "" : new String(readBytes((int) length), StandardCharsets.UTF_8); // optimization for empty strings
} }
protected Sha256Hash readHash() throws ProtocolException { protected Sha256Hash readHash() throws ProtocolException {

View File

@ -17,10 +17,10 @@
package org.bitcoinj.core; package org.bitcoinj.core;
import com.google.common.base.Charsets;
import com.google.common.base.Objects; import com.google.common.base.Objects;
import java.io.IOException; import java.io.IOException;
import java.io.OutputStream; import java.io.OutputStream;
import java.nio.charset.StandardCharsets;
import java.util.Locale; import java.util.Locale;
/** /**
@ -98,11 +98,11 @@ public class RejectMessage extends Message {
@Override @Override
public void bitcoinSerializeToStream(OutputStream stream) throws IOException { public void bitcoinSerializeToStream(OutputStream stream) throws IOException {
byte[] messageBytes = message.getBytes(Charsets.UTF_8); byte[] messageBytes = message.getBytes(StandardCharsets.UTF_8);
stream.write(new VarInt(messageBytes.length).encode()); stream.write(new VarInt(messageBytes.length).encode());
stream.write(messageBytes); stream.write(messageBytes);
stream.write(code.code); stream.write(code.code);
byte[] reasonBytes = reason.getBytes(Charsets.UTF_8); byte[] reasonBytes = reason.getBytes(StandardCharsets.UTF_8);
stream.write(new VarInt(reasonBytes.length).encode()); stream.write(new VarInt(reasonBytes.length).encode());
stream.write(reasonBytes); stream.write(reasonBytes);
if ("block".equals(message) || "tx".equals(message)) if ("block".equals(message) || "tx".equals(message))

View File

@ -16,7 +16,6 @@
package org.bitcoinj.core; package org.bitcoinj.core;
import com.google.common.base.Charsets;
import com.google.common.base.Objects; import com.google.common.base.Objects;
import com.google.common.net.InetAddresses; import com.google.common.net.InetAddresses;
@ -26,6 +25,7 @@ import java.io.OutputStream;
import java.math.BigInteger; import java.math.BigInteger;
import java.net.InetAddress; import java.net.InetAddress;
import java.net.UnknownHostException; import java.net.UnknownHostException;
import java.nio.charset.StandardCharsets;
import java.util.Locale; import java.util.Locale;
/** /**
@ -175,7 +175,7 @@ public class VersionMessage extends Message {
Utils.uint32ToByteStreamLE(0, buf); Utils.uint32ToByteStreamLE(0, buf);
Utils.uint32ToByteStreamLE(0, buf); Utils.uint32ToByteStreamLE(0, buf);
// Now comes subVer. // Now comes subVer.
byte[] subVerBytes = subVer.getBytes(Charsets.UTF_8); byte[] subVerBytes = subVer.getBytes(StandardCharsets.UTF_8);
buf.write(new VarInt(subVerBytes.length).encode()); buf.write(new VarInt(subVerBytes.length).encode());
buf.write(subVerBytes); buf.write(subVerBytes);
// Size of known block chain. // Size of known block chain.

View File

@ -17,7 +17,6 @@
package org.bitcoinj.crypto; package org.bitcoinj.crypto;
import org.bitcoinj.core.*; import org.bitcoinj.core.*;
import com.google.common.base.Charsets;
import com.google.common.primitives.Bytes; import com.google.common.primitives.Bytes;
import com.lambdaworks.crypto.SCrypt; import com.lambdaworks.crypto.SCrypt;
@ -25,6 +24,7 @@ import javax.crypto.Cipher;
import javax.crypto.spec.SecretKeySpec; import javax.crypto.spec.SecretKeySpec;
import java.math.BigInteger; import java.math.BigInteger;
import java.nio.charset.StandardCharsets;
import java.security.GeneralSecurityException; import java.security.GeneralSecurityException;
import java.text.Normalizer; import java.text.Normalizer;
import java.util.Arrays; import java.util.Arrays;
@ -117,7 +117,7 @@ public class BIP38PrivateKey extends PrefixedChecksummedBytes {
public ECKey decrypt(String passphrase) throws BadPassphraseException { public ECKey decrypt(String passphrase) throws BadPassphraseException {
String normalizedPassphrase = Normalizer.normalize(passphrase, Normalizer.Form.NFC); String normalizedPassphrase = Normalizer.normalize(passphrase, Normalizer.Form.NFC);
ECKey key = ecMultiply ? decryptEC(normalizedPassphrase) : decryptNoEC(normalizedPassphrase); ECKey key = ecMultiply ? decryptEC(normalizedPassphrase) : decryptNoEC(normalizedPassphrase);
Sha256Hash hash = Sha256Hash.twiceOf(LegacyAddress.fromKey(params, key).toString().getBytes(Charsets.US_ASCII)); Sha256Hash hash = Sha256Hash.twiceOf(LegacyAddress.fromKey(params, key).toString().getBytes(StandardCharsets.US_ASCII));
byte[] actualAddressHash = Arrays.copyOfRange(hash.getBytes(), 0, 4); byte[] actualAddressHash = Arrays.copyOfRange(hash.getBytes(), 0, 4);
if (!Arrays.equals(actualAddressHash, addressHash)) if (!Arrays.equals(actualAddressHash, addressHash))
throw new BadPassphraseException(); throw new BadPassphraseException();
@ -126,7 +126,7 @@ public class BIP38PrivateKey extends PrefixedChecksummedBytes {
private ECKey decryptNoEC(String normalizedPassphrase) { private ECKey decryptNoEC(String normalizedPassphrase) {
try { try {
byte[] derived = SCrypt.scrypt(normalizedPassphrase.getBytes(Charsets.UTF_8), addressHash, 16384, 8, 8, 64); byte[] derived = SCrypt.scrypt(normalizedPassphrase.getBytes(StandardCharsets.UTF_8), addressHash, 16384, 8, 8, 64);
byte[] key = Arrays.copyOfRange(derived, 32, 64); byte[] key = Arrays.copyOfRange(derived, 32, 64);
SecretKeySpec keyspec = new SecretKeySpec(key, "AES"); SecretKeySpec keyspec = new SecretKeySpec(key, "AES");
@ -148,7 +148,7 @@ public class BIP38PrivateKey extends PrefixedChecksummedBytes {
byte[] ownerEntropy = Arrays.copyOfRange(content, 0, 8); byte[] ownerEntropy = Arrays.copyOfRange(content, 0, 8);
byte[] ownerSalt = hasLotAndSequence ? Arrays.copyOfRange(ownerEntropy, 0, 4) : ownerEntropy; byte[] ownerSalt = hasLotAndSequence ? Arrays.copyOfRange(ownerEntropy, 0, 4) : ownerEntropy;
byte[] passFactorBytes = SCrypt.scrypt(normalizedPassphrase.getBytes(Charsets.UTF_8), ownerSalt, 16384, 8, 8, 32); byte[] passFactorBytes = SCrypt.scrypt(normalizedPassphrase.getBytes(StandardCharsets.UTF_8), ownerSalt, 16384, 8, 8, 32);
if (hasLotAndSequence) { if (hasLotAndSequence) {
byte[] hashBytes = Bytes.concat(passFactorBytes, ownerEntropy); byte[] hashBytes = Bytes.concat(passFactorBytes, ownerEntropy);
checkState(hashBytes.length == 40); checkState(hashBytes.length == 40);

View File

@ -22,7 +22,6 @@ import org.bitcoinj.core.Utils;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import com.google.common.base.Charsets;
import com.google.common.base.Stopwatch; import com.google.common.base.Stopwatch;
import java.io.BufferedReader; import java.io.BufferedReader;
@ -30,6 +29,7 @@ import java.io.FileNotFoundException;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.io.InputStreamReader; import java.io.InputStreamReader;
import java.nio.charset.StandardCharsets;
import java.security.MessageDigest; import java.security.MessageDigest;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collections; import java.util.Collections;
@ -88,7 +88,7 @@ public class MnemonicCode {
* is supplied the digest of the words will be checked. * is supplied the digest of the words will be checked.
*/ */
public MnemonicCode(InputStream wordstream, String wordListDigest) throws IOException, IllegalArgumentException { public MnemonicCode(InputStream wordstream, String wordListDigest) throws IOException, IllegalArgumentException {
BufferedReader br = new BufferedReader(new InputStreamReader(wordstream, Charsets.UTF_8)); BufferedReader br = new BufferedReader(new InputStreamReader(wordstream, StandardCharsets.UTF_8));
this.wordList = new ArrayList<>(2048); this.wordList = new ArrayList<>(2048);
MessageDigest md = Sha256Hash.newDigest(); MessageDigest md = Sha256Hash.newDigest();
String word; String word;

View File

@ -26,11 +26,10 @@ package org.bitcoinj.crypto;
import javax.crypto.Mac; import javax.crypto.Mac;
import javax.crypto.spec.SecretKeySpec; import javax.crypto.spec.SecretKeySpec;
import com.google.common.base.Charsets;
import java.io.ByteArrayOutputStream; import java.io.ByteArrayOutputStream;
import java.nio.ByteBuffer; import java.nio.ByteBuffer;
import java.nio.ByteOrder; import java.nio.ByteOrder;
import java.nio.charset.StandardCharsets;
/** /**
* <p>This is a clean-room implementation of PBKDF2 using RFC 2898 as a reference.</p> * <p>This is a clean-room implementation of PBKDF2 using RFC 2898 as a reference.</p>
@ -74,13 +73,13 @@ public class PBKDF2SHA512 {
byte[] U_LAST = null; byte[] U_LAST = null;
byte[] U_XOR = null; byte[] U_XOR = null;
SecretKeySpec key = new SecretKeySpec(P.getBytes(Charsets.UTF_8), "HmacSHA512"); SecretKeySpec key = new SecretKeySpec(P.getBytes(StandardCharsets.UTF_8), "HmacSHA512");
Mac mac = Mac.getInstance(key.getAlgorithm()); Mac mac = Mac.getInstance(key.getAlgorithm());
mac.init(key); mac.init(key);
for (int j = 0; j < c; j++) { for (int j = 0; j < c; j++) {
if (j == 0) { if (j == 0) {
byte[] baS = S.getBytes(Charsets.UTF_8); byte[] baS = S.getBytes(StandardCharsets.UTF_8);
byte[] baI = INT(i); byte[] baI = INT(i);
byte[] baU = new byte[baS.length + baI.length]; byte[] baU = new byte[baS.length + baI.length];

View File

@ -20,12 +20,11 @@ import org.bitcoinj.core.*;
import org.bitcoinj.utils.*; import org.bitcoinj.utils.*;
import org.slf4j.*; import org.slf4j.*;
import com.google.common.base.Charsets;
import javax.annotation.*; import javax.annotation.*;
import java.io.*; import java.io.*;
import java.nio.*; import java.nio.*;
import java.nio.channels.*; import java.nio.channels.*;
import java.nio.charset.StandardCharsets;
import java.util.*; import java.util.*;
import java.util.concurrent.locks.*; import java.util.concurrent.locks.*;
@ -133,7 +132,7 @@ public class SPVBlockStore implements BlockStore {
if (exists) { if (exists) {
header = new byte[4]; header = new byte[4];
buffer.get(header); buffer.get(header);
if (!new String(header, Charsets.US_ASCII).equals(HEADER_MAGIC)) if (!new String(header, StandardCharsets.US_ASCII).equals(HEADER_MAGIC))
throw new BlockStoreException("Header bytes do not equal " + HEADER_MAGIC); throw new BlockStoreException("Header bytes do not equal " + HEADER_MAGIC);
} else { } else {
initNewStore(params); initNewStore(params);

View File

@ -20,12 +20,13 @@ package org.bitcoinj.wallet;
import org.bitcoinj.core.Utils; import org.bitcoinj.core.Utils;
import org.bitcoinj.crypto.*; import org.bitcoinj.crypto.*;
import com.google.common.base.Charsets;
import com.google.common.base.Objects; import com.google.common.base.Objects;
import com.google.common.base.Splitter; import com.google.common.base.Splitter;
import org.spongycastle.crypto.params.KeyParameter; import org.spongycastle.crypto.params.KeyParameter;
import javax.annotation.Nullable; import javax.annotation.Nullable;
import java.nio.charset.StandardCharsets;
import java.security.SecureRandom; import java.security.SecureRandom;
import java.util.List; import java.util.List;
@ -188,7 +189,7 @@ public class DeterministicSeed implements EncryptableItem {
} }
private byte[] getMnemonicAsBytes() { private byte[] getMnemonicAsBytes() {
return Utils.SPACE_JOINER.join(mnemonicCode).getBytes(Charsets.UTF_8); return Utils.SPACE_JOINER.join(mnemonicCode).getBytes(StandardCharsets.UTF_8);
} }
public DeterministicSeed decrypt(KeyCrypter crypter, String passphrase, KeyParameter aesKey) { public DeterministicSeed decrypt(KeyCrypter crypter, String passphrase, KeyParameter aesKey) {
@ -236,7 +237,7 @@ public class DeterministicSeed implements EncryptableItem {
} }
private static List<String> decodeMnemonicCode(byte[] mnemonicCode) { private static List<String> decodeMnemonicCode(byte[] mnemonicCode) {
return decodeMnemonicCode(new String(mnemonicCode, Charsets.UTF_8)); return decodeMnemonicCode(new String(mnemonicCode, StandardCharsets.UTF_8));
} }
private static List<String> decodeMnemonicCode(String mnemonicCode) { private static List<String> decodeMnemonicCode(String mnemonicCode) {

View File

@ -16,7 +16,6 @@
package org.bitcoinj.core; package org.bitcoinj.core;
import com.google.common.base.Charsets;
import com.google.common.collect.*; import com.google.common.collect.*;
import org.bitcoinj.core.listeners.*; import org.bitcoinj.core.listeners.*;
import org.bitcoinj.params.TestNet3Params; import org.bitcoinj.params.TestNet3Params;
@ -43,6 +42,7 @@ import java.io.OutputStream;
import java.net.InetSocketAddress; import java.net.InetSocketAddress;
import java.net.SocketException; import java.net.SocketException;
import java.nio.channels.CancelledKeyException; import java.nio.channels.CancelledKeyException;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.Collection; import java.util.Collection;
@ -774,7 +774,7 @@ public class PeerTest extends TestWithNetworkConnections {
Transaction t2 = new Transaction(UNITTEST); Transaction t2 = new Transaction(UNITTEST);
t2.setLockTime(999999); t2.setLockTime(999999);
// Add a fake input to t3 that goes nowhere. // Add a fake input to t3 that goes nowhere.
Sha256Hash t3 = Sha256Hash.of("abc".getBytes(Charsets.UTF_8)); Sha256Hash t3 = Sha256Hash.of("abc".getBytes(StandardCharsets.UTF_8));
t2.addInput(new TransactionInput(UNITTEST, t2, new byte[]{}, new TransactionOutPoint(UNITTEST, 0, t3))); t2.addInput(new TransactionInput(UNITTEST, t2, new byte[]{}, new TransactionOutPoint(UNITTEST, 0, t3)));
t2.getInput(0).setSequenceNumber(0xDEADBEEF); t2.getInput(0).setSequenceNumber(0xDEADBEEF);
t2.addOutput(COIN, new ECKey()); t2.addOutput(COIN, new ECKey());

View File

@ -26,7 +26,6 @@ import org.bitcoinj.crypto.TransactionSignature;
import org.bitcoinj.params.MainNetParams; import org.bitcoinj.params.MainNetParams;
import org.bitcoinj.params.TestNet3Params; import org.bitcoinj.params.TestNet3Params;
import org.bitcoinj.script.Script.VerifyFlag; import org.bitcoinj.script.Script.VerifyFlag;
import com.google.common.base.Charsets;
import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableList;
import com.google.common.collect.Lists; import com.google.common.collect.Lists;
@ -39,6 +38,7 @@ import org.slf4j.LoggerFactory;
import java.io.IOException; import java.io.IOException;
import java.io.InputStreamReader; import java.io.InputStreamReader;
import java.math.BigInteger; import java.math.BigInteger;
import java.nio.charset.StandardCharsets;
import java.util.*; import java.util.*;
import static org.bitcoinj.core.Utils.HEX; import static org.bitcoinj.core.Utils.HEX;
@ -254,7 +254,7 @@ public class ScriptTest {
} else if (w.length() >= 2 && w.startsWith("'") && w.endsWith("'")) { } else if (w.length() >= 2 && w.startsWith("'") && w.endsWith("'")) {
// Single-quoted string, pushed as data. NOTE: this is poor-man's // Single-quoted string, pushed as data. NOTE: this is poor-man's
// parsing, spaces/tabs/newlines in single-quoted strings won't work. // parsing, spaces/tabs/newlines in single-quoted strings won't work.
Script.writeBytes(out, w.substring(1, w.length() - 1).getBytes(Charsets.UTF_8)); Script.writeBytes(out, w.substring(1, w.length() - 1).getBytes(StandardCharsets.UTF_8));
} else if (ScriptOpCodes.getOpCode(w) != OP_INVALIDOPCODE) { } else if (ScriptOpCodes.getOpCode(w) != OP_INVALIDOPCODE) {
// opcode, e.g. OP_ADD or OP_1: // opcode, e.g. OP_ADD or OP_1:
out.write(ScriptOpCodes.getOpCode(w)); out.write(ScriptOpCodes.getOpCode(w));
@ -286,7 +286,7 @@ public class ScriptTest {
@Test @Test
public void dataDrivenScripts() throws Exception { public void dataDrivenScripts() throws Exception {
JsonNode json = new ObjectMapper() JsonNode json = new ObjectMapper()
.readTree(new InputStreamReader(getClass().getResourceAsStream("script_tests.json"), Charsets.UTF_8)); .readTree(new InputStreamReader(getClass().getResourceAsStream("script_tests.json"), StandardCharsets.UTF_8));
for (JsonNode test : json) { for (JsonNode test : json) {
if (test.size() == 1) if (test.size() == 1)
continue; // skip comment continue; // skip comment
@ -358,7 +358,7 @@ public class ScriptTest {
@Test @Test
public void dataDrivenValidTransactions() throws Exception { public void dataDrivenValidTransactions() throws Exception {
JsonNode json = new ObjectMapper().readTree(new InputStreamReader(getClass().getResourceAsStream( JsonNode json = new ObjectMapper().readTree(new InputStreamReader(getClass().getResourceAsStream(
"tx_valid.json"), Charsets.UTF_8)); "tx_valid.json"), StandardCharsets.UTF_8));
for (JsonNode test : json) { for (JsonNode test : json) {
if (test.isArray() && test.size() == 1 && test.get(0).isTextual()) if (test.isArray() && test.size() == 1 && test.get(0).isTextual())
continue; // This is a comment. continue; // This is a comment.
@ -389,7 +389,7 @@ public class ScriptTest {
@Test @Test
public void dataDrivenInvalidTransactions() throws Exception { public void dataDrivenInvalidTransactions() throws Exception {
JsonNode json = new ObjectMapper().readTree(new InputStreamReader(getClass().getResourceAsStream( JsonNode json = new ObjectMapper().readTree(new InputStreamReader(getClass().getResourceAsStream(
"tx_invalid.json"), Charsets.UTF_8)); "tx_invalid.json"), StandardCharsets.UTF_8));
for (JsonNode test : json) { for (JsonNode test : json) {
if (test.isArray() && test.size() == 1 && test.get(0).isTextual()) if (test.isArray() && test.size() == 1 && test.get(0).isTextual())
continue; // This is a comment. continue; // This is a comment.

View File

@ -31,7 +31,6 @@ import org.bitcoinj.utils.BriefLogFormatter;
import org.bitcoinj.utils.Threading; import org.bitcoinj.utils.Threading;
import org.bitcoinj.wallet.listeners.AbstractKeyChainEventListener; import org.bitcoinj.wallet.listeners.AbstractKeyChainEventListener;
import com.google.common.base.Charsets;
import com.google.common.base.Joiner; import com.google.common.base.Joiner;
import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableList;
import com.google.common.collect.Lists; import com.google.common.collect.Lists;
@ -42,6 +41,7 @@ import org.junit.Test;
import org.spongycastle.crypto.params.KeyParameter; import org.spongycastle.crypto.params.KeyParameter;
import java.io.IOException; import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.security.SecureRandom; import java.security.SecureRandom;
import java.util.List; import java.util.List;
@ -693,7 +693,7 @@ public class DeterministicKeyChainTest {
private String checkSerialization(List<Protos.Key> keys, String filename) { private String checkSerialization(List<Protos.Key> keys, String filename) {
try { try {
String sb = protoToString(keys); String sb = protoToString(keys);
List<String> lines = Resources.readLines(getClass().getResource(filename), Charsets.UTF_8); List<String> lines = Resources.readLines(getClass().getResource(filename), StandardCharsets.UTF_8);
String expected = Joiner.on('\n').join(lines); String expected = Joiner.on('\n').join(lines);
assertEquals(expected, sb); assertEquals(expected, sb);
return expected; return expected;

View File

@ -27,7 +27,6 @@ import org.bitcoinj.store.BlockStore;
import org.bitcoinj.store.MemoryBlockStore; import org.bitcoinj.store.MemoryBlockStore;
import org.bitcoinj.utils.BriefLogFormatter; import org.bitcoinj.utils.BriefLogFormatter;
import org.bitcoinj.utils.Threading; import org.bitcoinj.utils.Threading;
import com.google.common.base.Charsets;
import com.google.common.io.Resources; import com.google.common.io.Resources;
import joptsimple.OptionParser; import joptsimple.OptionParser;
import joptsimple.OptionSet; import joptsimple.OptionSet;
@ -43,6 +42,7 @@ import java.io.PrintWriter;
import java.net.InetAddress; import java.net.InetAddress;
import java.net.UnknownHostException; import java.net.UnknownHostException;
import java.nio.ByteBuffer; import java.nio.ByteBuffer;
import java.nio.charset.StandardCharsets;
import java.security.DigestOutputStream; import java.security.DigestOutputStream;
import java.security.MessageDigest; import java.security.MessageDigest;
import java.util.*; import java.util.*;
@ -69,7 +69,7 @@ public class BuildCheckpoints {
OptionSet options = parser.parse(args); OptionSet options = parser.parse(args);
if (options.has("help")) { if (options.has("help")) {
System.out.println(Resources.toString(BuildCheckpoints.class.getResource("build-checkpoints-help.txt"), Charsets.UTF_8)); System.out.println(Resources.toString(BuildCheckpoints.class.getResource("build-checkpoints-help.txt"), StandardCharsets.UTF_8));
return; return;
} }
@ -196,7 +196,7 @@ public class BuildCheckpoints {
} }
private static void writeTextualCheckpoints(TreeMap<Integer, StoredBlock> checkpoints, File file) throws IOException { private static void writeTextualCheckpoints(TreeMap<Integer, StoredBlock> checkpoints, File file) throws IOException {
PrintWriter writer = new PrintWriter(new OutputStreamWriter(new FileOutputStream(file), Charsets.US_ASCII)); PrintWriter writer = new PrintWriter(new OutputStreamWriter(new FileOutputStream(file), StandardCharsets.US_ASCII));
writer.println("TXT CHECKPOINTS 1"); writer.println("TXT CHECKPOINTS 1");
writer.println("0"); // Number of signatures to read. Do this later. writer.println("0"); // Number of signatures to read. Do this later.
writer.println(checkpoints.size()); writer.println(checkpoints.size());

View File

@ -34,7 +34,6 @@ import org.bitcoinj.utils.BriefLogFormatter;
import org.bitcoinj.wallet.DeterministicSeed; import org.bitcoinj.wallet.DeterministicSeed;
import org.bitcoinj.wallet.DeterministicUpgradeRequiredException; import org.bitcoinj.wallet.DeterministicUpgradeRequiredException;
import org.bitcoinj.wallet.DeterministicUpgradeRequiresPassword; import org.bitcoinj.wallet.DeterministicUpgradeRequiresPassword;
import com.google.common.base.Charsets;
import com.google.common.base.Splitter; import com.google.common.base.Splitter;
import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableList;
import com.google.common.io.Resources; import com.google.common.io.Resources;
@ -95,6 +94,7 @@ import java.io.*;
import java.math.BigInteger; import java.math.BigInteger;
import java.net.InetAddress; import java.net.InetAddress;
import java.net.UnknownHostException; import java.net.UnknownHostException;
import java.nio.charset.StandardCharsets;
import java.security.SecureRandom; import java.security.SecureRandom;
import java.text.ParseException; import java.text.ParseException;
import java.text.SimpleDateFormat; import java.text.SimpleDateFormat;
@ -266,7 +266,7 @@ public class WalletTool {
if (args.length == 0 || options.has("help") || if (args.length == 0 || options.has("help") ||
options.nonOptionArguments().size() < 1 || options.nonOptionArguments().contains("help")) { options.nonOptionArguments().size() < 1 || options.nonOptionArguments().contains("help")) {
System.out.println(Resources.toString(WalletTool.class.getResource("wallet-tool-help.txt"), Charsets.UTF_8)); System.out.println(Resources.toString(WalletTool.class.getResource("wallet-tool-help.txt"), StandardCharsets.UTF_8));
return; return;
} }