/** * Returns base64 representation of specified byte array. */ public static String encode(byte[] data) { return encode(data, 0, data.length); }
/** */ public static void decode(char[] data, int off, int len, OutputStream ostream) throws IOException { char[] ibuf = new char[4]; int ibufcount = 0; byte[] obuf = new byte[3]; for (int i = off; i < (off + len); i++) { char ch = data[i]; if ((ch == S_BASE64PAD) || ((ch < S_DECODETABLE.length) && (S_DECODETABLE[ch] != Byte.MAX_VALUE))) { ibuf[ibufcount++] = ch; if (ibufcount == ibuf.length) { ibufcount = 0; int obufcount = decode0(ibuf, obuf, 0); ostream.write(obuf, 0, obufcount); } } } }
} else if (content.get(0).containsKey("hash")) { String base64Hash = ((Map<String, String>) content.get(0).get("hash")).get("BYTES_VALUE"); byte[] hash = Base64.decode(base64Hash); ServerGroupComponent sgc = (ServerGroupComponent) context.getParentResourceComponent(); String baseDir = ((HostControllerComponent) sgc.context.getParentResourceComponent()).pluginConfiguration } else if (content.get(0).containsKey("hash")) { String base64Hash = ((Map<String, String>) content.get(0).get("hash")).get("BYTES_VALUE"); byte[] hash = Base64.decode(base64Hash); Address contentPathAddress; if (context.getParentResourceComponent() instanceof ManagedASComponent) {
private synchronized String generateAgentToken() { if (random == null) { try { random = SecureRandom.getInstance("SHA1PRNG"); } catch (NoSuchAlgorithmException e) { throw new RuntimeException("Could not load SecureRandom algorithm", e); } } byte[] tokenBytes = new byte[50]; random.nextBytes(tokenBytes); return Base64.encode(tokenBytes); }
/** */ public static byte[] decode(char[] data, int off, int len) { char[] ibuf = new char[4]; int ibufcount = 0; byte[] obuf = new byte[(len / 4 * 3) + 3]; int obufcount = 0; for (int i = off; i < (off + len); i++) { char ch = data[i]; if ((ch == S_BASE64PAD) || ((ch < S_DECODETABLE.length) && (S_DECODETABLE[ch] != Byte.MAX_VALUE))) { ibuf[ibufcount++] = ch; if (ibufcount == ibuf.length) { ibufcount = 0; obufcount += decode0(ibuf, obuf, obufcount); } } } if (obufcount == obuf.length) { return obuf; } byte[] ret = new byte[obufcount]; System.arraycopy(obuf, 0, ret, 0, obufcount); return ret; }
/** * @see org.apache.tools.ant.Task#execute() */ public void execute() throws BuildException { validateAttributes(); MessageDigest message_digest; try { message_digest = MessageDigest.getInstance("MD5"); } catch (NoSuchAlgorithmException e) { throw new BuildException(e); // should never occur; this would be bad - JRE has this builtin } byte[] md5_bytes = message_digest.digest(value.getBytes()); String md5; if (base64) { md5 = Base64.encode(md5_bytes); } else { // put the md5 bytes in string form StringBuilder md5_string = new StringBuilder(md5_bytes.length * 2); for (byte md5_byte : md5_bytes) { int hi = (md5_byte >> 4) & 0xf; int lo = md5_byte & 0xf; md5_string.append(Character.forDigit(hi, 16)); md5_string.append(Character.forDigit(lo, 16)); } md5 = md5_string.toString(); } Project this_project = getProject(); this_project.setNewProperty(property, md5); return; }
/** */ public static void decode(String data, OutputStream ostream) throws IOException { char[] ibuf = new char[4]; int ibufcount = 0; byte[] obuf = new byte[3]; for (int i = 0; i < data.length(); i++) { char ch = data.charAt(i); if ((ch == S_BASE64PAD) || ((ch < S_DECODETABLE.length) && (S_DECODETABLE[ch] != Byte.MAX_VALUE))) { ibuf[ibufcount++] = ch; if (ibufcount == ibuf.length) { ibufcount = 0; int obufcount = decode0(ibuf, obuf, 0); ostream.write(obuf, 0, obufcount); } } } }
/** */ public static byte[] decode(String data) { char[] ibuf = new char[4]; int ibufcount = 0; byte[] obuf = new byte[(data.length() / 4 * 3) + 3]; int obufcount = 0; for (int i = 0; i < data.length(); i++) { char ch = data.charAt(i); if ((ch == S_BASE64PAD) || ((ch < S_DECODETABLE.length) && (S_DECODETABLE[ch] != Byte.MAX_VALUE))) { ibuf[ibufcount++] = ch; if (ibufcount == ibuf.length) { ibufcount = 0; obufcount += decode0(ibuf, obuf, obufcount); } } } if (obufcount == obuf.length) { return obuf; } byte[] ret = new byte[obufcount]; System.arraycopy(obuf, 0, ret, 0, obufcount); return ret; }