Source:
public void writeString(String value, Function<Integer, Byte> leadingOrdinalGenerator) throws IOException { final int leadingOrdinalLength = (leadingOrdinalGenerator == null) ? 0 : 1; final int maxLength = value.length() * 3; final int maxLengthVarIntSize = computeUInt32Size(maxLength); if (maxLengthVarIntSize + maxLength + leadingOrdinalLength > _limit) { final byte[] encodedBytes = new byte[maxLength]; int actualLength = Utf8Utils.encode(value, encodedBytes, 0, maxLength); if (leadingOrdinalGenerator != null) { writeByte(leadingOrdinalGenerator.apply(actualLength)); } writeUInt32(actualLength); writeBytes(encodedBytes, 0, actualLength); return; } if (maxLengthVarIntSize + maxLength + leadingOrdinalLength > _limit - _position) { flush(); } final int oldPosition = _position; try { final int minLengthVarIntSize = computeUInt32Size(value.length()); if (minLengthVarIntSize == maxLengthVarIntSize) { _position = oldPosition + leadingOrdinalLength + minLengthVarIntSize; int newPosition = Utf8Utils.encode(value, _buffer, _position, _limit - _position); _position = oldPosition; int length = newPosition - oldPosition - leadingOrdinalLength - minLengthVarIntSize; if (leadingOrdinalGenerator != null) { writeByte(leadingOrdinalGenerator.apply(length)); } bufferUInt32(length); _position = newPosition; } else { int length = Utf8Utils.encodedLength(value); if (leadingOrdinalGenerator != null) { writeByte(leadingOrdinalGenerator.apply(length)); } bufferUInt32(length); _position = Utf8Utils.encode(value, _buffer, _position, length); } } catch (IllegalArgumentException e) { throw new IOException(e); } catch (IndexOutOfBoundsException e) { throw new EOFException(String.format("Pos: %d, limit: %d, len: %d", _position, _limit, 1)); } }

Target:
public void writeString(String value, Function<Integer, Byte> leadingOrdinalGenerator) throws IOException { final int leadingOrdinalLength = (leadingOrdinalGenerator == null) ? 0 : 1; final int maxLength = value.length() * 3; final int maxLengthVarIntSize = computeUInt32Size(maxLength); if (maxLengthVarIntSize + maxLength + leadingOrdinalLength > _limit) { final byte[] encodedBytes = new byte[maxLength]; int actualLength = Utf8Utils.encode(value, encodedBytes, 0, maxLength); if (leadingOrdinalGenerator != null) { writeByte(leadingOrdinalGenerator.apply(actualLength)); } writeUInt32(actualLength); writeBytes(encodedBytes, 0, actualLength); return; } if (maxLengthVarIntSize + maxLength + leadingOrdinalLength > _limit - _position) { flush(); } final int oldPosition = _position; try { final int minLengthVarIntSize = computeUInt32Size(value.length()); if (minLengthVarIntSize == maxLengthVarIntSize) { _position = oldPosition + leadingOrdinalLength + minLengthVarIntSize; int newPosition = Utf8Utils.encode(value, _buffer, _position, _limit - _position); _position = oldPosition; int length = newPosition - oldPosition - leadingOrdinalLength - minLengthVarIntSize; if (leadingOrdinalGenerator != null) { buffer(leadingOrdinalGenerator.apply(length)); } bufferUInt32(length); _position = newPosition; } else { int length = Utf8Utils.encodedLength(value); if (leadingOrdinalGenerator != null) { buffer(leadingOrdinalGenerator.apply(length)); } bufferUInt32(length); _position = Utf8Utils.encode(value, _buffer, _position, length); } } catch (IllegalArgumentException e) { throw new IOException(e); } catch (IndexOutOfBoundsException e) { throw new EOFException(String.format("Pos: %d, limit: %d, len: %d", _position, _limit, 1)); } }