@Test public void testEncodeQRestricted() throws Exception { byte[] b = new byte[136]; for (int i = 0; i < 136; i++) { b[i] = (byte) i; } String expected = "=00=01=02=03=04=05=06=07=08=09=0A=0B=0C=0D=0E=0F" + "=10=11=12=13=14=15=16=17=18=19=1A=1B=1C=1D=1E=1F_!=22=23" + "=24=25=26=27=28=29*+=2C-=2E/0123456789=3A=3B=3C=3D=3E=3F" + "=40ABCDEFGHIJKLMNOPQRSTUVWXYZ=5B=5C=5D=5E=5F=60abcdefghi" + "jklmnopqrstuvwxyz=7B=7C=7D=7E=7F=80=81=82=83=84=85=86=87"; Assert.assertEquals(expected, EncoderUtil.encodeQ(b, Usage.WORD_ENTITY)); }
public static String encodeQ(byte[] bytes, Usage usage) { BitSet qChars = usage == Usage.TEXT_TOKEN ? Q_REGULAR_CHARS : Q_RESTRICTED_CHARS; StringBuilder sb = new StringBuilder(); for (byte aByte : bytes) { int v = aByte & 0xff; if (v == 32) { sb.append('_'); } else if (!qChars.get(v)) { sb.append('='); sb.append(hexDigit(v >>> 4)); sb.append(hexDigit(v & 0xf)); } else { sb.append((char) v); } } return sb.toString(); }
EncoderUtil { public static String encodeQ(byte[] bytes, Usage usage) { BitSet qChars = usage == Usage.TEXT_TOKEN ? Q_REGULAR_CHARS : Q_RESTRICTED_CHARS; StringBuilder sb = new StringBuilder(); for (byte aByte : bytes) { int v = aByte & 0xff; if (v == 32) { sb.append('_'); } else if (!qChars.get(v)) { sb.append('='); sb.append(hexDigit(v >>> 4)); sb.append(hexDigit(v & 0xf)); } else { sb.append((char) v); } } return sb.toString(); } }
EncoderUtil { public static String encodeQ(byte[] bytes, Usage usage) { BitSet qChars = usage == Usage.TEXT_TOKEN ? Q_REGULAR_CHARS : Q_RESTRICTED_CHARS; StringBuilder sb = new StringBuilder(); for (byte aByte : bytes) { int v = aByte & 0xff; if (v == 32) { sb.append('_'); } else if (!qChars.get(v)) { sb.append('='); sb.append(hexDigit(v >>> 4)); sb.append(hexDigit(v & 0xf)); } else { sb.append((char) v); } } return sb.toString(); } private  EncoderUtil(); }
EncoderUtil { public static String encodeQ(byte[] bytes, Usage usage) { BitSet qChars = usage == Usage.TEXT_TOKEN ? Q_REGULAR_CHARS : Q_RESTRICTED_CHARS; StringBuilder sb = new StringBuilder(); for (byte aByte : bytes) { int v = aByte & 0xff; if (v == 32) { sb.append('_'); } else if (!qChars.get(v)) { sb.append('='); sb.append(hexDigit(v >>> 4)); sb.append(hexDigit(v & 0xf)); } else { sb.append((char) v); } } return sb.toString(); } private  EncoderUtil(); static String encodeAddressDisplayName(String displayName); static String encodeAddressLocalPart(String localPart); static String encodeHeaderParameter(String name, String value); static String encodeIfNecessary(String text, Usage usage,
            int usedCharacters); static boolean hasToBeEncoded(String text, int usedCharacters); static String encodeEncodedWord(String text, Usage usage); static String encodeEncodedWord(String text, Usage usage,
            int usedCharacters); static String encodeEncodedWord(String text, Usage usage,
            int usedCharacters, Charset charset, Encoding encoding); static String encodeB(byte[] bytes); static String encodeQ(byte[] bytes, Usage usage); static void encodeQBinary(final InputStream in, final OutputStream out); static void encodeQ(final InputStream in, final OutputStream out); static void encodeB(final InputStream in, final OutputStream out); static boolean isToken(String str); }
EncoderUtil { public static String encodeQ(byte[] bytes, Usage usage) { BitSet qChars = usage == Usage.TEXT_TOKEN ? Q_REGULAR_CHARS : Q_RESTRICTED_CHARS; StringBuilder sb = new StringBuilder(); for (byte aByte : bytes) { int v = aByte & 0xff; if (v == 32) { sb.append('_'); } else if (!qChars.get(v)) { sb.append('='); sb.append(hexDigit(v >>> 4)); sb.append(hexDigit(v & 0xf)); } else { sb.append((char) v); } } return sb.toString(); } private  EncoderUtil(); static String encodeAddressDisplayName(String displayName); static String encodeAddressLocalPart(String localPart); static String encodeHeaderParameter(String name, String value); static String encodeIfNecessary(String text, Usage usage,
            int usedCharacters); static boolean hasToBeEncoded(String text, int usedCharacters); static String encodeEncodedWord(String text, Usage usage); static String encodeEncodedWord(String text, Usage usage,
            int usedCharacters); static String encodeEncodedWord(String text, Usage usage,
            int usedCharacters, Charset charset, Encoding encoding); static String encodeB(byte[] bytes); static String encodeQ(byte[] bytes, Usage usage); static void encodeQBinary(final InputStream in, final OutputStream out); static void encodeQ(final InputStream in, final OutputStream out); static void encodeB(final InputStream in, final OutputStream out); static boolean isToken(String str);  }