Here you can find the source of fromBase64(String s)
Parameter | Description |
---|---|
s | a String representation of a base 64 number |
public static long fromBase64(String s)
//package com.java2s; /*//from w w w . ja v a2s .c om Copyright 1996-2008 Ariba, Inc. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. $Id: //ariba/platform/util/core/ariba/util/core/MathUtil.java#11 $ */ public class Main { private static final int AlphabetSize = 26; private static final int AlphabetSizeTimesTwo = 52; private static final int Base64 = 64; /** Convert a string representation of a base64 number into a long. @param s a String representation of a base 64 number @return long the number as a long; -1 in case the string s contains a character not present in the base64 character set @aribaapi documented */ public static long fromBase64(String s) { return fromBase64(s, 0, s.length() - 1); } /** Convert a string representation of a base64 number into a long. @param s a String containing a representation of a base 64 number @param offset the offset of the first character in the string to start begin parsing at. @return long the number as a long; -1 in case the string s contains a character not present in the base64 character set @aribaapi documented */ public static long fromBase64(String s, int offset) { return fromBase64(s, offset, s.length() - 1); } /** Convert a string representation of a base64 number into a long. @param s a String containing a representation of a base 64 number @param beginIndex the offset of the first character in the string to parse (inclusive). @param endIndex the offset of the last character in the string to parse (inclusive). @return long the number as a long; -1 in case the string s contains a character not present in the base64 character set @aribaapi documented */ public static long fromBase64(String s, int beginIndex, int endIndex) { long sum = 0; for (int i = beginIndex; i <= endIndex; i++) { char c = s.charAt(i); int digit; if (c >= 'A' && c <= 'Z') { digit = c - 'A'; } else if (c >= 'a' && c <= 'z') { digit = c - 'a' + AlphabetSize; } else if (c >= '0' && c <= '9') { digit = c - '0' + AlphabetSizeTimesTwo; } else if (c == '+') { digit = 62; } else if (c == '!') { digit = 63; } else { return -1; } sum = (sum * Base64) + digit; } return sum; } }