MCPcopy Create free account
hub / github.com/aboutcode-org/scancode-toolkit / decode

Method decode

samples/JGroups/src/S3_PING.java:2290–2329  ·  view source on GitHub ↗

Very low-level access to decoding ASCII characters in the form of a byte array. Does not support automatically gunzipping or any other "fancy" features. @param source The Base64 encoded data @param off The offset of where to begin decoding @param len The length of characters to decode @return

(byte[] source, int off, int len)

Source from the content-addressed store, hash-verified

2288 * @since 1.3
2289 */
2290 public static byte[] decode(byte[] source, int off, int len) {
2291 int len34=len * 3 / 4;
2292 byte[] outBuff=new byte[len34]; // Upper limit on size of output
2293 int outBuffPosn=0;
2294
2295 byte[] b4=new byte[4];
2296 int b4Posn=0;
2297 int i=0;
2298 byte sbiCrop=0;
2299 byte sbiDecode=0;
2300 for(i=off; i < off + len; i++) {
2301 sbiCrop=(byte)(source[i] & 0x7f); // Only the low seven bits
2302 sbiDecode=DECODABET[sbiCrop];
2303
2304 if(sbiDecode >= WHITE_SPACE_ENC) // White space, Equals sign or better
2305 {
2306 if(sbiDecode >= EQUALS_SIGN_ENC) {
2307 b4[b4Posn++]=sbiCrop;
2308 if(b4Posn > 3) {
2309 outBuffPosn+=decode4to3(b4, 0, outBuff, outBuffPosn);
2310 b4Posn=0;
2311
2312 // If that was the equals sign, break out of 'for' loop
2313 if(sbiCrop == EQUALS_SIGN)
2314 break;
2315 } // end if: quartet built
2316
2317 } // end if: equals sign or better
2318
2319 } // end if: white space, equals sign or better
2320 else {
2321 System.err.println("Bad Base64 input character at " + i + ": " + source[i] + "(decimal)");
2322 return null;
2323 } // end else:
2324 } // each input character
2325
2326 byte[] out=new byte[outBuffPosn];
2327 System.arraycopy(outBuff, 0, out, 0, outBuffPosn);
2328 return out;
2329 } // end decode
2330
2331
2332 /**

Callers 15

decodeToObjectMethod · 0.95
check_aboutFunction · 0.45
get_test_method_nameMethod · 0.45
scancode_config.pyFile · 0.45
Z_checksum_handlerFunction · 0.45
read_stringMethod · 0.45
prettyFunction · 0.45
write_spdxFunction · 0.45
return_unicodeFunction · 0.45
as_unicodeFunction · 0.45
extract_ascii_stringsFunction · 0.45
extract_unicode_stringsFunction · 0.45

Calls 4

decode4to3Method · 0.95
readMethod · 0.45
writeMethod · 0.45
closeMethod · 0.45

Tested by 1

get_test_method_nameMethod · 0.36