public static byte[] encode(byte[] input, int offset, int len, int flags) {
    Encoder encoder = new Encoder(flags, null);

    // Compute the exact length of the array we will produce.
    int outputLen = len / 3 * 4;

    // Account for the tail of the data and the padding bytes, if any.
    if (encoder.doPadding) {
      if (len % 3 > 0) {
        outputLen += 4;
      }
    } else {
      switch (len % 3) {
        case 0:
          break;
        case 1:
          outputLen += 2;
          break;
        case 2:
          outputLen += 3;
          break;
        default:
          break;
      }
    }

    // Account for the newlines, if any.
    if (encoder.doNewline && len > 0) {
      outputLen += (((len - 1) / (3 * Encoder.LINE_GROUPS)) + 1) * (encoder.doCr ? 2 : 1);
    }

    encoder.output = new byte[outputLen];
    encoder.process(input, offset, len, true);

    assert encoder.op == outputLen;

    return encoder.output;
  }
Base64-encode the given data and return a newly allocated byte[] with the result.

@param input the data to encode
@param offset the position within the input array at which to start
@param len the number of bytes of input to encode
@param flags controls certain features of the encoded output. Passing {@code DEFAULT} results
    in output that adheres to RFC 2045.
java_src/src/main/java/com/google/crypto/tink/subtle/Base64.java