3
0
mirror of https://github.com/Qortal/altcoinj.git synced 2025-02-15 11:45:51 +00:00

Utils: Move copyOf() to UnsafeByteArrayOutputStream, as it's only being used there.

This commit is contained in:
Andreas Schildbach 2018-02-22 11:08:58 +01:00
parent 0fd8ab3fa2
commit 96bdad5a67
2 changed files with 8 additions and 9 deletions

View File

@ -49,7 +49,7 @@ public class UnsafeByteArrayOutputStream extends ByteArrayOutputStream {
public void write(int b) { public void write(int b) {
int newcount = count + 1; int newcount = count + 1;
if (newcount > buf.length) { 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; buf[count] = (byte) b;
count = newcount; count = newcount;
@ -73,7 +73,7 @@ public class UnsafeByteArrayOutputStream extends ByteArrayOutputStream {
} }
int newcount = count + len; int newcount = count + len;
if (newcount > buf.length) { 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); System.arraycopy(b, off, buf, count, len);
count = newcount; count = newcount;
@ -115,7 +115,7 @@ public class UnsafeByteArrayOutputStream extends ByteArrayOutputStream {
*/ */
@Override @Override
public byte toByteArray()[] { 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; 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;
}
} }

View File

@ -402,12 +402,6 @@ public class Utils {
return iso8601.format(dateTime); 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 * Attempts to parse the given string as arbitrary-length hex or base58 and then return the results, or null if
* neither parse was successful. * neither parse was successful.