docs: public static byte[] encode(final byte[] source, final int off, final int len, final int options) {
          if (source == null) {
              throw new NullPointerException("Cannot serialize a null array.");
          }   // end if: null
  
          if (off < 0) {
              throw new IllegalArgumentException("Cannot have negative offset: " + off);
          }   // end if: off < 0
  
          if (len < 0) {
              throw new IllegalArgumentException("Cannot have length offset: " + len);
          }   // end if: len < 0
  
          if (off + len > source.length) {
              throw new IllegalArgumentException(String.format(
                      "Cannot have offset of %d and length of %d with array of length %d",
                      off,
                      len,
                      source.length));
          }   // end if: off < 0
  
          if (len == 0) {
              return new byte[0];
          }
  
          final boolean breakLines = (options & (Base64.NO_WRAP)) == 0;
          final boolean crlf = (options & Base64.CRLF) != 0;
          final boolean noPadding = (options & (Base64.NO_PADDING)) != 0;
          final byte[] alphabet = getAlphabet(options);
  
          //int    len43   = len * 4 / 3;
          //byte[] outBuff = new byte[   ( len43 )                      // Main 4:3
          //                           + ( (len % 3) > 0 ? 4 : 0 )      // Account for padding
          //                           + (breakLines ? ( len43 / MAX_LINE_LENGTH ) : 0) ]; // New lines
          // Try to determine more precisely how big the array needs to be.
          // If we get it right, we don't have to do an array copy, and
          // we save a bunch of memory.
          int bufLen = (len / 3) * 4 + (len % 3 > 0 ? 4 : 0); // Bytes needed for actual encoding
          if (breakLines) {
              int lines = bufLen / MAX_LINE_LENGTH; // Plus extra newline characters
              bufLen += crlf ? lines * 2 : lines;
          }
  
  
          byte[] dest = new byte[bufLen];
  
          int srcPos = 0;
          int destPos = 0;
          int lineLength = 0;
          final int len2 = len - 2;
          for (; srcPos < len2; srcPos += 3) {
              if (breakLines && lineLength >= MAX_LINE_LENGTH) {
                  if (crlf) {
                      dest[destPos++] = CR;
                  }
                  dest[destPos++] = LF;
                  lineLength = 0;
              }
  
              int l = encode3to4(source, srcPos + off, 3, dest, destPos, noPadding, alphabet);
  
              destPos += l;
              lineLength += l;
          }   // end for: each piece of array
  
          if (srcPos < len) {
              if (breakLines && lineLength >= MAX_LINE_LENGTH) {
                  if (crlf) {
                      dest[destPos++] = CR;
                  }
                  dest[destPos++] = LF;
              }
              destPos += encode3to4(source, srcPos + off, len - srcPos, dest, destPos, noPadding, alphabet);
          }   // end if: some padding needed
  
          // Only resize array if we didn't guess it right.
          if (destPos < dest.length) {
              // If breaking lines and the last byte falls right at
              // the line length (76 bytes per line), there will be
              // one extra byte, and the array will need to be resized.
              // Not too bad of an estimate on array size, I'd say.
              byte[] finalOut = new byte[destPos];
              System.arraycopy(dest, 0, finalOut, 0, destPos);
              return finalOut;
          } else {
              return dest;
          }
  
      }