protected void _decodeBase64(String str,ByteArrayBuilder builder,Base64Variant b64variant) throws IOException, JsonParseException {
  int ptr=0;
  int len=str.length();
  main_loop:   while (ptr < len) {
    char ch;
    do {
      ch=str.charAt(ptr++);
      if (ptr >= len) {
        break main_loop;
      }
    }
 while (ch <= INT_SPACE);
    int bits=b64variant.decodeBase64Char(ch);
    if (bits < 0) {
      _reportInvalidBase64(b64variant,ch,0,null);
    }
    int decodedData=bits;
    if (ptr >= len) {
      _reportBase64EOF();
    }
    ch=str.charAt(ptr++);
    bits=b64variant.decodeBase64Char(ch);
    if (bits < 0) {
      _reportInvalidBase64(b64variant,ch,1,null);
    }
    decodedData=(decodedData << 6) | bits;
    if (ptr >= len) {
      if (!b64variant.usesPadding()) {
        decodedData>>=4;
        builder.append(decodedData);
        break;
      }
      _reportBase64EOF();
    }
    ch=str.charAt(ptr++);
    bits=b64variant.decodeBase64Char(ch);
    if (bits < 0) {
      if (bits != Base64Variant.BASE64_VALUE_PADDING) {
        _reportInvalidBase64(b64variant,ch,2,null);
      }
      if (ptr >= len) {
        _reportBase64EOF();
      }
      ch=str.charAt(ptr++);
      if (!b64variant.usesPaddingChar(ch)) {
        _reportInvalidBase64(b64variant,ch,3,"expected padding character '" + b64variant.getPaddingChar() + "'");
      }
      decodedData>>=4;
      builder.append(decodedData);
      continue;
    }
    decodedData=(decodedData << 6) | bits;
    if (ptr >= len) {
      if (!b64variant.usesPadding()) {
        decodedData>>=2;
        builder.appendTwoBytes(decodedData);
        break;
      }
      _reportBase64EOF();
    }
    ch=str.charAt(ptr++);
    bits=b64variant.decodeBase64Char(ch);
    if (bits < 0) {
      if (bits != Base64Variant.BASE64_VALUE_PADDING) {
        _reportInvalidBase64(b64variant,ch,3,null);
      }
      decodedData>>=2;
      builder.appendTwoBytes(decodedData);
    }
 else {
      decodedData=(decodedData << 6) | bits;
      builder.appendThreeBytes(decodedData);
    }
  }
}

protected void _decodeBase64 ( String str , ByteArrayBuilder builder , Base64Variant b64variant ) throws IOException , JsonParseException { int ptr = 0 ; int len = str . length ( ) ; main_loop : while ( ptr < len ) { char ch ; do { ch = str . charAt ( ptr ++ ) ; if ( ptr >= len ) { break main_loop ; } } while ( ch <= INT_SPACE ) ; int bits = b64variant . decodeBase64Char ( ch ) ; if ( bits < 0 ) { _reportInvalidBase64 ( b64variant , ch , 0 , null ) ; } int decodedData = bits ; if ( ptr >= len ) { _reportBase64EOF ( ) ; } ch = str . charAt ( ptr ++ ) ; bits = b64variant . decodeBase64Char ( ch ) ; if ( bits < 0 ) { _reportInvalidBase64 ( b64variant , ch , 1 , null ) ; } decodedData = ( decodedData << 6 ) | bits ; if ( ptr >= len ) { if ( ! b64variant . usesPadding ( ) ) { decodedData >>= 4 ; builder . append ( decodedData ) ; break ; } _reportBase64EOF ( ) ; } ch = str . charAt ( ptr ++ ) ; bits = b64variant . decodeBase64Char ( ch ) ; if ( bits < 0 ) { if ( bits != Base64Variant . BASE64_VALUE_PADDING ) { _reportInvalidBase64 ( b64variant , ch , 2 , null ) ; } if ( ptr >= len ) { _reportBase64EOF ( ) ; } ch = str . charAt ( ptr ++ ) ; if ( ! b64variant . usesPaddingChar ( ch ) ) { _reportInvalidBase64 ( b64variant , ch , 3 , "expected padding character '" + b64variant . getPaddingChar ( ) + "'" ) ; } decodedData >>= 4 ; builder . append ( decodedData ) ; continue ; } decodedData = ( decodedData << 6 ) | bits ; if ( ptr >= len ) { if ( ! b64variant . usesPadding ( ) ) { decodedData >>= 2 ; builder . appendTwoBytes ( decodedData ) ; break ; } _reportBase64EOF ( ) ; } ch = str . charAt ( ptr ++ ) ; bits = b64variant . decodeBase64Char ( ch ) ; if ( bits < 0 ) { if ( bits != Base64Variant . BASE64_VALUE_PADDING ) { _reportInvalidBase64 ( b64variant , ch , 3 , null ) ; } decodedData >>= 2 ; builder . appendTwoBytes ( decodedData ) ; } else { decodedData = ( decodedData << 6 ) | bits ; builder . appendThreeBytes ( decodedData ) ; } } }
helper method that can be used for base64 decoding in cases where encoded content has already been read as a string .
