@Test public void testIllegalArgument() { byte[] errorBytes = {0x01}; assertThrows(IllegalArgumentException.class, () -> ByteUtils.unescape(errorBytes)); }
public static byte[] unescape(byte[] in) { int escapeCount = 0; for (int i = 0; i < in.length; i++) { if (in[i] == 0x01) { escapeCount++; i++; } } if (escapeCount == 0) return in; byte[] ret = new byte[in.length - escapeCount]; int index = 0; for (int i = 0; i < in.length; i++) { if (in[i] == 0x01) { i++; if (i >= in.length) { throw new IllegalArgumentException("Bad bytes when attempting to unescape. Expected " + "more bytes after last byte " + String.format("x%02x", in[in.length - 1])); } ret[index++] = (byte) (in[i] - 1); } else { ret[index++] = in[i]; } } return ret; }
ByteUtils { public static byte[] unescape(byte[] in) { int escapeCount = 0; for (int i = 0; i < in.length; i++) { if (in[i] == 0x01) { escapeCount++; i++; } } if (escapeCount == 0) return in; byte[] ret = new byte[in.length - escapeCount]; int index = 0; for (int i = 0; i < in.length; i++) { if (in[i] == 0x01) { i++; if (i >= in.length) { throw new IllegalArgumentException("Bad bytes when attempting to unescape. Expected " + "more bytes after last byte " + String.format("x%02x", in[in.length - 1])); } ret[index++] = (byte) (in[i] - 1); } else { ret[index++] = in[i]; } } return ret; } }
ByteUtils { public static byte[] unescape(byte[] in) { int escapeCount = 0; for (int i = 0; i < in.length; i++) { if (in[i] == 0x01) { escapeCount++; i++; } } if (escapeCount == 0) return in; byte[] ret = new byte[in.length - escapeCount]; int index = 0; for (int i = 0; i < in.length; i++) { if (in[i] == 0x01) { i++; if (i >= in.length) { throw new IllegalArgumentException("Bad bytes when attempting to unescape. Expected " + "more bytes after last byte " + String.format("x%02x", in[in.length - 1])); } ret[index++] = (byte) (in[i] - 1); } else { ret[index++] = in[i]; } } return ret; }  }
ByteUtils { public static byte[] unescape(byte[] in) { int escapeCount = 0; for (int i = 0; i < in.length; i++) { if (in[i] == 0x01) { escapeCount++; i++; } } if (escapeCount == 0) return in; byte[] ret = new byte[in.length - escapeCount]; int index = 0; for (int i = 0; i < in.length; i++) { if (in[i] == 0x01) { i++; if (i >= in.length) { throw new IllegalArgumentException("Bad bytes when attempting to unescape. Expected " + "more bytes after last byte " + String.format("x%02x", in[in.length - 1])); } ret[index++] = (byte) (in[i] - 1); } else { ret[index++] = in[i]; } } return ret; }  static byte[] escape(byte[] in); static byte[] unescape(byte[] in); static byte[][] split(byte[] data); static byte[][] split(byte[] data, int dataOffset, int len); static byte[] concat(byte[]... fields); }
ByteUtils { public static byte[] unescape(byte[] in) { int escapeCount = 0; for (int i = 0; i < in.length; i++) { if (in[i] == 0x01) { escapeCount++; i++; } } if (escapeCount == 0) return in; byte[] ret = new byte[in.length - escapeCount]; int index = 0; for (int i = 0; i < in.length; i++) { if (in[i] == 0x01) { i++; if (i >= in.length) { throw new IllegalArgumentException("Bad bytes when attempting to unescape. Expected " + "more bytes after last byte " + String.format("x%02x", in[in.length - 1])); } ret[index++] = (byte) (in[i] - 1); } else { ret[index++] = in[i]; } } return ret; }  static byte[] escape(byte[] in); static byte[] unescape(byte[] in); static byte[][] split(byte[] data); static byte[][] split(byte[] data, int dataOffset, int len); static byte[] concat(byte[]... fields);  }