mirror of
https://github.com/bitcoinj/bitcoinj.git
synced 2025-02-23 22:46:56 +01:00
ByteUtils: rename read helpers that read from streams
This commit is contained in:
parent
d89718aaf6
commit
7303043f37
4 changed files with 8 additions and 8 deletions
|
@ -418,7 +418,7 @@ public class ByteUtils {
|
||||||
* Read 2 bytes from the stream as unsigned 16-bit integer in little endian format.
|
* Read 2 bytes from the stream as unsigned 16-bit integer in little endian format.
|
||||||
* @param is stream to be read from
|
* @param is stream to be read from
|
||||||
*/
|
*/
|
||||||
public static int readUint16FromStream(InputStream is) {
|
public static int readUint16(InputStream is) {
|
||||||
byte[] buf = new byte[2];
|
byte[] buf = new byte[2];
|
||||||
try {
|
try {
|
||||||
is.read(buf);
|
is.read(buf);
|
||||||
|
@ -432,7 +432,7 @@ public class ByteUtils {
|
||||||
* Read 4 bytes from the stream as unsigned 32-bit integer in little endian format.
|
* Read 4 bytes from the stream as unsigned 32-bit integer in little endian format.
|
||||||
* @param is stream to be read from
|
* @param is stream to be read from
|
||||||
*/
|
*/
|
||||||
public static long readUint32FromStream(InputStream is) {
|
public static long readUint32(InputStream is) {
|
||||||
byte[] buf = new byte[4];
|
byte[] buf = new byte[4];
|
||||||
try {
|
try {
|
||||||
is.read(buf);
|
is.read(buf);
|
||||||
|
|
|
@ -40,12 +40,12 @@ public class TransactionOutputChanges {
|
||||||
}
|
}
|
||||||
|
|
||||||
public TransactionOutputChanges(InputStream in) throws IOException {
|
public TransactionOutputChanges(InputStream in) throws IOException {
|
||||||
int numOutsCreated = (int) ByteUtils.readUint32FromStream(in);
|
int numOutsCreated = (int) ByteUtils.readUint32(in);
|
||||||
txOutsCreated = new LinkedList<>();
|
txOutsCreated = new LinkedList<>();
|
||||||
for (int i = 0; i < numOutsCreated; i++)
|
for (int i = 0; i < numOutsCreated; i++)
|
||||||
txOutsCreated.add(UTXO.fromStream(in));
|
txOutsCreated.add(UTXO.fromStream(in));
|
||||||
|
|
||||||
int numOutsSpent = (int) ByteUtils.readUint32FromStream(in);
|
int numOutsSpent = (int) ByteUtils.readUint32(in);
|
||||||
txOutsSpent = new LinkedList<>();
|
txOutsSpent = new LinkedList<>();
|
||||||
for (int i = 0; i < numOutsSpent; i++)
|
for (int i = 0; i < numOutsSpent; i++)
|
||||||
txOutsSpent.add(UTXO.fromStream(in));
|
txOutsSpent.add(UTXO.fromStream(in));
|
||||||
|
|
|
@ -160,7 +160,7 @@ public class UTXO {
|
||||||
throw new EOFException();
|
throw new EOFException();
|
||||||
Coin value = Coin.valueOf(ByteUtils.readInt64(valueBytes, 0));
|
Coin value = Coin.valueOf(ByteUtils.readInt64(valueBytes, 0));
|
||||||
|
|
||||||
int scriptBytesLength = (int) ByteUtils.readUint32FromStream(in);
|
int scriptBytesLength = (int) ByteUtils.readUint32(in);
|
||||||
byte[] scriptBytes = new byte[scriptBytesLength];
|
byte[] scriptBytes = new byte[scriptBytesLength];
|
||||||
if (in.read(scriptBytes) != scriptBytesLength)
|
if (in.read(scriptBytes) != scriptBytesLength)
|
||||||
throw new EOFException();
|
throw new EOFException();
|
||||||
|
@ -176,7 +176,7 @@ public class UTXO {
|
||||||
throw new EOFException();
|
throw new EOFException();
|
||||||
long index = ByteUtils.readUint32(indexBytes, 0);
|
long index = ByteUtils.readUint32(indexBytes, 0);
|
||||||
|
|
||||||
int height = (int) ByteUtils.readUint32FromStream(in);
|
int height = (int) ByteUtils.readUint32(in);
|
||||||
|
|
||||||
byte[] coinbaseByte = new byte[1];
|
byte[] coinbaseByte = new byte[1];
|
||||||
in.read(coinbaseByte);
|
in.read(coinbaseByte);
|
||||||
|
|
|
@ -368,12 +368,12 @@ public class Script {
|
||||||
} else if (opcode == OP_PUSHDATA2) {
|
} else if (opcode == OP_PUSHDATA2) {
|
||||||
// Read a short, then read that many bytes of data.
|
// Read a short, then read that many bytes of data.
|
||||||
if (bis.available() < 2) throw new ScriptException(ScriptError.SCRIPT_ERR_UNKNOWN_ERROR, "Unexpected end of script");
|
if (bis.available() < 2) throw new ScriptException(ScriptError.SCRIPT_ERR_UNKNOWN_ERROR, "Unexpected end of script");
|
||||||
dataToRead = ByteUtils.readUint16FromStream(bis);
|
dataToRead = ByteUtils.readUint16(bis);
|
||||||
} else if (opcode == OP_PUSHDATA4) {
|
} else if (opcode == OP_PUSHDATA4) {
|
||||||
// Read a uint32, then read that many bytes of data.
|
// Read a uint32, then read that many bytes of data.
|
||||||
// Though this is allowed, because its value cannot be > 520, it should never actually be used
|
// Though this is allowed, because its value cannot be > 520, it should never actually be used
|
||||||
if (bis.available() < 4) throw new ScriptException(ScriptError.SCRIPT_ERR_UNKNOWN_ERROR, "Unexpected end of script");
|
if (bis.available() < 4) throw new ScriptException(ScriptError.SCRIPT_ERR_UNKNOWN_ERROR, "Unexpected end of script");
|
||||||
dataToRead = ByteUtils.readUint32FromStream(bis);
|
dataToRead = ByteUtils.readUint32(bis);
|
||||||
}
|
}
|
||||||
|
|
||||||
ScriptChunk chunk;
|
ScriptChunk chunk;
|
||||||
|
|
Loading…
Add table
Reference in a new issue