2020/**
2121 * Provides Base32 encoding and decoding as defined by RFC 4648.
2222 *
23- * <b>Initial implementation. API may change. Incomplete.</b>
24- *
2523 * <p>
2624 * The class can be parameterized in the following manner with various constructors:
2725 * <ul>
26+ * <li>Whether to use the "base32hex" variant instead of the default "base32"</li>
2827 * <li>Line length: Default 76. Line length that aren't multiples of 8 will still essentially end up being multiples of
2928 * 8 in the encoded data.
30- *
3129 * <li>Line separator: Default is CRLF ("\r\n")</li>
3230 * </ul>
3331 * </p>
3432 * <p>
35- * Since this class operates directly on byte streams, and not character streams, it is hard-coded to only encode/decode
36- * character encodings which are compatible with the lower 127 ASCII chart (ISO-8859-1, Windows-1252, UTF-8, etc).
33+ * This class operates directly on byte streams, and not character streams.
3734 * </p>
3835 *
3936 * @see <a href="http://www.ietf.org/rfc/rfc4648.txt">RFC 4648</a>
@@ -48,7 +45,7 @@ public class Base32 extends BaseNCodec {
4845 * They are formed by taking a block of five octets to form a 40-bit string,
4946 * which is converted into eight BASE32 characters.
5047 */
51- private static final int BITS_PER_ENCODED_CHAR = 5 ;
48+ private static final int BITS_PER_ENCODED_BYTE = 5 ;
5249 private static final int BYTES_PER_UNENCODED_BLOCK = 5 ;
5350 private static final int BYTES_PER_ENCODED_BLOCK = 8 ;
5451
@@ -338,7 +335,7 @@ void encode(byte[] in, int inPos, int inAvail) { // package protected for access
338335 } else {
339336 for (int i = 0 ; i < inAvail ; i ++) {
340337 ensureBufferSize (encodeSize );
341- modulus = (++modulus ) % BITS_PER_ENCODED_CHAR ;
338+ modulus = (++modulus ) % BITS_PER_ENCODED_BYTE ;
342339 int b = in [inPos ++];
343340 if (b < 0 ) {
344341 b += 256 ;
@@ -404,7 +401,7 @@ void decode(byte[] in, int inPos, int inAvail) { // package protected for access
404401 int result = this .decodeTable [b ];
405402 if (result >= 0 ) {
406403 modulus = (++modulus ) % BYTES_PER_ENCODED_BLOCK ;
407- bitWorkArea = (bitWorkArea << BITS_PER_ENCODED_CHAR ) + result ; // collect decoded bytes
404+ bitWorkArea = (bitWorkArea << BITS_PER_ENCODED_BYTE ) + result ; // collect decoded bytes
408405 if (modulus == 0 ) { // we can output the 5 bytes
409406 buffer [pos ++] = (byte ) ((bitWorkArea >> 32 ) & MASK_8BITS );
410407 buffer [pos ++] = (byte ) ((bitWorkArea >> 24 ) & MASK_8BITS );
0 commit comments