mirror of
https://github.com/Qortal/altcoinj.git
synced 2025-02-14 19:25:51 +00:00
Utils: Move copyOf() to UnsafeByteArrayOutputStream, as it's only being used there.
This commit is contained in:
parent
0fd8ab3fa2
commit
96bdad5a67
@ -49,7 +49,7 @@ public class UnsafeByteArrayOutputStream extends ByteArrayOutputStream {
|
||||
public void write(int b) {
|
||||
int newcount = count + 1;
|
||||
if (newcount > buf.length) {
|
||||
buf = Utils.copyOf(buf, Math.max(buf.length << 1, newcount));
|
||||
buf = copyOf(buf, Math.max(buf.length << 1, newcount));
|
||||
}
|
||||
buf[count] = (byte) b;
|
||||
count = newcount;
|
||||
@ -73,7 +73,7 @@ public class UnsafeByteArrayOutputStream extends ByteArrayOutputStream {
|
||||
}
|
||||
int newcount = count + len;
|
||||
if (newcount > buf.length) {
|
||||
buf = Utils.copyOf(buf, Math.max(buf.length << 1, newcount));
|
||||
buf = copyOf(buf, Math.max(buf.length << 1, newcount));
|
||||
}
|
||||
System.arraycopy(b, off, buf, count, len);
|
||||
count = newcount;
|
||||
@ -115,7 +115,7 @@ public class UnsafeByteArrayOutputStream extends ByteArrayOutputStream {
|
||||
*/
|
||||
@Override
|
||||
public byte toByteArray()[] {
|
||||
return count == buf.length ? buf : Utils.copyOf(buf, count);
|
||||
return count == buf.length ? buf : copyOf(buf, count);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -130,4 +130,9 @@ public class UnsafeByteArrayOutputStream extends ByteArrayOutputStream {
|
||||
return count;
|
||||
}
|
||||
|
||||
private static byte[] copyOf(byte[] in, int length) {
|
||||
byte[] out = new byte[length];
|
||||
System.arraycopy(in, 0, out, 0, Math.min(length, in.length));
|
||||
return out;
|
||||
}
|
||||
}
|
||||
|
@ -402,12 +402,6 @@ public class Utils {
|
||||
return iso8601.format(dateTime);
|
||||
}
|
||||
|
||||
public static byte[] copyOf(byte[] in, int length) {
|
||||
byte[] out = new byte[length];
|
||||
System.arraycopy(in, 0, out, 0, Math.min(length, in.length));
|
||||
return out;
|
||||
}
|
||||
|
||||
/**
|
||||
* Attempts to parse the given string as arbitrary-length hex or base58 and then return the results, or null if
|
||||
* neither parse was successful.
|
||||
|
Loading…
x
Reference in New Issue
Block a user