Ascii85 { public static String encode(byte[] payload) { if (payload == null || payload.length == 0) { throw new IllegalArgumentException("You must provide a non-zero length input"); } StringBuilder stringBuff = new StringBuilder(payload.length * 5 / 4); byte[] chunk = new byte[4]; int chunkIndex = 0; for (int i = 0; i < payload.length; i++) { byte currByte = payload[i]; chunk[chunkIndex++] = currByte; if (chunkIndex == 4) { int value = byteToInt(chunk); if (value == 0) { stringBuff.append('z'); } else { stringBuff.append(encodeChunk(value)); } Arrays.fill(chunk, (byte) 0); chunkIndex = 0; } } if (chunkIndex > 0) { int numPadded = chunk.length - chunkIndex; Arrays.fill(chunk, chunkIndex, chunk.length, (byte) 0); int value = byteToInt(chunk); char[] encodedChunk = encodeChunk(value); for (int i = 0; i < encodedChunk.length - numPadded; i++) { stringBuff.append(encodedChunk[i]); } } return stringBuff.toString(); } private  Ascii85(); static String encode(byte[] payload); static byte[] decode(String chars);  }
@Test public void testEncode() { assertEquals("<+oue+DGm>@3BZ'F*%", Ascii85.encode("This is a test".getBytes())); assertEquals(";f?Ma+E)@8ATAo8ATMr9G%#30AH", Ascii85.encode("Some other test value".getBytes())); }