@Test public void testByteStringToArray() { assertArrayEquals(new byte[]{}, Bencode.byteStringToArray("")); assertArrayEquals(new byte[]{10}, Bencode.byteStringToArray("\n")); assertArrayEquals(new byte[]{'C','o','D','e'}, Bencode.byteStringToArray("CoDe")); assertArrayEquals(new byte[]{-1,-128,127}, Bencode.byteStringToArray("\u00FF\u0080\u007F")); }
public static byte[] byteStringToArray(String str) { byte[] result = new byte[str.length()]; for (int i = 0; i < str.length(); i++) { char c = str.charAt(i); if (c > 0xFF) throw new IllegalArgumentException("Character value outside of byte range"); result[i] = (byte)c; } return result; }
Bencode { public static byte[] byteStringToArray(String str) { byte[] result = new byte[str.length()]; for (int i = 0; i < str.length(); i++) { char c = str.charAt(i); if (c > 0xFF) throw new IllegalArgumentException("Character value outside of byte range"); result[i] = (byte)c; } return result; } }
Bencode { public static byte[] byteStringToArray(String str) { byte[] result = new byte[str.length()]; for (int i = 0; i < str.length(); i++) { char c = str.charAt(i); if (c > 0xFF) throw new IllegalArgumentException("Character value outside of byte range"); result[i] = (byte)c; } return result; } private  Bencode(InputStream in); }
Bencode { public static byte[] byteStringToArray(String str) { byte[] result = new byte[str.length()]; for (int i = 0; i < str.length(); i++) { char c = str.charAt(i); if (c > 0xFF) throw new IllegalArgumentException("Character value outside of byte range"); result[i] = (byte)c; } return result; } private  Bencode(InputStream in); static void serialize(Object obj, OutputStream out); static Object parse(InputStream in); static byte[] byteStringToArray(String str); static String arrayToByteString(byte[] arr); }
Bencode { public static byte[] byteStringToArray(String str) { byte[] result = new byte[str.length()]; for (int i = 0; i < str.length(); i++) { char c = str.charAt(i); if (c > 0xFF) throw new IllegalArgumentException("Character value outside of byte range"); result[i] = (byte)c; } return result; } private  Bencode(InputStream in); static void serialize(Object obj, OutputStream out); static Object parse(InputStream in); static byte[] byteStringToArray(String str); static String arrayToByteString(byte[] arr);  }