mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-17 13:19:52 +01:00
Whitespace-only code formatting changes.
This commit is contained in:
@@ -13,24 +13,24 @@ public class ByteUtils {
|
||||
public static final long MAX_32_BIT_UNSIGNED = 4294967295L; // 2^32 - 1
|
||||
|
||||
public static void writeUint8(int i, byte[] b, int offset) {
|
||||
if(i < 0) throw new IllegalArgumentException();
|
||||
if(i > 255) throw new IllegalArgumentException();
|
||||
if(b.length < offset) throw new IllegalArgumentException();
|
||||
if (i < 0) throw new IllegalArgumentException();
|
||||
if (i > 255) throw new IllegalArgumentException();
|
||||
if (b.length < offset) throw new IllegalArgumentException();
|
||||
b[offset] = (byte) i;
|
||||
}
|
||||
|
||||
public static void writeUint16(int i, byte[] b, int offset) {
|
||||
if(i < 0) throw new IllegalArgumentException();
|
||||
if(i > MAX_16_BIT_UNSIGNED) throw new IllegalArgumentException();
|
||||
if(b.length < offset + 2) throw new IllegalArgumentException();
|
||||
if (i < 0) throw new IllegalArgumentException();
|
||||
if (i > MAX_16_BIT_UNSIGNED) throw new IllegalArgumentException();
|
||||
if (b.length < offset + 2) throw new IllegalArgumentException();
|
||||
b[offset] = (byte) (i >> 8);
|
||||
b[offset + 1] = (byte) (i & 0xFF);
|
||||
}
|
||||
|
||||
public static void writeUint32(long i, byte[] b, int offset) {
|
||||
if(i < 0) throw new IllegalArgumentException();
|
||||
if(i > MAX_32_BIT_UNSIGNED) throw new IllegalArgumentException();
|
||||
if(b.length < offset + 4) throw new IllegalArgumentException();
|
||||
if (i < 0) throw new IllegalArgumentException();
|
||||
if (i > MAX_32_BIT_UNSIGNED) throw new IllegalArgumentException();
|
||||
if (b.length < offset + 4) throw new IllegalArgumentException();
|
||||
b[offset] = (byte) (i >> 24);
|
||||
b[offset + 1] = (byte) (i >> 16 & 0xFF);
|
||||
b[offset + 2] = (byte) (i >> 8 & 0xFF);
|
||||
@@ -38,21 +38,21 @@ public class ByteUtils {
|
||||
}
|
||||
|
||||
public static int readUint16(byte[] b, int offset) {
|
||||
if(b.length < offset + 2) throw new IllegalArgumentException();
|
||||
if (b.length < offset + 2) throw new IllegalArgumentException();
|
||||
return ((b[offset] & 0xFF) << 8) | (b[offset + 1] & 0xFF);
|
||||
}
|
||||
|
||||
public static long readUint32(byte[] b, int offset) {
|
||||
if(b.length < offset + 4) throw new IllegalArgumentException();
|
||||
if (b.length < offset + 4) throw new IllegalArgumentException();
|
||||
return ((b[offset] & 0xFFL) << 24) | ((b[offset + 1] & 0xFFL) << 16)
|
||||
| ((b[offset + 2] & 0xFFL) << 8) | (b[offset + 3] & 0xFFL);
|
||||
}
|
||||
|
||||
public static int readUint(byte[] b, int bits) {
|
||||
if(b.length << 3 < bits) throw new IllegalArgumentException();
|
||||
if (b.length << 3 < bits) throw new IllegalArgumentException();
|
||||
int result = 0;
|
||||
for(int i = 0; i < bits; i++) {
|
||||
if((b[i >> 3] & 128 >> (i & 7)) != 0) result |= 1 << bits - i - 1;
|
||||
for (int i = 0; i < bits; i++) {
|
||||
if ((b[i >> 3] & 128 >> (i & 7)) != 0) result |= 1 << bits - i - 1;
|
||||
}
|
||||
assert result >= 0;
|
||||
assert result < 1 << bits;
|
||||
|
||||
@@ -15,8 +15,8 @@ public class LatchedReference<T> {
|
||||
}
|
||||
|
||||
public boolean set(T t) {
|
||||
if(t == null) throw new IllegalArgumentException();
|
||||
if(reference.compareAndSet(null, t)) {
|
||||
if (t == null) throw new IllegalArgumentException();
|
||||
if (reference.compareAndSet(null, t)) {
|
||||
latch.countDown();
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -15,14 +15,14 @@ public class OsUtils {
|
||||
}
|
||||
|
||||
public static boolean isMacLeopardOrNewer() {
|
||||
if(!isMac() || version == null) return false;
|
||||
if (!isMac() || version == null) return false;
|
||||
try {
|
||||
String[] v = version.split("\\.");
|
||||
if(v.length != 3) return false;
|
||||
if (v.length != 3) return false;
|
||||
int major = Integer.parseInt(v[0]);
|
||||
int minor = Integer.parseInt(v[1]);
|
||||
return major >= 10 && minor >= 5;
|
||||
} catch(NumberFormatException e) {
|
||||
} catch (NumberFormatException e) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,8 +16,8 @@ public class StringUtils {
|
||||
|
||||
public static String join(Collection<String> strings, String separator) {
|
||||
StringBuilder joined = new StringBuilder();
|
||||
for(String s : strings) {
|
||||
if(joined.length() > 0) joined.append(separator);
|
||||
for (String s : strings) {
|
||||
if (joined.length() > 0) joined.append(separator);
|
||||
joined.append(s);
|
||||
}
|
||||
return joined.toString();
|
||||
@@ -26,7 +26,7 @@ public class StringUtils {
|
||||
public static byte[] toUtf8(String s) {
|
||||
try {
|
||||
return s.getBytes("UTF-8");
|
||||
} catch(UnsupportedEncodingException e) {
|
||||
} catch (UnsupportedEncodingException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
@@ -34,7 +34,7 @@ public class StringUtils {
|
||||
public static String fromUtf8(byte[] bytes) {
|
||||
try {
|
||||
return new String(bytes, "UTF-8");
|
||||
} catch(UnsupportedEncodingException e) {
|
||||
} catch (UnsupportedEncodingException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
@@ -42,7 +42,7 @@ public class StringUtils {
|
||||
/** Converts the given byte array to a hex character array. */
|
||||
public static char[] toHexChars(byte[] bytes) {
|
||||
char[] hex = new char[bytes.length * 2];
|
||||
for(int i = 0, j = 0; i < bytes.length; i++) {
|
||||
for (int i = 0, j = 0; i < bytes.length; i++) {
|
||||
hex[j++] = HEX[(bytes[i] >> 4) & 0xF];
|
||||
hex[j++] = HEX[bytes[i] & 0xF];
|
||||
}
|
||||
@@ -57,9 +57,9 @@ public class StringUtils {
|
||||
/** Converts the given hex string to a byte array. */
|
||||
public static byte[] fromHexString(String hex) {
|
||||
int len = hex.length();
|
||||
if(len % 2 != 0) throw new IllegalArgumentException("Not a hex string");
|
||||
if (len % 2 != 0) throw new IllegalArgumentException("Not a hex string");
|
||||
byte[] bytes = new byte[len / 2];
|
||||
for(int i = 0, j = 0; i < len; i += 2, j++) {
|
||||
for (int i = 0, j = 0; i < len; i += 2, j++) {
|
||||
int high = hexDigitToInt(hex.charAt(i));
|
||||
int low = hexDigitToInt(hex.charAt(i + 1));
|
||||
bytes[j] = (byte) ((high << 4) + low);
|
||||
@@ -68,9 +68,9 @@ public class StringUtils {
|
||||
}
|
||||
|
||||
private static int hexDigitToInt(char c) {
|
||||
if(c >= '0' && c <= '9') return c - '0';
|
||||
if(c >= 'A' && c <= 'F') return c - 'A' + 10;
|
||||
if(c >= 'a' && c <= 'f') return c - 'a' + 10;
|
||||
if (c >= '0' && c <= '9') return c - '0';
|
||||
if (c >= 'A' && c <= 'F') return c - 'A' + 10;
|
||||
if (c >= 'a' && c <= 'f') return c - 'a' + 10;
|
||||
throw new IllegalArgumentException("Not a hex digit: " + c);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user