1 23 24 package org.infoglue.deliver.util; 25 26 44 45 public class HTUU 46 { 47 static String version = "HTUU Class v1.0 7/13/96"; 48 49 static char[] ENC = { 51 'A','B','C','D','E','F','G','H','I','J','K','L','M', 52 'N','O','P','Q','R','S','T','U','V','W','X','Y','Z', 53 'a','b','c','d','e','f','g','h','i','j','k','l','m', 54 'n','o','p','q','r','s','t','u','v','w','x','y','z', 55 '0','1','2','3','4','5','6','7','8','9','+','/' }; 56 57 60 public static String encode(String string) 61 { 62 int i, j; 63 byte[] byte_array = new byte[3]; 64 StringBuffer buf_coded = new StringBuffer (); 65 66 int nbytes = string.length(); 68 for (i = 0; i < nbytes; i+= 3) 69 { 70 if (i + 3 < nbytes) 72 j = i + 3; 73 else 74 j = nbytes; 75 76 string.getBytes(i, j, byte_array, 0); 78 if (j - i == 1) 79 { byte_array[1] = 0; 81 byte_array[2] = 0; 82 } 83 if (j - i == 2) 84 { byte_array[2] = 0; 86 } 87 buf_coded.append(ENC[byte_array[0] >> 2]); 90 buf_coded.append(ENC[((byte_array[0] << 4) & 060) | ((byte_array[1] >> 4) & 017)]); 91 buf_coded.append(ENC[((byte_array[1] << 2) & 074) | ((byte_array[2] >> 6) & 03)]); 92 buf_coded.append(ENC[byte_array[2] & 077]); } int buf_length = buf_coded.length(); 96 if (i == nbytes+1) 97 { 98 99 buf_coded.setCharAt(buf_length - 1, '='); 100 } 101 else if (i == nbytes+2) 102 { 103 104 buf_coded.setCharAt(buf_length - 1, '='); 105 buf_coded.setCharAt(buf_length - 2, '='); 106 } 107 return buf_coded.toString(); 109 } 110 } | Popular Tags |