ByteUtil { public static void replace(final byte[] buffer, final int offset, final int length, final byte target, final byte replacement) { for (int i = 0; i < length; i++) { int location = i + offset; if (target == buffer[location]) { buffer[location] = replacement; } } }  static void writeLongAsAscii(final byte[] outputBuffer, final int offset, final long valueParam); static boolean isAsciiDigit(final byte asciiCharacter); static String formatIntAsIpAddress(final int address); static void formatIntAsIpAddress(final StringBuilder buffer, final int address); static long packLongWithUnsignedShortInts(final int int1, final int int2, final int int3, final int int4); static boolean isEqual(final byte[] lhs, final int lhsOffset, final byte[] rhs, final int rhsOffset, final int length); static int readIntFromAscii(final byte[] asciiBuffer, final int offset, final int length); static long readLongFromAscii(final byte[] asciiBuffer, final int offset, final int length); static boolean isInteger(final byte[] asciiBuffer, final int offset, final int length); static void replace(final byte[] buffer, final int offset, final int length,
                               final byte target, final byte replacement); static void asciiEncode(final CharSequence chars, final int charOffset,
                                   final byte[] buffer, final int bufferOffset, final int length); static final int MAX_UNSIGNED_SHORT; }
@Test public void shouldReplaceSohWithBar() throws Exception { final byte[] source = "A test string \u0001 containing \u0001 ASCII SOH\u0001".getBytes(StandardCharsets.US_ASCII); final byte[] expected = "A test string | containing | ASCII SOH|".getBytes(StandardCharsets.US_ASCII); final byte soh = (byte) 1; final byte bar = (byte) 124; ByteUtil.replace(source, 0, source.length, soh, bar); Assert.assertArrayEquals(expected, source); }