(String s)
| 140 | } |
| 141 | |
| 142 | private static ByteArrayOutputStream baosFromBase64(String s) { |
| 143 | int padding=0; |
| 144 | int ibuf=1; |
| 145 | ByteArrayOutputStream baos=new ByteArrayOutputStream(2048); |
| 146 | for (int i=0; i<s.length(); i++) { |
| 147 | int nextChar = s.charAt(i); |
| 148 | //if( nextChar == -1 ) |
| 149 | // throw new EndOfXMLException(); |
| 150 | int base64=-1; |
| 151 | if (nextChar>'A'-1 && nextChar<'Z'+1) base64=nextChar-'A'; |
| 152 | else if (nextChar>'a'-1 && nextChar<'z'+1) base64=nextChar+26-'a'; |
| 153 | else if (nextChar>'0'-1 && nextChar<'9'+1) base64=nextChar+52-'0'; |
| 154 | else if (nextChar=='+') base64=62; |
| 155 | else if (nextChar=='/') base64=63; |
| 156 | else if (nextChar=='=') {base64=0; padding++;} else if (nextChar=='<') break; |
| 157 | if (base64>=0) ibuf=(ibuf<<6)+base64; |
| 158 | if (ibuf>=0x01000000){ |
| 159 | baos.write((ibuf>>16) &0xff); //00xx0000 0,1,2 = |
| 160 | if (padding<2) baos.write((ibuf>>8) &0xff); //0000xx00 0,1 = |
| 161 | if (padding==0) baos.write(ibuf &0xff); //000000xx 0 = |
| 162 | //len+=3; |
| 163 | ibuf=1; |
| 164 | } |
| 165 | } |
| 166 | try { baos.close(); } catch (Exception e) {} |
| 167 | //System.out.println(ibuf); |
| 168 | //System.out.println(baos.size()); |
| 169 | return baos; |
| 170 | } |
| 171 | |
| 172 | public static String unicodeToUTF(String src) { |
| 173 | return toUTFSb(new StringBuffer(src)).toString(); |
no test coverage detected