ByteUtils: rename read helpers that read from streams

This commit is contained in:
Andreas Schildbach 2023-03-21 17:46:26 +01:00
parent d89718aaf6
commit 7303043f37
4 changed files with 8 additions and 8 deletions

View file

@ -418,7 +418,7 @@ public class ByteUtils {
* Read 2 bytes from the stream as unsigned 16-bit integer in little endian format.
* @param is stream to be read from
*/
public static int readUint16FromStream(InputStream is) {
public static int readUint16(InputStream is) {
byte[] buf = new byte[2];
try {
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.
* @param is stream to be read from
*/
public static long readUint32FromStream(InputStream is) {
public static long readUint32(InputStream is) {
byte[] buf = new byte[4];
try {
is.read(buf);

View file

@ -40,12 +40,12 @@ public class TransactionOutputChanges {
}
public TransactionOutputChanges(InputStream in) throws IOException {
int numOutsCreated = (int) ByteUtils.readUint32FromStream(in);
int numOutsCreated = (int) ByteUtils.readUint32(in);
txOutsCreated = new LinkedList<>();
for (int i = 0; i < numOutsCreated; i++)
txOutsCreated.add(UTXO.fromStream(in));
int numOutsSpent = (int) ByteUtils.readUint32FromStream(in);
int numOutsSpent = (int) ByteUtils.readUint32(in);
txOutsSpent = new LinkedList<>();
for (int i = 0; i < numOutsSpent; i++)
txOutsSpent.add(UTXO.fromStream(in));

View file

@ -160,7 +160,7 @@ public class UTXO {
throw new EOFException();
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];
if (in.read(scriptBytes) != scriptBytesLength)
throw new EOFException();
@ -176,7 +176,7 @@ public class UTXO {
throw new EOFException();
long index = ByteUtils.readUint32(indexBytes, 0);
int height = (int) ByteUtils.readUint32FromStream(in);
int height = (int) ByteUtils.readUint32(in);
byte[] coinbaseByte = new byte[1];
in.read(coinbaseByte);

View file

@ -368,12 +368,12 @@ public class Script {
} else if (opcode == OP_PUSHDATA2) {
// 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");
dataToRead = ByteUtils.readUint16FromStream(bis);
dataToRead = ByteUtils.readUint16(bis);
} else if (opcode == OP_PUSHDATA4) {
// 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
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;