commons-codec-1.3

, DoubleMetaphoneResult result, int index)
  {
    if (index == 0)
    {
      result.append('S');
      index++;
    }
    else
    {
      if ((index != value.length() - 1) || ((!contains(value, index - 3, 3, "IAU", "EAU")) && (!contains(value, index - 2, 2, "AU", "OU")))) {
        result.append("KS");
      }
      index = contains(value, index + 1, 1, "C", "X") ? index + 2 : index + 1;
    }
    return index;
  }
  
  private int handleZ(String value, DoubleMetaphoneResult result, int index, boolean slavoGermanic)
  {
    if (charAt(value, index + 1) == 'H')
    {
      result.append('J');
      index += 2;
    }
    else
    {
      if ((contains(value, index + 1, 2, "ZO", "ZI", "ZA")) || ((slavoGermanic) && (index > 0) && (charAt(value, index - 1) != 'T'))) {
        result.append("S", "TS");
      } else {
        result.append('S');
      }
      index = charAt(value, index + 1) == 'Z' ? index + 2 : index + 1;
    }
    return index;
  }
  
  private boolean conditionC0(String value, int index)
  {
    if (contains(value, index, 4, "CHIA")) {
      return true;
    }
    if (index <= 1) {
      return false;
    }
    if (isVowel(charAt(value, index - 2))) {
      return false;
    }
    if (!contains(value, index - 1, 3, "ACH")) {
      return false;
    }
    char c = charAt(value, index + 2);
    return ((c != 'I') && (c != 'E')) || (contains(value, index - 2, 6, "BACHER", "MACHER"));
  }
  
  private boolean conditionCH0(String value, int index)
  {
    if (index != 0) {
      return false;
    }
    if ((!contains(value, index + 1, 5, "HARAC", "HARIS")) && (!contains(value, index + 1, 3, "HOR", "HYM", "HIA", "HEM"))) {
      return false;
    }
    if (contains(value, 0, 5, "CHORE")) {
      return false;
    }
    return true;
  }
  
  private boolean conditionCH1(String value, int index)
  {
    return (contains(value, 0, 4, "VAN ", "VON ")) || (contains(value, 0, 3, "SCH")) || (contains(value, index - 2, 6, "ORCHES", "ARCHIT", "ORCHID")) || (contains(value, index + 2, 1, "T", "S")) || (((contains(value, index - 1, 1, "A", "O", "U", "E")) || (index == 0)) && ((contains(value, index + 2, 1, L_R_N_M_B_H_F_V_W_SPACE)) || (index + 1 == value.length() - 1)));
  }
  
  private boolean conditionL0(String value, int index)
  {
    if ((index == value.length() - 3) && (contains(value, index - 1, 4, "ILLO", "ILLA", "ALLE"))) {
      return true;
    }
    if (((contains(value, index - 1, 2, "AS", "OS")) || (contains(value, value.length() - 1, 1, "A", "O"))) && (contains(value, index - 1, 4, "ALLE"))) {
      return true;
    }
    return false;
  }
  
  private boolean conditionM0(String value, int index)
  {
    if (charAt(value, index + 1) == 'M') {
      return true;
    }
    return (contains(value, index - 1, 3, "UMB")) && ((index + 1 == value.length() - 1) || (contains(value, index + 2, 2, "ER")));
  }
  
  private boolean isSlavoGermanic(String value)
  {
    return (value.indexOf('W') > -1) || (value.indexOf('K') > -1) || (value.indexOf("CZ") > -1) || (value.indexOf("WITZ") > -1);
  }
  
  private boolean isVowel(char ch)
  {
    return "AEIOUY".indexOf(ch) != -1;
  }
  
  private boolean isSilentStart(String value)
  {
    boolean result = false;
    for (int i = 0; i < SILENT_START.length; i++) {
      if (value.startsWith(SILENT_START[i]))
      {
        result = true;
        break;
      }
    }
    return result;
  }
  
  private String cleanInput(String input)
  {
    if (input == null) {
      return null;
    }
    input = input.trim();
    if (input.length() == 0) {
      return null;
    }
    return input.toUpperCase();
  }
  
  protected char charAt(String value, int index)
  {
    if ((index < 0) || (index >= value.length())) {
      return '\000';
    }
    return value.charAt(index);
  }
  
  private static boolean contains(String value, int start, int length, String criteria)
  {
    return contains(value, start, length, new String[] { criteria });
  }
  
  private static boolean contains(String value, int start, int length, String criteria1, String criteria2)
  {
    return contains(value, start, length, new String[] { criteria1, criteria2 });
  }
  
  private static boolean contains(String value, int start, int length, String criteria1, String criteria2, String criteria3)
  {
    return contains(value, start, length, new String[] { criteria1, criteria2, criteria3 });
  }
  
  private static boolean contains(String value, int start, int length, String criteria1, String criteria2, String criteria3, String criteria4)
  {
    return contains(value, start, length, new String[] { criteria1, criteria2, criteria3, criteria4 });
  }
  
  private static boolean contains(String value, int start, int length, String criteria1, String criteria2, String criteria3, String criteria4, String criteria5)
  {
    return contains(value, start, length, new String[] { criteria1, criteria2, criteria3, criteria4, criteria5 });
  }
  
  private static boolean contains(String value, int start, int length, String criteria1, String criteria2, String criteria3, String criteria4, String criteria5, String criteria6)
  {
    return contains(value, start, length, new String[] { criteria1, criteria2, criteria3, criteria4, criteria5, criteria6 });
  }
  
  protected static boolean contains(String value, int start, int length, String[] criteria)
  {
    boolean result = false;
    if ((start >= 0) && (start + length <= value.length()))
    {
      String target = value.substring(start, start + length);
      for (int i = 0; i < criteria.length; i++) {
        if (target.equals(criteria[i]))
        {
          result = true;
          break;
        }
      }
    }
    return result;
  }
  
  public class DoubleMetaphoneResult
  {
    private StringBuffer primary = new StringBuffer(getMaxCodeLen());
    private StringBuffer alternate = new StringBuffer(getMaxCodeLen());
    private int maxLength;
    
    public DoubleMetaphoneResult(int maxLength)
    {
      this.maxLength = maxLength;
    }
    
    public void append(char value)
    {
      appendPrimary(value);
      appendAlternate(value);
    }
    
    public void append(char primary, char alternate)
    {
      appendPrimary(primary);
      appendAlternate(alternate);
    }
    
    public void appendPrimary(char value)
    {
      if (primary.length() < maxLength) {
        primary.append(value);
      }
    }
    
    public void appendAlternate(char value)
    {
      if (alternate.length() < maxLength) {
        alternate.append(value);
      }
    }
    
    public void append(String value)
    {
      appendPrimary(value);
      appendAlternate(value);
    }
    
    public void append(String primary, String alternate)
    {
      appendPrimary(primary);
      appendAlternate(alternate);
    }
    
    public void appendPrimary(String value)
    {
      int addChars = maxLength - primary.length();
      if (value.length() <= addChars) {
        primary.append(value);
      } else {
        primary.append(value.substring(0, addChars));
      }
    }
    
    public void appendAlternate(String value)
    {
      int addChars = maxLength - alternate.length();
      if (value.length() <= addChars) {
        alternate.append(value);
      } else {
        alternate.append(value.substring(0, addChars));
      }
    }
    
    public String getPrimary()
    {
      return primary.toString();
    }
    
    public String getAlternate()
    {
      return alternate.toString();
    }
    
    public boolean isComplete()
    {
      return (primary.length() >= maxLength) && (alternate.length() >= maxLength);
    }
  }
}

/* Location:
 * Qualified Name:     org.apache.commons.codec.language.DoubleMetaphone
 * Java Class Version: 1.2 (46.0)
 * JD-Core Version:    0.7.1
 */
package org.apache.commons.codec.language;

import org.apache.commons.codec.EncoderException;
import org.apache.commons.codec.StringEncoder;

public class Metaphone
  implements StringEncoder
{
  private String vowels = "AEIOU";
  private String frontv = "EIY";
  private String varson = "CSPTG";
  private int maxCodeLen = 4;
  
  public String metaphone(String txt)
  {
    boolean hard = false;
    if ((txt == null) || (txt.length() == 0)) {
      return "";
    }
    if (txt.length() == 1) {
      return txt.toUpperCase();
    }
    char[] inwd = txt.toUpperCase().toCharArray();
    
    StringBuffer local = new StringBuffer(40);
    StringBuffer code = new StringBuffer(10);
    switch (inwd[0])
    {
    case 'G': 
    case 'K': 
    case 'P': 
      if (inwd[1] == 'N') {
        local.append(inwd, 1, inwd.length - 1);
      } else {
        local.append(inwd);
      }
      break;
    case 'A': 
      if (inwd[1] == 'E') {
        local.append(inwd, 1, inwd.length - 1);
      } else {
        local.append(inwd);
      }
      break;
    case 'W': 
      if (inwd[1] == 'R')
      {
        local.append(inwd, 1, inwd.length - 1);
      }
      else if (inwd[1] == 'H')
      {
        local.append(inwd, 1, inwd.length - 1);
        local.setCharAt(0, 'W');
      }
      else
      {
        local.append(inwd);
      }
      break;
    case 'X': 
      inwd[0] = 'S';
      local.append(inwd);
      break;
    default: 
      local.append(inwd);
    }
    int wdsz = local.length();
    int n = 0;
    while ((code.length() < getMaxCodeLen()) && (n < wdsz))
    {
      char symb = local.charAt(n);
      if ((symb != 'C') && (isPreviousChar(local, n, symb)))
      {
        n++;
      }
      else
      {
        switch (symb)
        {
        case 'A': 
        case 'E': 
        case 'I': 
        case 'O': 
        case 'U': 
          if (n == 0) {
            code.append(symb);
          }
          break;
        case 'B': 
          if ((!isPreviousChar(local, n, 'M')) || (!isLastChar(wdsz, n))) {
            code.append(symb);
          }
          break;
        case 'C': 
          if ((!isPreviousChar(local, n, 'S')) || (isLastChar(wdsz, n)) || (frontv.indexOf(local.charAt(n + 1)) < 0)) {
            if (regionMatch(local, n, "CIA")) {
              code.append('X');
            } else if ((!isLastChar(wdsz, n)) && (frontv.indexOf(local.charAt(n + 1)) >= 0)) {
              code.append('S');
            } else if ((isPreviousChar(local, n, 'S')) && (isNextChar(local, n, 'H'))) {
              code.append('K');
            } else if (isNextChar(local, n, 'H'))
            {
              if ((n == 0) && (wdsz >= 3) && (isVowel(local, 2))) {
                code.append('K');
              } else {
                code.append('X');
              }
            }
            else {
              code.append('K');
            }
          }
          break;
        case 'D': 
          if ((!isLastChar(wdsz, n + 1)) && (isNextChar(local, n, 'G')) && (frontv.indexOf(local.charAt(n + 2)) >= 0))
          {
            code.append('J');n += 2;
          }
          else
          {
            code.append('T');
          }
          break;
        case 'G': 
          if ((!isLastChar(wdsz, n + 1)) || (!isNextChar(local, n, 'H'))) {
            if ((isLastChar(wdsz, n + 1)) || (!isNextChar(local, n, 'H')) || (isVowel(local, n + 2))) {
              if ((n <= 0) || ((!regionMatch(local, n, "GN")) && (!regionMatch(local, n, "GNED"))))
              {
                if (isPreviousChar(local, n, 'G')) {
                  hard = true;
                } else {
                  hard = false;
                }
                if ((!isLastChar(wdsz, n)) && (frontv.indexOf(local.charAt(n + 1)) >= 0) && (!hard)) {
                  code.append('J');
                } else {
                  code.append('K');
                }
              }
            }
          }
          break;
        case 'H': 
          if (!isLastChar(wdsz, n)) {
            if ((n <= 0) || (varson.indexOf(local.charAt(n - 1)) < 0)) {
              if (isVowel(local, n + 1)) {
                code.append('H');
              }
            }
          }
          break;
        case 'F': 
        case 'J': 
        case 'L': 
        case 'M': 
        case 'N': 
        case 'R': 
          code.append(symb);
          break;
        case 'K': 
          if (n > 0)
          {
            if (!isPreviousChar(local, n, 'C')) {
              code.append(symb);
            }
          }
          else {
            code.append(symb);
          }
          break;
        case 'P': 
          if (isNextChar(local, n, 'H')) {
            code.append('F');
          } else {
            code.append(symb);
          }
          break;
        case 'Q': 
          code.append('K');
          break;
        case 'S': 
          if ((regionMatch(local, n, "SH")) || (regionMatch(local, n, "SIO")) || (regionMatch(local, n, "SIA"))) {
            code.append('X');
          } else {
            code.append('S');
          }
          break;
        case 'T': 
          if ((regionMatch(local, n, "TIA")) || (regionMatch(local, n, "TIO"))) {
            code.append('X');
          } else if (!regionMatch(local, n, "TCH")) {
            if (regionMatch(local, n, "TH")) {
              code.append('0');
            } else {
              code.append('T');
            }
          }
          break;
        case 'V': 
          code.append('F'); break;
        case 'W': 
        case 'Y': 
          if ((!isLastChar(wdsz, n)) && (isVowel(local, n + 1))) {
            code.append(symb);
          }
          break;
        case 'X': 
          code.append('K');code.append('S');
          break;
        case 'Z': 
          code.append('S');
        }
        n++;
      }
      if (code.length() > getMaxCodeLen()) {
        code.setLength(getMaxCodeLen());
      }
    }
    return code.toString();
  }
  
  private boolean isVowel(StringBuffer string, int index)
  {
    return vowels.indexOf(string.charAt(index)) >= 0;
  }
  
  private boolean isPreviousChar(StringBuffer string, int index, char c)
  {
    boolean matches = false;
    if ((index > 0) && (index < string.length())) {
      matches = string.charAt(index - 1) == c;
    }
    return matches;
  }
  
  private boolean isNextChar(StringBuffer string, int index, char c)
  {
    boolean matches = false;
    if ((index >= 0) && (index < string.length() - 1)) {
      matches = string.charAt(index + 1) == c;
    }
    return matches;
  }
  
  private boolean regionMatch(StringBuffer string, int index, String test)
  {
    boolean matches = false;
    if ((index >= 0) && (index + test.length() - 1 < string.length()))
    {
      String substring = string.substring(index, index + test.length());
      matches = substring.equals(test);
    }
    return matches;
  }
  
  private boolean isLastChar(int wdsz, int n)
  {
    return n + 1 == wdsz;
  }
  
  public Object encode(Object pObject)
    throws EncoderException
  {
    if (!(pObject instanceof String)) {
      throw new EncoderException("Parameter supplied to Metaphone encode is not of type java.lang.String");
    }
    return metaphone((String)pObject);
  }
  
  public String encode(String pString)
  {
    return metaphone(pString);
  }
  
  public boolean isMetaphoneEqual(String str1, String str2)
  {
    return metaphone(str1).equals(metaphone(str2));
  }
  
  public int getMaxCodeLen()
  {
    return maxCodeLen;
  }
  
  public void setMaxCodeLen(int maxCodeLen)
  {
    this.maxCodeLen = maxCodeLen;
  }
}

/* Location:
 * Qualified Name:     org.apache.commons.codec.language.Metaphone
 * Java Class Version: 1.2 (46.0)
 * JD-Core Version:    0.7.1
 */
package org.apache.commons.codec.language;

import org.apache.commons.codec.EncoderException;
import org.apache.commons.codec.StringEncoder;

public class RefinedSoundex
  implements StringEncoder
{
  public static final RefinedSoundex US_ENGLISH = new RefinedSoundex();
  public static final char[] US_ENGLISH_MAPPING = "01360240043788015936020505".toCharArray();
  private char[] soundexMapping;
  
  public RefinedSoundex()
  {
    this(US_ENGLISH_MAPPING);
  }
  
  public RefinedSoundex(char[] mapping)
  {
    soundexMapping = mapping;
  }
  
  public int difference(String s1, String s2)
    throws EncoderException
  {
    return SoundexUtils.difference(this, s1, s2);
  }
  
  public Object encode(Object pObject)
    throws EncoderException
  {
    if (!(pObject instanceof String)) {
      throw new EncoderException("Parameter supplied to RefinedSoundex encode is not of type java.lang.String");
    }
    return soundex((String)pObject);
  }
  
  public String encode(String pString)
  {
    return soundex(pString);
  }
  
  char getMappingCode(char c)
  {
    if (!Character.isLetter(c)) {
      return '\000';
    }
    return soundexMapping[(Character.toUpperCase(c) - 'A')];
  }
  
  public String soundex(String str)
  {
    if (str == null) {
      return null;
    }
    str = SoundexUtils.clean(str);
    if (str.length() == 0) {
      return str;
    }
    StringBuffer sBuf = new StringBuffer();
    sBuf.append(str.charAt(0));
    
    char last = '*';
    for (int i = 0; i < str.length(); i++)
    {
      char current = getMappingCode(str.charAt(i));
      if (current != last)
      {
        if (current != 0) {
          sBuf.append(current);
        }
        last = current;
      }
    }
    return sBuf.toString();
  }
}

/* Location:
 * Qualified Name:     org.apache.commons.codec.language.RefinedSoundex
 * Java Class Version: 1.2 (46.0)
 * JD-Core Version:    0.7.1
 */
package org.apache.commons.codec.language;

import org.apache.commons.codec.EncoderException;
import org.apache.commons.codec.StringEncoder;

public class Soundex
  implements StringEncoder
{
  public static final Soundex US_ENGLISH = new Soundex();
  public static final String US_ENGLISH_MAPPING_STRING = "01230120022455012623010202";
  public static final char[] US_ENGLISH_MAPPING = "01230120022455012623010202".toCharArray();
  
  public int difference(String s1, String s2)
    throws EncoderException
  {
    return SoundexUtils.difference(this, s1, s2);
  }
  
  /**
   * @deprecated
   */
  private int maxLength = 4;
  private char[] soundexMapping;
  
  public Soundex()
  {
    this(US_ENGLISH_MAPPING);
  }
  
  public Soundex(char[] mapping)
  {
    setSoundexMapping(mapping);
  }
  
  public Object encode(Object pObject)
    throws EncoderException
  {
    if (!(pObject instanceof String)) {
      throw new EncoderException("Parameter supplied to Soundex encode is not of type java.lang.String");
    }
    return soundex((String)pObject);
  }
  
  public String encode(String pString)
  {
    return soundex(pString);
  }
  
  private char getMappingCode(String str, int index)
  {
    char mappedChar = map(str.charAt(index));
    if ((index > 1) && (mappedChar != '0'))
    {
      char hwChar = str.charAt(index - 1);
      if (('H' == hwChar) || ('W' == hwChar))
      {
        char preHWChar = str.charAt(index - 2);
        char firstCode = map(preHWChar);
        if ((firstCode == mappedChar) || ('H' == preHWChar) || ('W' == preHWChar)) {
          return '\000';
        }
      }
    }
    return mappedChar;
  }
  
  /**
   * @deprecated
   */
  public int getMaxLength()
  {
    return maxLength;
  }
  
  private char[] getSoundexMapping()
  {
    return soundexMapping;
  }
  
  private char map(char ch)
  {
    int index = ch - 'A';
    if ((index < 0) || (index >= getSoundexMapping().length)) {
      throw new IllegalArgumentException("The character is not mapped: " + ch);
    }
    return getSoundexMapping()[index];
  }
  
  /**
   * @deprecated
   */
  public void setMaxLength(int maxLength)
  {
    this.maxLength = maxLength;
  }
  
  private void setSoundexMapping(char[] soundexMapping)
  {
    this.soundexMapping = soundexMapping;
  }
  
  public String soundex(String str)
  {
    if (str == null) {
      return null;
    }
    str = SoundexUtils.clean(str);
    if (str.length() == 0) {
      return str;
    }
    char[] out = { '0', '0', '0', '0' };
    
    int incount = 1;int count = 1;
    out[0] = str.charAt(0);
    char last = getMappingCode(str, 0);
    while ((incount < str.length()) && (count < out.length))
    {
      char mapped = getMappingCode(str, incount++);
      if (mapped != 0)
      {
        if ((mapped != '0') && (mapped != last)) {
          out[(count++)] = mapped;
        }
        last = mapped;
      }
    }
    return new String(out);
  }
}

/* Location:
 * Qualified Name:     org.apache.commons.codec.language.Soundex
 * Java Class Version: 1.2 (46.0)
 * JD-Core Version:    0.7.1
 */
package org.apache.commons.codec.language;

import org.apache.commons.codec.EncoderException;
import org.apache.commons.codec.StringEncoder;

final class SoundexUtils
{
  static String clean(String str)
  {
    if ((str == null) || (str.length() == 0)) {
      return str;
    }
    int len = str.length();
    char[] chars = new char[len];
    int count = 0;
    for (int i = 0; i < len; i++) {
      if (Character.isLetter(str.charAt(i))) {
        chars[(count++)] = str.charAt(i);
      }
    }
    if (count == len) {
      return str.toUpperCase();
    }
    return new String(chars, 0, count).toUpperCase();
  }
  
  static int difference(StringEncoder encoder, String s1, String s2)
    throws EncoderException
  {
    return differenceEncoded(encoder.encode(s1), encoder.encode(s2));
  }
  
  static int differenceEncoded(String es1, String es2)
  {
    if ((es1 == null) || (es2 == null)) {
      return 0;
    }
    int lengthToMatch = Math.min(es1.length(), es2.length());
    int diff = 0;
    for (int i = 0; i < lengthToMatch; i++) {
      if (es1.charAt(i) == es2.charAt(i)) {
        diff++;
      }
    }
    return diff;
  }
}

/* Location:
 * Qualified Name:     org.apache.commons.codec.language.SoundexUtils
 * Java Class Version: 1.2 (46.0)
 * JD-Core Version:    0.7.1
 */
package org.apache.commons.codec.net;

import java.io.UnsupportedEncodingException;
import org.apache.commons.codec.DecoderException;
import org.apache.commons.codec.EncoderException;
import org.apache.commons.codec.StringDecoder;
import org.apache.commons.codec.StringEncoder;
import org.apache.commons.codec.binary.Base64;

public class BCodec
  extends RFC1522Codec
  implements StringEncoder, StringDecoder
{
  private String charset = "UTF-8";
  
  public BCodec() {}
  
  public BCodec(String charset)
  {
    this.charset = charset;
  }
  
  protected String getEncoding()
  {
    return "B";
  }
  
  protected byte[] doEncoding(byte[] bytes)
    throws EncoderException
  {
    if (bytes == null) {
      return null;
    }
    return Base64.encodeBase64(bytes);
  }
  
  protected byte[] doDecoding(byte[] bytes)
    throws DecoderException
  {
    if (bytes == null) {
      return null;
    }
    return Base64.decodeBase64(bytes);
  }
  
  public String encode(String value, String charset)
    throws EncoderException
  {
    if (value == null) {
      return null;
    }
    try
    {
      return encodeText(value, charset);
    }
    catch (UnsupportedEncodingException e)
    {
      throw new EncoderException(e.getMessage());
    }
  }
  
  public String encode(String value)
    throws EncoderException
  {
    if (value == null) {
      return null;
    }
    return encode(value, getDefaultCharset());
  }
  
  public String decode(String value)
    throws DecoderException
  {
    if (value == null) {
      return null;
    }
    try
    {
      return decodeText(value);
    }
    catch (UnsupportedEncodingException e)
    {
      throw new DecoderException(e.getMessage());
    }
  }
  
  public Object encode(Object value)
    throws EncoderException
  {
    if (value == null) {
      return null;
    }
    if ((value instanceof String)) {
      return encode((String)value);
    }
    throw new EncoderException("Objects of type " + value.getClass().getName() + " cannot be encoded using BCodec");
  }
  
  public Object decode(Object value)
    throws DecoderException
  {
    if (value == null) {
      return null;
    }
    if ((value instanceof String)) {
      return decode((String)value);
    }
    throw new DecoderException("Objects of type " + value.getClass().getName() + " cannot be decoded using BCodec");
  }
  
  public String getDefaultCharset()
  {
    return charset;
  }
}

/* Location:
 * Qualified Name:     org.apache.commons.codec.net.BCodec
 * Java Class Version: 1.2 (46.0)
 * JD-Core Version:    0.7.1
 */
package org.apache.commons.codec.net;

import java.io.UnsupportedEncodingException;
import java.util.BitSet;
import org.apache.commons.codec.DecoderException;
import org.apache.commons.codec.EncoderException;
import org.apache.commons.codec.StringDecoder;
import org.apache.commons.codec.StringEncoder;

public class QCodec
  extends RFC1522Codec
  implements StringEncoder, StringDecoder
{
  private String charset = "UTF-8";
  private static final BitSet PRINTABLE_CHARS = new BitSet(256);
  
  static
  {
    PRINTABLE_CHARS.set(32);
    PRINTABLE_CHARS.set(33);
    PRINTABLE_CHARS.set(34);
    PRINTABLE_CHARS.set(35);
    PRINTABLE_CHARS.set(36);
    PRINTABLE_CHARS.set(37);
    PRINTABLE_CHARS.set(38);
    PRINTABLE_CHARS.set(39);
    PRINTABLE_CHARS.set(40);
    PRINTABLE_CHARS.set(41);
    PRINTABLE_CHARS.set(42);
    PRINTABLE_CHARS.set(43);
    PRINTABLE_CHARS.set(44);
    PRINTABLE_CHARS.set(45);
    PRINTABLE_CHARS.set(46);
    PRINTABLE_CHARS.set(47);
    for (int i = 48; i <= 57; i++) {
      PRINTABLE_CHARS.set(i);
    }
    PRINTABLE_CHARS.set(58);
    PRINTABLE_CHARS.set(59);
    PRINTABLE_CHARS.set(60);
    PRINTABLE_CHARS.set(62);
    PRINTABLE_CHARS.set(64);
    for (int i = 65; i <= 90; i++) {
      PRINTABLE_CHARS.set(i);
    }
    PRINTABLE_CHARS.set(91);
    PRINTABLE_CHARS.set(92);
    PRINTABLE_CHARS.set(93);
    PRINTABLE_CHARS.set(94);
    PRINTABLE_CHARS.set(96);
    for (int i = 97; i <= 122; i++) {
      PRINTABLE_CHARS.set(i);
    }
    PRINTABLE_CHARS.set(123);
    PRINTABLE_CHARS.set(124);
    PRINTABLE_CHARS.set(125);
    PRINTABLE_CHARS.set(126);
  }
  
  private static byte BLANK = 32;
  private static byte UNDERSCORE = 95;
  private boolean encodeBlanks = false;
  
  public QCodec(String charset)
  {
    this.charset = charset;
  }
  
  protected String getEncoding()
  {
    return "Q";
  }
  
  protected byte[] doEncoding(byte[] bytes)
    throws EncoderException
  {
    if (bytes == null) {
      return null;
    }
    byte[] data = QuotedPrintableCodec.encodeQuotedPrintable(PRINTABLE_CHARS, bytes);
    if (encodeBlanks) {
      for (int i = 0; i < data.length; i++) {
        if (data[i] == BLANK) {
          data[i] = UNDERSCORE;
        }
      }
    }
    return data;
  }
  
  protected byte[] doDecoding(byte[] bytes)
    throws DecoderException
  {
    if (bytes == null) {
      return null;
    }
    boolean hasUnderscores = false;
    for (int i = 0; i < bytes.length; i++) {
      if (bytes[i] == UNDERSCORE)
      {
        hasUnderscores = true;
        break;
      }
    }
    if (hasUnderscores)
    {
      byte[] tmp = new byte[bytes.length];
      for (int i = 0; i < bytes.length; i++)
      {
        byte b = bytes[i];
        if (b != UNDERSCORE) {
          tmp[i] = b;
        } else {
          tmp[i] = BLANK;
        }
      }
      return QuotedPrintableCodec.decodeQuotedPrintable(tmp);
    }
    return QuotedPrintableCodec.decodeQuotedPrintable(bytes);
  }
  
  public String encode(String pString, String charset)
    throws EncoderException
  {
    if (pString == null) {
      return null;
    }
    try
    {
      return encodeText(pString, charset);
    }
    catch (UnsupportedEncodingException e)
    {
      throw new EncoderException(e.getMessage());
    }
  }
  
  public String encode(String pString)
    throws EncoderException
  {
    if (pString == null) {
      return null;
    }
    return encode(pString, getDefaultCharset());
  }
  
  public String decode(String pString)
    throws DecoderException
  {
    if (pString == null) {
      return null;
    }
    try
    {
      return decodeText(pString);
    }
    catch (UnsupportedEncodingException e)
    {
      throw new DecoderException(e.getMessage());
    }
  }
  
  public Object encode(Object pObject)
    throws EncoderException
  {
    if (pObject == null) {
      return null;
    }
    if ((pObject instanceof String)) {
      return encode((String)pObject);
    }
    throw new EncoderException("Objects of type " + pObject.getClass().getName() + " cannot be encoded using Q codec");
  }
  
  public Object decode(Object pObject)
    throws DecoderException
  {
    if (pObject == null) {
      return null;
    }
    if ((pObject instanceof String)) {
      return decode((String)pObject);
    }
    throw new DecoderException("Objects of type " + pObject.getClass().getName() + " cannot be decoded using Q codec");
  }
  
  public String getDefaultCharset()
  {
    return charset;
  }
  
  public boolean isEncodeBlanks()
  {
    return encodeBlanks;
  }
  
  public void setEncodeBlanks(boolean b)
  {
    encodeBlanks = b;
  }
  
  public QCodec() {}
}

/* Location:
 * Qualified Name:     org.apache.commons.codec.net.QCodec
 * Java Class Version: 1.2 (46.0)
 * JD-Core Version:    0.7.1
 */
package org.apache.commons.codec.net;

import java.io.ByteArrayOutputStream;
import java.io.UnsupportedEncodingException;
import java.util.BitSet;
import org.apache.commons.codec.BinaryDecoder;
import org.apache.commons.codec.BinaryEncoder;
import org.apache.commons.codec.DecoderException;
import org.apache.commons.codec.EncoderException;
import org.apache.commons.codec.StringDecoder;
import org.apache.commons.codec.StringEncoder;

public class QuotedPrintableCodec
  implements BinaryEncoder, BinaryDecoder, StringEncoder, StringDecoder
{
  private String charset = "UTF-8";
  private static final BitSet PRINTABLE_CHARS = new BitSet(256);
  private static byte ESCAPE_CHAR = 61;
  private static byte TAB = 9;
  private static byte SPACE = 32;
  
  static
  {
    for (int i = 33; i <= 60; i++) {
      PRINTABLE_CHARS.set(i);
    }
    for (int i = 62; i <= 126; i++) {
      PRINTABLE_CHARS.set(i);
    }
    PRINTABLE_CHARS.set(TAB);
    PRINTABLE_CHARS.set(SPACE);
  }
  
  public QuotedPrintableCodec(String charset)
  {
    this.charset = charset;
  }
  
  private static final void encodeQuotedPrintable(int b, ByteArrayOutputStream buffer)
  {
    buffer.write(ESCAPE_CHAR);
    char hex1 = Character.toUpperCase(Character.forDigit(b >> 4 & 0xF, 16));
    char hex2 = Character.toUpperCase(Character.forDigit(b & 0xF, 16));
    buffer.write(hex1);
    buffer.write(hex2);
  }
  
  public static final byte[] encodeQuotedPrintable(BitSet printable, byte[] bytes)
  {
    if (bytes == null) {
      return null;
    }
    if (printable == null) {
      printable = PRINTABLE_CHARS;
    }
    ByteArrayOutputStream buffer = new ByteArrayOutputStream();
    for (int i = 0; i < bytes.length; i++)
    {
      int b = bytes[i];
      if (b < 0) {
        b = 256 + b;
      }
      if (printable.get(b)) {
        buffer.write(b);
      } else {
        encodeQuotedPrintable(b, buffer);
      }
    }
    return buffer.toByteArray();
  }
  
  public static final byte[] decodeQuotedPrintable(byte[] bytes)
    throws DecoderException
  {
    if (bytes == null) {
      return null;
    }
    ByteArrayOutputStream buffer = new ByteArrayOutputStream();
    for (int i = 0; i < bytes.length; i++)
    {
      int b = bytes[i];
      if (b == ESCAPE_CHAR) {
        try
        {
          int u = Character.digit((char)bytes[(++i)], 16);
          int l = Character.digit((char)bytes[(++i)], 16);
          if ((u == -1) || (l == -1)) {
            throw new DecoderException("Invalid quoted-printable encoding");
          }
          buffer.write((char)((u << 4) + l));
        }
        catch (ArrayIndexOutOfBoundsException e)
        {
          throw new DecoderException("Invalid quoted-printable encoding");
        }
      } else {
        buffer.write(b);
      }
    }
    return buffer.toByteArray();
  }
  
  public byte[] encode(byte[] bytes)
  {
    return encodeQuotedPrintable(PRINTABLE_CHARS, bytes);
  }
  
  public byte[] decode(byte[] bytes)
    throws DecoderException
  {
    return decodeQuotedPrintable(bytes);
  }
  
  public String encode(String pString)
    throws EncoderException
  {
    if (pString == null) {
      return null;
    }
    try
    {
      return encode(pString, getDefaultCharset());
    }
    catch (UnsupportedEncodingException e)
    {
      throw new EncoderException(e.getMessage());
    }
  }
  
  public String decode(String pString, String charset)
    throws DecoderException, UnsupportedEncodingException
  {
    if (pString == null) {
      return null;
    }
    return new String(decode(pString.getBytes("US-ASCII")), charset);
  }
  
  public String decode(String pString)
    throws DecoderException
  {
    if (pString == null) {
      return null;
    }
    try
    {
      return decode(pString, getDefaultCharset());
    }
    catch (UnsupportedEncodingException e)
    {
      throw new DecoderException(e.getMessage());
    }
  }
  
  public Object encode(Object pObject)
    throws EncoderException
  {
    if (pObject == null) {
      return null;
    }
    if ((pObject instanceof byte[])) {
      return encode((byte[])pObject);
    }
    if ((pObject instanceof String)) {
      return encode((String)pObject);
    }
    throw new EncoderException("Objects of type " + pObject.getClass().getName() + " cannot be quoted-printable encoded");
  }
  
  public Object decode(Object pObject)
    throws DecoderException
  {
    if (pObject == null) {
      return null;
    }
    if ((pObject instanceof byte[])) {
      return decode((byte[])pObject);
    }
    if ((pObject instanceof String)) {
      return decode((String)pObject);
    }
    throw new DecoderException("Objects of type " + pObject.getClass().getName() + " cannot be quoted-printable decoded");
  }
  
  public String getDefaultCharset()
  {
    return charset;
  }
  
  public String encode(String pString, String charset)
    throws UnsupportedEncodingException
  {
    if (pString == null) {
      return null;
    }
    return new String(encode(pString.getBytes(charset)), "US-ASCII");
  }
  
  public QuotedPrintableCodec() {}
}

/* Location:
 * Qualified Name:     org.apache.commons.codec.net.QuotedPrintableCodec
 * Java Class Version: 1.2 (46.0)
 * JD-Core Version:    0.7.1
 */
package org.apache.commons.codec.net;

import java.io.UnsupportedEncodingException;
import org.apache.commons.codec.DecoderException;
import org.apache.commons.codec.EncoderException;

abstract class RFC1522Codec
{
  protected String encodeText(String text, String charset)
    throws EncoderException, UnsupportedEncodingException
  {
    if (text == null) {
      return null;
    }
    StringBuffer buffer = new StringBuffer();
    buffer.append("=?");
    buffer.append(charset);
    buffer.append('?');
    buffer.append(getEncoding());
    buffer.append('?');
    byte[] rawdata = doEncoding(text.getBytes(charset));
    buffer.append(new String(rawdata, "US-ASCII"));
    buffer.append("?=");
    return buffer.toString();
  }
  
  protected String decodeText(String text)
    throws DecoderException, UnsupportedEncodingException
  {
    if (text == null) {
      return null;
    }
    if ((!text.startsWith("=?")) || (!text.endsWith("?="))) {
      throw new DecoderException("RFC 1522 violation: malformed encoded content");
    }
    int termnator = text.length() - 2;
    int from = 2;
    int to = text.indexOf("?", from);
    if ((to == -1) || (to == termnator)) {
      throw new DecoderException("RFC 1522 violation: charset token not found");
    }
    String charset = text.substring(from, to);
    if (charset.equals("")) {
      throw new DecoderException("RFC 1522 violation: charset not specified");
    }
    from = to + 1;
    to = text.indexOf("?", from);
    if ((to == -1) || (to == termnator)) {
      throw new DecoderException("RFC 1522 violation: encoding token not found");
    }
    String encoding = text.substring(from, to);
    if (!getEncoding().equalsIgnoreCase(encoding)) {
      throw new DecoderException("This codec cannot decode " + encoding + " encoded content");
    }
    from = to + 1;
    to = text.indexOf("?", from);
    byte[] data = text.substring(from, to).getBytes("US-ASCII");
    data = doDecoding(data);
    return new String(data, charset);
  }
  
  protected abstract String getEncoding();
  
  protected abstract byte[] doEncoding(byte[] paramArrayOfByte)
    throws EncoderException;
  
  protected abstract byte[] doDecoding(byte[] paramArrayOfByte)
    throws DecoderException;
}

/* Location:
 * Qualified Name:     org.apache.commons.codec.net.RFC1522Codec
 * Java Class Version: 1.2 (46.0)
 * JD-Core Version:    0.7.1
 */
package org.apache.commons.codec.net;

abstract interface StringEncodings
{
  public static final String US_ASCII = "US-ASCII";
  public static final String UTF8 = "UTF-8";
}

/* Location:
 * Qualified Name:     org.apache.commons.codec.net.StringEncodings
 * Java Class Version: 1.2 (46.0)
 * JD-Core Version:    0.7.1
 */
package org.apache.commons.codec.net;

import java.io.ByteArrayOutputStream;
import java.io.UnsupportedEncodingException;
import java.util.BitSet;
import org.apache.commons.codec.BinaryDecoder;
import org.apache.commons.codec.BinaryEncoder;
import org.apache.commons.codec.DecoderException;
import org.apache.commons.codec.EncoderException;
import org.apache.commons.codec.StringDecoder;
import org.apache.commons.codec.StringEncoder;

public class URLCodec
  implements BinaryEncoder, BinaryDecoder, StringEncoder, StringDecoder
{
  protected String charset = "UTF-8";
  protected static byte ESCAPE_CHAR = 37;
  protected static final BitSet WWW_FORM_URL = new BitSet(256);
  
  static
  {
    for (int i = 97; i <= 122; i++) {
      WWW_FORM_URL.set(i);
    }
    for (int i = 65; i <= 90; i++) {
      WWW_FORM_URL.set(i);
    }
    for (int i = 48; i <= 57; i++) {
      WWW_FORM_URL.set(i);
    }
    WWW_FORM_URL.set(45);
    WWW_FORM_URL.set(95);
    WWW_FORM_URL.set(46);
    WWW_FORM_URL.set(42);
    
    WWW_FORM_URL.set(32);
  }
  
  public URLCodec(String charset)
  {
    this.charset = charset;
  }
  
  public static final byte[] encodeUrl(BitSet urlsafe, byte[] bytes)
  {
    if (bytes == null) {
      return null;
    }
    if (urlsafe == null) {
      urlsafe = WWW_FORM_URL;
    }
    ByteArrayOutputStream buffer = new ByteArrayOutputStream();
    for (int i = 0; i < bytes.length; i++)
    {
      int b = bytes[i];
      if (b < 0) {
        b = 256 + b;
      }
      if (urlsafe.get(b))
      {
        if (b == 32) {
          b = 43;
        }
        buffer.write(b);
      }
      else
      {
        buffer.write(37);
        char hex1 = Character.toUpperCase(Character.forDigit(b >> 4 & 0xF, 16));
        
        char hex2 = Character.toUpperCase(Character.forDigit(b & 0xF, 16));
        
        buffer.write(hex1);
        buffer.write(hex2);
      }
    }
    return buffer.toByteArray();
  }
  
  public static final byte[] decodeUrl(byte[] bytes)
    throws DecoderException
  {
    if (bytes == null) {
      return null;
    }
    ByteArrayOutputStream buffer = new ByteArrayOutputStream();
    for (int i = 0; i < bytes.length; i++)
    {
      int b = bytes[i];
      if (b == 43) {
        buffer.write(32);
      } else if (b == 37) {
        try
        {
          int u = Character.digit((char)bytes[(++i)], 16);
          int l = Character.digit((char)bytes[(++i)], 16);
          if ((u == -1) || (l == -1)) {
            throw new DecoderException("Invalid URL encoding");
          }
          buffer.write((char)((u << 4) + l));
        }
        catch (ArrayIndexOutOfBoundsException e)
        {
          throw new DecoderException("Invalid URL encoding");
        }
      } else {
        buffer.write(b);
      }
    }
    return buffer.toByteArray();
  }
  
  public byte[] encode(byte[] bytes)
  {
    return encodeUrl(WWW_FORM_
1 2 3

Further reading...

For more information on Java 1.5 Tiger, you may find Java 1.5 Tiger, A developer's Notebook by D. Flanagan and B. McLaughlin from O'Reilly of interest.

New!JAR listings


Copyright 2006-2019. Infinite Loop Ltd