Beispiel #1
0
  static {
    Class<Object> clazz;

    logger = LoggerManager.getLogger(Base64.class.getName());

    try {
      clazz = (Class<Object>) Class.forName("android.util.Base64");
      // Looking for encode( byte[] input, int flags)
      aMethod = clazz.getMethod("encode", byte[].class, Integer.TYPE);
      logger.info(clazz.getName() + " is available.");
    } catch (ClassNotFoundException x) {
    } // Ignore
    catch (Exception x) {
      logger.error("Failed to initialize use of android.util.Base64", x);
    }

    try {
      clazz = (Class<Object>) Class.forName("org.bouncycastle.util.encoders.Base64Encoder");
      bEncoder = clazz.newInstance();
      // Looking for encode( byte[] input, int offset, int length, OutputStream output)
      bMethod =
          clazz.getMethod("encode", byte[].class, Integer.TYPE, Integer.TYPE, OutputStream.class);
      logger.info(clazz.getName() + " is available.");
    } catch (ClassNotFoundException x) {
    } // Ignore
    catch (Exception x) {
      logger.error("Failed to initialize use of org.bouncycastle.util.encoders.Base64Encoder", x);
    }

    if (aMethod == null && bMethod == null)
      throw new IllegalStateException("No base64 encoder implementation is available.");
  }