/** * 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); } } } }
Base64.decode(myBuffer, 0, nCopied, bos); } catch (IOException e) { throw new XMLStreamException("Could not decode base64 text.", e);
public static void encodeBytes(XMLStreamWriter writer, byte[] bytes) throws XMLStreamException { // TODO: Could be more efficient if we didn't make a String writer.writeCharacters( Base64.encode(bytes) ); }
/** * */ 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; }
/** * */ 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; }