/** * Decodes a byte array from Base64 format. * No blanks or line breaks are allowed within the Base64 encoded input data. * @param in A character array containing the Base64 encoded data. * @return An array containing the decoded data bytes. * @throws IllegalArgumentException If the input is not valid Base64 encoded data. */ public static byte[] decode (char[] in) { return decode(in, 0, in.length); }
/** * Encodes a byte array into Base64 format. * No blanks or line breaks are inserted in the output. * @param in An array containing the data bytes to be encoded. * @return A character array containing the Base64 encoded data. */ public static char[] encode (byte[] in) { return encode(in, 0, in.length); }
/** * Encodes a byte array into Base 64 format and breaks the output into lines of 76 characters. * This method is compatible with <code>sun.misc.BASE64Encoder.encodeBuffer(byte[])</code>. * @param in An array containing the data bytes to be encoded. * @return A String containing the Base64 encoded data, broken into lines. */ public static String encodeLines (byte[] in) { return encodeLines(in, 0, in.length, 76, systemLineSeparator); }
public static String getProfileURL(Object profile) { String url = null; if (profile == null) { return null; } try { @SuppressWarnings("unchecked") Multimap<String, Object> properties = (Multimap<String, Object>)class_GameProfile_properties.get(profile); Collection<Object> textures = properties.get("textures"); if (textures != null && textures.size() > 0) { Object textureProperty = textures.iterator().next(); String texture = (String)class_GameProfileProperty_value.get(textureProperty); String decoded = Base64Coder.decodeString(texture); url = getTextureURL(decoded); } } catch (Exception ex) { ex.printStackTrace(); } return url; }
public static void setSkullURL(ItemStack itemStack, URL url, UUID id) { try { Object skullOwner = createNode(itemStack, "SkullOwner"); setMeta(skullOwner, "Id", id.toString()); Object properties = createNode(skullOwner, "Properties"); Object listMeta = class_NBTTagList_constructor.newInstance(); Object textureNode = class_NBTTagCompound_constructor.newInstance(); String textureJSON = "{textures:{SKIN:{url:\"" + url + "\"}}}"; String encoded = Base64Coder.encodeString(textureJSON); setMeta(textureNode, "Value", encoded); class_NBTTagList_addMethod.invoke(listMeta, textureNode); class_NBTTagCompound_setMethod.invoke(properties, "textures", listMeta); } catch (Exception ex) { ex.printStackTrace(); } }
return; String decodedTextures = Base64Coder.decodeString(encodedTextures); if (DEBUG) plugin.getLogger().info("Decoded textures: " + decodedTextures); String skinURL = getTextureURL(decodedTextures);
String pageText = pages.get(0); try { String decoded = Base64Coder.decodeString(pageText); if (decoded == null || decoded.isEmpty()) { player.sendMessage(api.getMessages().get("item.skull_invalid_book"));
/** * Encodes a byte array into Base64 format. * No blanks or line breaks are inserted in the output. * @param in An array containing the data bytes to be encoded. * @param iLen Number of bytes to process in <code>in</code>. * @return A character array containing the Base64 encoded data. */ public static char[] encode (byte[] in, int iLen) { return encode(in, 0, iLen); }
/** * Decodes a string from Base64 format. * No blanks or line breaks are allowed within the Base64 encoded input data. * @param s A Base64 String to be decoded. * @return A String containing the decoded data. * @throws IllegalArgumentException If the input is not valid Base64 encoded data. */ public static String decodeString (String s) { return new String(decode(s), StandardCharsets.UTF_8); }
/** * Encodes a string into Base64 format. * No blanks or line breaks are inserted. * @param s A String to be encoded. * @return A String containing the Base64 encoded data. */ public static String encodeString (String s) { return new String(encode(s.getBytes(StandardCharsets.UTF_8))); }
/** * Decodes a byte array from Base64 format. * No blanks or line breaks are allowed within the Base64 encoded input data. * @param s A Base64 String to be decoded. * @return An array containing the decoded data bytes. * @throws IllegalArgumentException If the input is not valid Base64 encoded data. */ public static byte[] decode (String s) { return decode(s.toCharArray()); }
/** * Encodes a byte array into Base 64 format and breaks the output into lines. * @param in An array containing the data bytes to be encoded. * @param iOff Offset of the first byte in <code>in</code> to be processed. * @param iLen Number of bytes to be processed in <code>in</code>, starting at <code>iOff</code>. * @param lineLen Line length for the output data. Should be a multiple of 4. * @param lineSeparator The line separator to be used to separate the output lines. * @return A String containing the Base64 encoded data, broken into lines. */ public static String encodeLines (byte[] in, int iOff, int iLen, int lineLen, String lineSeparator) { int blockLen = (lineLen*3) / 4; if (blockLen <= 0) throw new IllegalArgumentException(); int lines = (iLen+blockLen-1) / blockLen; int bufLen = ((iLen+2)/3)*4 + lines*lineSeparator.length(); StringBuilder buf = new StringBuilder(bufLen); int ip = 0; while (ip < iLen) { int l = Math.min(iLen-ip, blockLen); buf.append(encode(in, iOff+ip, l)); buf.append(lineSeparator); ip += l; } return buf.toString(); }
/** * Decodes a byte array from Base64 format and ignores line separators, tabs and blanks. * CR, LF, Tab and Space characters are ignored in the input data. * This method is compatible with <code>sun.misc.BASE64Decoder.decodeBuffer(String)</code>. * @param s A Base64 String to be decoded. * @return An array containing the decoded data bytes. * @throws IllegalArgumentException If the input is not valid Base64 encoded data. */ public static byte[] decodeLines (String s) { char[] buf = new char[s.length()]; int p = 0; for (int ip = 0; ip < s.length(); ip++) { char c = s.charAt(ip); if (c != ' ' && c != '\r' && c != '\n' && c != '\t') buf[p++] = c; } return decode(buf, 0, p); }