@Test public void testHasToBeEncoded() throws Exception { Assert.assertFalse(EncoderUtil.hasToBeEncoded("", 0)); Assert.assertFalse(EncoderUtil.hasToBeEncoded("only ascii characters", 0)); Assert.assertTrue(EncoderUtil.hasToBeEncoded("non-printable ascii: \010", 0)); Assert.assertTrue(EncoderUtil.hasToBeEncoded("non-ascii: \u20ac", 0)); Assert.assertFalse(EncoderUtil.hasToBeEncoded("123456789012345678901234567", 50)); Assert.assertTrue(EncoderUtil.hasToBeEncoded("1234567890123456789012345678", 50)); Assert.assertFalse(EncoderUtil.hasToBeEncoded( "\t12345678901234567890123456789", 50)); }
public static boolean hasToBeEncoded(String text, int usedCharacters) { if (text == null) throw new IllegalArgumentException(); if (usedCharacters < 0 || usedCharacters > MAX_USED_CHARACTERS) throw new IllegalArgumentException(); int nonWhiteSpaceCount = usedCharacters; for (int idx = 0; idx < text.length(); idx++) { char ch = text.charAt(idx); if (ch == '\t' || ch == ' ') { nonWhiteSpaceCount = 0; } else { nonWhiteSpaceCount++; if (nonWhiteSpaceCount > 77) { return true; } if (ch < 32 || ch >= 127) { return true; } } } return false; }
EncoderUtil { public static boolean hasToBeEncoded(String text, int usedCharacters) { if (text == null) throw new IllegalArgumentException(); if (usedCharacters < 0 || usedCharacters > MAX_USED_CHARACTERS) throw new IllegalArgumentException(); int nonWhiteSpaceCount = usedCharacters; for (int idx = 0; idx < text.length(); idx++) { char ch = text.charAt(idx); if (ch == '\t' || ch == ' ') { nonWhiteSpaceCount = 0; } else { nonWhiteSpaceCount++; if (nonWhiteSpaceCount > 77) { return true; } if (ch < 32 || ch >= 127) { return true; } } } return false; } }
EncoderUtil { public static boolean hasToBeEncoded(String text, int usedCharacters) { if (text == null) throw new IllegalArgumentException(); if (usedCharacters < 0 || usedCharacters > MAX_USED_CHARACTERS) throw new IllegalArgumentException(); int nonWhiteSpaceCount = usedCharacters; for (int idx = 0; idx < text.length(); idx++) { char ch = text.charAt(idx); if (ch == '\t' || ch == ' ') { nonWhiteSpaceCount = 0; } else { nonWhiteSpaceCount++; if (nonWhiteSpaceCount > 77) { return true; } if (ch < 32 || ch >= 127) { return true; } } } return false; } private  EncoderUtil(); }
EncoderUtil { public static boolean hasToBeEncoded(String text, int usedCharacters) { if (text == null) throw new IllegalArgumentException(); if (usedCharacters < 0 || usedCharacters > MAX_USED_CHARACTERS) throw new IllegalArgumentException(); int nonWhiteSpaceCount = usedCharacters; for (int idx = 0; idx < text.length(); idx++) { char ch = text.charAt(idx); if (ch == '\t' || ch == ' ') { nonWhiteSpaceCount = 0; } else { nonWhiteSpaceCount++; if (nonWhiteSpaceCount > 77) { return true; } if (ch < 32 || ch >= 127) { return true; } } } return false; } 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 boolean hasToBeEncoded(String text, int usedCharacters) { if (text == null) throw new IllegalArgumentException(); if (usedCharacters < 0 || usedCharacters > MAX_USED_CHARACTERS) throw new IllegalArgumentException(); int nonWhiteSpaceCount = usedCharacters; for (int idx = 0; idx < text.length(); idx++) { char ch = text.charAt(idx); if (ch == '\t' || ch == ' ') { nonWhiteSpaceCount = 0; } else { nonWhiteSpaceCount++; if (nonWhiteSpaceCount > 77) { return true; } if (ch < 32 || ch >= 127) { return true; } } } return false; } 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);  }