commons-codec-1.4

16:34:39.752 INFO  jd.cli.Main - Decompiling commons-codec-1.4.jar
package org.apache.commons.codec.binary;

import java.math.BigInteger;
import org.apache.commons.codec.BinaryDecoder;
import org.apache.commons.codec.BinaryEncoder;
import org.apache.commons.codec.DecoderException;
import org.apache.commons.codec.EncoderException;

public class Base64
  implements BinaryEncoder, BinaryDecoder
{
  private static final int DEFAULT_BUFFER_RESIZE_FACTOR = 2;
  private static final int DEFAULT_BUFFER_SIZE = 8192;
  static final int CHUNK_SIZE = 76;
  static final byte[] CHUNK_SEPARATOR = { 13, 10 };
  private static final byte[] STANDARD_ENCODE_TABLE = { 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 97, 98, 99, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 43, 47 };
  private static final byte[] URL_SAFE_ENCODE_TABLE = { 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 97, 98, 99, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 45, 95 };
  private static final byte PAD = 61;
  private static final byte[] DECODE_TABLE = { -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 62, -1, 62, -1, 63, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, -1, -1, -1, -1, -1, -1, -1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, -1, -1, -1, -1, 63, -1, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51 };
  private static final int MASK_6BITS = 63;
  private static final int MASK_8BITS = 255;
  private final byte[] encodeTable;
  private final int lineLength;
  private final byte[] lineSeparator;
  private final int decodeSize;
  private final int encodeSize;
  private byte[] buffer;
  private int pos;
  private int readPos;
  private int currentLinePos;
  private int modulus;
  private boolean eof;
  private int x;
  
  public Base64()
  {
    this(false);
  }
  
  public Base64(boolean urlSafe)
  {
    this(76, CHUNK_SEPARATOR, urlSafe);
  }
  
  public Base64(int lineLength)
  {
    this(lineLength, CHUNK_SEPARATOR);
  }
  
  public Base64(int lineLength, byte[] lineSeparator)
  {
    this(lineLength, lineSeparator, false);
  }
  
  public Base64(int lineLength, byte[] lineSeparator, boolean urlSafe)
  {
    if (lineSeparator == null)
    {
      lineLength = 0;
      lineSeparator = CHUNK_SEPARATOR;
    }
    this.lineLength = (lineLength > 0 ? lineLength / 4 * 4 : 0);
    this.lineSeparator = new byte[lineSeparator.length];
    System.arraycopy(lineSeparator, 0, this.lineSeparator, 0, lineSeparator.length);
    if (lineLength > 0) {
      encodeSize = (4 + lineSeparator.length);
    } else {
      encodeSize = 4;
    }
    decodeSize = (encodeSize - 1);
    if (containsBase64Byte(lineSeparator))
    {
      String sep = StringUtils.newStringUtf8(lineSeparator);
      throw new IllegalArgumentException("lineSeperator must not contain base64 characters: [" + sep + "]");
    }
    encodeTable = (urlSafe ? URL_SAFE_ENCODE_TABLE : STANDARD_ENCODE_TABLE);
  }
  
  public boolean isUrlSafe()
  {
    return encodeTable == URL_SAFE_ENCODE_TABLE;
  }
  
  boolean hasData()
  {
    return buffer != null;
  }
  
  int avail()
  {
    return buffer != null ? pos - readPos : 0;
  }
  
  private void resizeBuffer()
  {
    if (buffer == null)
    {
      buffer = new byte['?'];
      pos = 0;
      readPos = 0;
    }
    else
    {
      byte[] b = new byte[buffer.length * 2];
      System.arraycopy(buffer, 0, b, 0, buffer.length);
      buffer = b;
    }
  }
  
  int readResults(byte[] b, int bPos, int bAvail)
  {
    if (buffer != null)
    {
      int len = Math.min(avail(), bAvail);
      if (buffer != b)
      {
        System.arraycopy(buffer, readPos, b, bPos, len);
        readPos += len;
        if (readPos >= pos) {
          buffer = null;
        }
      }
      else
      {
        buffer = null;
      }
      return len;
    }
    return eof ? -1 : 0;
  }
  
  void setInitialBuffer(byte[] out, int outPos, int outAvail)
  {
    if ((out != null) && (out.length == outAvail))
    {
      buffer = out;
      pos = outPos;
      readPos = outPos;
    }
  }
  
  void encode(byte[] in, int inPos, int inAvail)
  {
    if (eof) {
      return;
    }
    if (inAvail < 0)
    {
      eof = true;
      if ((buffer == null) || (buffer.length - pos < encodeSize)) {
        resizeBuffer();
      }
      switch (modulus)
      {
      case 1: 
        buffer[(pos++)] = encodeTable[(x >> 2 & 0x3F)];
        buffer[(pos++)] = encodeTable[(x << 4 & 0x3F)];
        if (encodeTable == STANDARD_ENCODE_TABLE)
        {
          buffer[(pos++)] = 61;
          buffer[(pos++)] = 61;
        }
        break;
      case 2: 
        buffer[(pos++)] = encodeTable[(x >> 10 & 0x3F)];
        buffer[(pos++)] = encodeTable[(x >> 4 & 0x3F)];
        buffer[(pos++)] = encodeTable[(x << 2 & 0x3F)];
        if (encodeTable == STANDARD_ENCODE_TABLE) {
          buffer[(pos++)] = 61;
        }
        break;
      }
      if ((lineLength > 0) && (pos > 0))
      {
        System.arraycopy(lineSeparator, 0, buffer, pos, lineSeparator.length);
        pos += lineSeparator.length;
      }
    }
    else
    {
      for (int i = 0; i < inAvail; i++)
      {
        if ((buffer == null) || (buffer.length - pos < encodeSize)) {
          resizeBuffer();
        }
        modulus = (++modulus % 3);
        int b = in[(inPos++)];
        if (b < 0) {
          b += 256;
        }
        x = ((x << 8) + b);
        if (0 == modulus)
        {
          buffer[(pos++)] = encodeTable[(x >> 18 & 0x3F)];
          buffer[(pos++)] = encodeTable[(x >> 12 & 0x3F)];
          buffer[(pos++)] = encodeTable[(x >> 6 & 0x3F)];
          buffer[(pos++)] = encodeTable[(x & 0x3F)];
          currentLinePos += 4;
          if ((lineLength > 0) && (lineLength <= currentLinePos))
          {
            System.arraycopy(lineSeparator, 0, buffer, pos, lineSeparator.length);
            pos += lineSeparator.length;
            currentLinePos = 0;
          }
        }
      }
    }
  }
  
  void decode(byte[] in, int inPos, int inAvail)
  {
    if (eof) {
      return;
    }
    if (inAvail < 0) {
      eof = true;
    }
    for (int i = 0; i < inAvail; i++)
    {
      if ((buffer == null) || (buffer.length - pos < decodeSize)) {
        resizeBuffer();
      }
      byte b = in[(inPos++)];
      if (b == 61)
      {
        eof = true;
        break;
      }
      if ((b >= 0) && (b < DECODE_TABLE.length))
      {
        int result = DECODE_TABLE[b];
        if (result >= 0)
        {
          modulus = (++modulus % 4);
          x = ((x << 6) + result);
          if (modulus == 0)
          {
            buffer[(pos++)] = ((byte)(x >> 16 & 0xFF));
            buffer[(pos++)] = ((byte)(x >> 8 & 0xFF));
            buffer[(pos++)] = ((byte)(x & 0xFF));
          }
        }
      }
    }
    if ((eof) && (modulus != 0))
    {
      x <<= 6;
      switch (modulus)
      {
      case 2: 
        x <<= 6;
        buffer[(pos++)] = ((byte)(x >> 16 & 0xFF));
        break;
      case 3: 
        buffer[(pos++)] = ((byte)(x >> 16 & 0xFF));
        buffer[(pos++)] = ((byte)(x >> 8 & 0xFF));
      }
    }
  }
  
  public static boolean isBase64(byte octet)
  {
    return (octet == 61) || ((octet >= 0) && (octet < DECODE_TABLE.length) && (DECODE_TABLE[octet] != -1));
  }
  
  public static boolean isArrayByteBase64(byte[] arrayOctet)
  {
    for (int i = 0; i < arrayOctet.length; i++) {
      if ((!isBase64(arrayOctet[i])) && (!isWhiteSpace(arrayOctet[i]))) {
        return false;
      }
    }
    return true;
  }
  
  private static boolean containsBase64Byte(byte[] arrayOctet)
  {
    for (int i = 0; i < arrayOctet.length; i++) {
      if (isBase64(arrayOctet[i])) {
        return true;
      }
    }
    return false;
  }
  
  public static byte[] encodeBase64(byte[] binaryData)
  {
    return encodeBase64(binaryData, false);
  }
  
  public static String encodeBase64String(byte[] binaryData)
  {
    return StringUtils.newStringUtf8(encodeBase64(binaryData, true));
  }
  
  public static byte[] encodeBase64URLSafe(byte[] binaryData)
  {
    return encodeBase64(binaryData, false, true);
  }
  
  public static String encodeBase64URLSafeString(byte[] binaryData)
  {
    return StringUtils.newStringUtf8(encodeBase64(binaryData, false, true));
  }
  
  public static byte[] encodeBase64Chunked(byte[] binaryData)
  {
    return encodeBase64(binaryData, true);
  }
  
  public Object decode(Object pObject)
    throws DecoderException
  {
    if ((pObject instanceof byte[])) {
      return decode((byte[])pObject);
    }
    if ((pObject instanceof String)) {
      return decode((String)pObject);
    }
    throw new DecoderException("Parameter supplied to Base64 decode is not a byte[] or a String");
  }
  
  public byte[] decode(String pArray)
  {
    return decode(StringUtils.getBytesUtf8(pArray));
  }
  
  public byte[] decode(byte[] pArray)
  {
    reset();
    if ((pArray == null) || (pArray.length == 0)) {
      return pArray;
    }
    long len = pArray.length * 3 / 4;
    byte[] buf = new byte[(int)len];
    setInitialBuffer(buf, 0, buf.length);
    decode(pArray, 0, pArray.length);
    decode(pArray, 0, -1);
    
    byte[] result = new byte[pos];
    readResults(result, 0, result.length);
    return result;
  }
  
  public static byte[] encodeBase64(byte[] binaryData, boolean isChunked)
  {
    return encodeBase64(binaryData, isChunked, false);
  }
  
  public static byte[] encodeBase64(byte[] binaryData, boolean isChunked, boolean urlSafe)
  {
    return encodeBase64(binaryData, isChunked, urlSafe, Integer.MAX_VALUE);
  }
  
  public static byte[] encodeBase64(byte[] binaryData, boolean isChunked, boolean urlSafe, int maxResultSize)
  {
    if ((binaryData == null) || (binaryData.length == 0)) {
      return binaryData;
    }
    long len = getEncodeLength(binaryData, 76, CHUNK_SEPARATOR);
    if (len > maxResultSize) {
      throw new IllegalArgumentException("Input array too big, the output array would be bigger (" + len + ") than the specified maxium size of " + maxResultSize);
    }
    Base64 b64 = isChunked ? new Base64(urlSafe) : new Base64(0, CHUNK_SEPARATOR, urlSafe);
    return b64.encode(binaryData);
  }
  
  public static byte[] decodeBase64(String base64String)
  {
    return new Base64().decode(base64String);
  }
  
  public static byte[] decodeBase64(byte[] base64Data)
  {
    return new Base64().decode(base64Data);
  }
  
  /**
   * @deprecated
   */
  static byte[] discardWhitespace(byte[] data)
  {
    byte[] groomedData = new byte[data.length];
    int bytesCopied = 0;
    for (int i = 0; i < data.length; i++) {
      switch (data[i])
      {
      case 9: 
      case 10: 
      case 13: 
      case 32: 
        break;
      default: 
        groomedData[(bytesCopied++)] = data[i];
      }
    }
    byte[] packedData = new byte[bytesCopied];
    System.arraycopy(groomedData, 0, packedData, 0, bytesCopied);
    return packedData;
  }
  
  private static boolean isWhiteSpace(byte byteToCheck)
  {
    switch (byteToCheck)
    {
    case 9: 
    case 10: 
    case 13: 
    case 32: 
      return true;
    }
    return false;
  }
  
  public Object encode(Object pObject)
    throws EncoderException
  {
    if (!(pObject instanceof byte[])) {
      throw new EncoderException("Parameter supplied to Base64 encode is not a byte[]");
    }
    return encode((byte[])pObject);
  }
  
  public String encodeToString(byte[] pArray)
  {
    return StringUtils.newStringUtf8(encode(pArray));
  }
  
  public byte[] encode(byte[] pArray)
  {
    reset();
    if ((pArray == null) || (pArray.length == 0)) {
      return pArray;
    }
    long len = getEncodeLength(pArray, lineLength, lineSeparator);
    byte[] buf = new byte[(int)len];
    setInitialBuffer(buf, 0, buf.length);
    encode(pArray, 0, pArray.length);
    encode(pArray, 0, -1);
    if (buffer != buf) {
      readResults(buf, 0, buf.length);
    }
    if ((isUrlSafe()) && (pos < buf.length))
    {
      byte[] smallerBuf = new byte[pos];
      System.arraycopy(buf, 0, smallerBuf, 0, pos);
      buf = smallerBuf;
    }
    return buf;
  }
  
  private static long getEncodeLength(byte[] pArray, int chunkSize, byte[] chunkSeparator)
  {
    chunkSize = chunkSize / 4 * 4;
    
    long len = pArray.length * 4 / 3;
    long mod = len % 4L;
    if (mod != 0L) {
      len += 4L - mod;
    }
    if (chunkSize > 0)
    {
      boolean lenChunksPerfectly = len % chunkSize == 0L;
      len += len / chunkSize * chunkSeparator.length;
      if (!lenChunksPerfectly) {
        len += chunkSeparator.length;
      }
    }
    return len;
  }
  
  public static BigInteger decodeInteger(byte[] pArray)
  {
    return new BigInteger(1, decodeBase64(pArray));
  }
  
  public static byte[] encodeInteger(BigInteger bigInt)
  {
    if (bigInt == null) {
      throw new NullPointerException("encodeInteger called with null parameter");
    }
    return encodeBase64(toIntegerBytes(bigInt), false);
  }
  
  static byte[] toIntegerBytes(BigInteger bigInt)
  {
    int bitlen = bigInt.bitLength();
    
    bitlen = bitlen + 7 >> 3 << 3;
    byte[] bigBytes = bigInt.toByteArray();
    if ((bigInt.bitLength() % 8 != 0) && (bigInt.bitLength() / 8 + 1 == bitlen / 8)) {
      return bigBytes;
    }
    int startSrc = 0;
    int len = bigBytes.length;
    if (bigInt.bitLength() % 8 == 0)
    {
      startSrc = 1;
      len--;
    }
    int startDst = bitlen / 8 - len;
    byte[] resizedBytes = new byte[bitlen / 8];
    System.arraycopy(bigBytes, startSrc, resizedBytes, startDst, len);
    return resizedBytes;
  }
  
  private void reset()
  {
    buffer = null;
    pos = 0;
    readPos = 0;
    currentLinePos = 0;
    modulus = 0;
    eof = false;
  }
}

/* Location:
 * Qualified Name:     org.apache.commons.codec.binary.Base64
 * Java Class Version: 1.4 (48.0)
 * JD-Core Version:    0.7.1
 */
package org.apache.commons.codec.binary;

import java.io.FilterInputStream;
import java.io.IOException;
import java.io.InputStream;

public class Base64InputStream
  extends FilterInputStream
{
  private final boolean doEncode;
  private final Base64 base64;
  private final byte[] singleByte = new byte[1];
  
  public Base64InputStream(InputStream in)
  {
    this(in, false);
  }
  
  public Base64InputStream(InputStream in, boolean doEncode)
  {
    super(in);
    this.doEncode = doEncode;
    base64 = new Base64();
  }
  
  public Base64InputStream(InputStream in, boolean doEncode, int lineLength, byte[] lineSeparator)
  {
    super(in);
    this.doEncode = doEncode;
    base64 = new Base64(lineLength, lineSeparator);
  }
  
  public int read()
    throws IOException
  {
    int r = read(singleByte, 0, 1);
    while (r == 0) {
      r = read(singleByte, 0, 1);
    }
    if (r > 0) {
      return singleByte[0] < 0 ? 256 + singleByte[0] : singleByte[0];
    }
    return -1;
  }
  
  public int read(byte[] b, int offset, int len)
    throws IOException
  {
    if (b == null) {
      throw new NullPointerException();
    }
    if ((offset < 0) || (len < 0)) {
      throw new IndexOutOfBoundsException();
    }
    if ((offset > b.length) || (offset + len > b.length)) {
      throw new IndexOutOfBoundsException();
    }
    if (len == 0) {
      return 0;
    }
    if (!base64.hasData())
    {
      byte[] buf = new byte[doEncode ? '?' : '?'];
      int c = in.read(buf);
      if ((c > 0) && (b.length == len)) {
        base64.setInitialBuffer(b, offset, len);
      }
      if (doEncode) {
        base64.encode(buf, 0, c);
      } else {
        base64.decode(buf, 0, c);
      }
    }
    return base64.readResults(b, offset, len);
  }
  
  public boolean markSupported()
  {
    return false;
  }
}

/* Location:
 * Qualified Name:     org.apache.commons.codec.binary.Base64InputStream
 * Java Class Version: 1.4 (48.0)
 * JD-Core Version:    0.7.1
 */
package org.apache.commons.codec.binary;

import java.io.FilterOutputStream;
import java.io.IOException;
import java.io.OutputStream;

public class Base64OutputStream
  extends FilterOutputStream
{
  private final boolean doEncode;
  private final Base64 base64;
  private final byte[] singleByte = new byte[1];
  
  public Base64OutputStream(OutputStream out)
  {
    this(out, true);
  }
  
  public Base64OutputStream(OutputStream out, boolean doEncode)
  {
    super(out);
    this.doEncode = doEncode;
    base64 = new Base64();
  }
  
  public Base64OutputStream(OutputStream out, boolean doEncode, int lineLength, byte[] lineSeparator)
  {
    super(out);
    this.doEncode = doEncode;
    base64 = new Base64(lineLength, lineSeparator);
  }
  
  public void write(int i)
    throws IOException
  {
    singleByte[0] = ((byte)i);
    write(singleByte, 0, 1);
  }
  
  public void write(byte[] b, int offset, int len)
    throws IOException
  {
    if (b == null) {
      throw new NullPointerException();
    }
    if ((offset < 0) || (len < 0)) {
      throw new IndexOutOfBoundsException();
    }
    if ((offset > b.length) || (offset + len > b.length)) {
      throw new IndexOutOfBoundsException();
    }
    if (len > 0)
    {
      if (doEncode) {
        base64.encode(b, offset, len);
      } else {
        base64.decode(b, offset, len);
      }
      flush(false);
    }
  }
  
  private void flush(boolean propogate)
    throws IOException
  {
    int avail = base64.avail();
    if (avail > 0)
    {
      byte[] buf = new byte[avail];
      int c = base64.readResults(buf, 0, avail);
      if (c > 0) {
        out.write(buf, 0, c);
      }
    }
    if (propogate) {
      out.flush();
    }
  }
  
  public void flush()
    throws IOException
  {
    flush(true);
  }
  
  public void close()
    throws IOException
  {
    if (doEncode) {
      base64.encode(singleByte, 0, -1);
    } else {
      base64.decode(singleByte, 0, -1);
    }
    flush();
    out.close();
  }
}

/* Location:
 * Qualified Name:     org.apache.commons.codec.binary.Base64OutputStream
 * Java Class Version: 1.4 (48.0)
 * JD-Core Version:    0.7.1
 */
package org.apache.commons.codec.binary;

import org.apache.commons.codec.BinaryDecoder;
import org.apache.commons.codec.BinaryEncoder;
import org.apache.commons.codec.DecoderException;
import org.apache.commons.codec.EncoderException;

public class BinaryCodec
  implements BinaryDecoder, BinaryEncoder
{
  private static final char[] EMPTY_CHAR_ARRAY = new char[0];
  private static final byte[] EMPTY_BYTE_ARRAY = new byte[0];
  private static final int BIT_0 = 1;
  private static final int BIT_1 = 2;
  private static final int BIT_2 = 4;
  private static final int BIT_3 = 8;
  private static final int BIT_4 = 16;
  private static final int BIT_5 = 32;
  private static final int BIT_6 = 64;
  private static final int BIT_7 = 128;
  private static final int[] BITS = { 1, 2, 4, 8, 16, 32, 64, 128 };
  
  public byte[] encode(byte[] raw)
  {
    return toAsciiBytes(raw);
  }
  
  public Object encode(Object raw)
    throws EncoderException
  {
    if (!(raw instanceof byte[])) {
      throw new EncoderException("argument not a byte array");
    }
    return toAsciiChars((byte[])raw);
  }
  
  public Object decode(Object ascii)
    throws DecoderException
  {
    if (ascii == null) {
      return EMPTY_BYTE_ARRAY;
    }
    if ((ascii instanceof byte[])) {
      return fromAscii((byte[])ascii);
    }
    if ((ascii instanceof char[])) {
      return fromAscii((char[])ascii);
    }
    if ((ascii instanceof String)) {
      return fromAscii(((String)ascii).toCharArray());
    }
    throw new DecoderException("argument not a byte array");
  }
  
  public byte[] decode(byte[] ascii)
  {
    return fromAscii(ascii);
  }
  
  public byte[] toByteArray(String ascii)
  {
    if (ascii == null) {
      return EMPTY_BYTE_ARRAY;
    }
    return fromAscii(ascii.toCharArray());
  }
  
  public static byte[] fromAscii(char[] ascii)
  {
    if ((ascii == null) || (ascii.length == 0)) {
      return EMPTY_BYTE_ARRAY;
    }
    byte[] l_raw = new byte[ascii.length >> 3];
    
    int ii = 0;
    for (int jj = ascii.length - 1; ii < l_raw.length; jj -= 8)
    {
      for (int bits = 0; bits < BITS.length; bits++) {
        if (ascii[(jj - bits)] == '1')
        {
          int tmp58_57 = ii; byte[] tmp58_56 = l_raw;tmp58_56[tmp58_57] = ((byte)(tmp58_56[tmp58_57] | BITS[bits]));
        }
      }
      ii++;
    }
    return l_raw;
  }
  
  public static byte[] fromAscii(byte[] ascii)
  {
    if (isEmpty(ascii)) {
      return EMPTY_BYTE_ARRAY;
    }
    byte[] l_raw = new byte[ascii.length >> 3];
    
    int ii = 0;
    for (int jj = ascii.length - 1; ii < l_raw.length; jj -= 8)
    {
      for (int bits = 0; bits < BITS.length; bits++) {
        if (ascii[(jj - bits)] == 49)
        {
          int tmp56_55 = ii; byte[] tmp56_54 = l_raw;tmp56_54[tmp56_55] = ((byte)(tmp56_54[tmp56_55] | BITS[bits]));
        }
      }
      ii++;
    }
    return l_raw;
  }
  
  private static boolean isEmpty(byte[] array)
  {
    return (array == null) || (array.length == 0);
  }
  
  public static byte[] toAsciiBytes(byte[] raw)
  {
    if (isEmpty(raw)) {
      return EMPTY_BYTE_ARRAY;
    }
    byte[] l_ascii = new byte[raw.length << 3];
    
    int ii = 0;
    for (int jj = l_ascii.length - 1; ii < raw.length; jj -= 8)
    {
      for (int bits = 0; bits < BITS.length; bits++) {
        if ((raw[ii] & BITS[bits]) == 0) {
          l_ascii[(jj - bits)] = 48;
        } else {
          l_ascii[(jj - bits)] = 49;
        }
      }
      ii++;
    }
    return l_ascii;
  }
  
  public static char[] toAsciiChars(byte[] raw)
  {
    if (isEmpty(raw)) {
      return EMPTY_CHAR_ARRAY;
    }
    char[] l_ascii = new char[raw.length << 3];
    
    int ii = 0;
    for (int jj = l_ascii.length - 1; ii < raw.length; jj -= 8)
    {
      for (int bits = 0; bits < BITS.length; bits++) {
        if ((raw[ii] & BITS[bits]) == 0) {
          l_ascii[(jj - bits)] = '0';
        } else {
          l_ascii[(jj - bits)] = '1';
        }
      }
      ii++;
    }
    return l_ascii;
  }
  
  public static String toAsciiString(byte[] raw)
  {
    return new String(toAsciiChars(raw));
  }
}

/* Location:
 * Qualified Name:     org.apache.commons.codec.binary.BinaryCodec
 * Java Class Version: 1.4 (48.0)
 * JD-Core Version:    0.7.1
 */
package org.apache.commons.codec.binary;

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

public class Hex
  implements BinaryEncoder, BinaryDecoder
{
  public static final String DEFAULT_CHARSET_NAME = "UTF-8";
  private static final char[] DIGITS_LOWER = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f' };
  private static final char[] DIGITS_UPPER = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F' };
  private final String charsetName;
  
  public static byte[] decodeHex(char[] data)
    throws DecoderException
  {
    int len = data.length;
    if ((len & 0x1) != 0) {
      throw new DecoderException("Odd number of characters.");
    }
    byte[] out = new byte[len >> 1];
    
    int i = 0;
    for (int j = 0; j < len; i++)
    {
      int f = toDigit(data[j], j) << 4;
      j++;
      f |= toDigit(data[j], j);
      j++;
      out[i] = ((byte)(f & 0xFF));
    }
    return out;
  }
  
  public static char[] encodeHex(byte[] data)
  {
    return encodeHex(data, true);
  }
  
  public static char[] encodeHex(byte[] data, boolean toLowerCase)
  {
    return encodeHex(data, toLowerCase ? DIGITS_LOWER : DIGITS_UPPER);
  }
  
  protected static char[] encodeHex(byte[] data, char[] toDigits)
  {
    int l = data.length;
    char[] out = new char[l << 1];
    
    int i = 0;
    for (int j = 0; i < l; i++)
    {
      out[(j++)] = toDigits[((0xF0 & data[i]) >>> 4)];
      out[(j++)] = toDigits[(0xF & data[i])];
    }
    return out;
  }
  
  public static String encodeHexString(byte[] data)
  {
    return new String(encodeHex(data));
  }
  
  protected static int toDigit(char ch, int index)
    throws DecoderException
  {
    int digit = Character.digit(ch, 16);
    if (digit == -1) {
      throw new DecoderException("Illegal hexadecimal charcter " + ch + " at index " + index);
    }
    return digit;
  }
  
  public Hex()
  {
    charsetName = "UTF-8";
  }
  
  public Hex(String csName)
  {
    charsetName = csName;
  }
  
  public byte[] decode(byte[] array)
    throws DecoderException
  {
    try
    {
      return decodeHex(new String(array, getCharsetName()).toCharArray());
    }
    catch (UnsupportedEncodingException e)
    {
      throw new DecoderException(e.getMessage(), e);
    }
  }
  
  public Object decode(Object object)
    throws DecoderException
  {
    try
    {
      char[] charArray = (object instanceof String) ? ((String)object).toCharArray() : (char[])object;
      return decodeHex(charArray);
    }
    catch (ClassCastException e)
    {
      throw new DecoderException(e.getMessage(), e);
    }
  }
  
  public byte[] encode(byte[] array)
  {
    return StringUtils.getBytesUnchecked(encodeHexString(array), getCharsetName());
  }
  
  public Object encode(Object object)
    throws EncoderException
  {
    try
    {
      byte[] byteArray = (object instanceof String) ? ((String)object).getBytes(getCharsetName()) : (byte[])object;
      return encodeHex(byteArray);
    }
    catch (ClassCastException e)
    {
      throw new EncoderException(e.getMessage(), e);
    }
    catch (UnsupportedEncodingException e)
    {
      throw new EncoderException(e.getMessage(), e);
    }
  }
  
  public String getCharsetName()
  {
    return charsetName;
  }
  
  public String toString()
  {
    return super.toString() + "[charsetName=" + charsetName + "]";
  }
}

/* Location:
 * Qualified Name:     org.apache.commons.codec.binary.Hex
 * Java Class Version: 1.4 (48.0)
 * JD-Core Version:    0.7.1
 */
package org.apache.commons.codec.binary;

import java.io.UnsupportedEncodingException;

public class StringUtils
{
  public static byte[] getBytesIso8859_1(String string)
  {
    return getBytesUnchecked(string, "ISO-8859-1");
  }
  
  public static byte[] getBytesUsAscii(String string)
  {
    return getBytesUnchecked(string, "US-ASCII");
  }
  
  public static byte[] getBytesUtf16(String string)
  {
    return getBytesUnchecked(string, "UTF-16");
  }
  
  public static byte[] getBytesUtf16Be(String string)
  {
    return getBytesUnchecked(string, "UTF-16BE");
  }
  
  public static byte[] getBytesUtf16Le(String string)
  {
    return getBytesUnchecked(string, "UTF-16LE");
  }
  
  public static byte[] getBytesUtf8(String string)
  {
    return getBytesUnchecked(string, "UTF-8");
  }
  
  public static byte[] getBytesUnchecked(String string, String charsetName)
  {
    if (string == null) {
      return null;
    }
    try
    {
      return string.getBytes(charsetName);
    }
    catch (UnsupportedEncodingException e)
    {
      throw newIllegalStateException(charsetName, e);
    }
  }
  
  private static IllegalStateException newIllegalStateException(String charsetName, UnsupportedEncodingException e)
  {
    return new IllegalStateException(charsetName + ": " + e);
  }
  
  public static String newString(byte[] bytes, String charsetName)
  {
    if (bytes == null) {
      return null;
    }
    try
    {
      return new String(bytes, charsetName);
    }
    catch (UnsupportedEncodingException e)
    {
      throw newIllegalStateException(charsetName, e);
    }
  }
  
  public static String newStringIso8859_1(byte[] bytes)
  {
    return newString(bytes, "ISO-8859-1");
  }
  
  public static String newStringUsAscii(byte[] bytes)
  {
    return newString(bytes, "US-ASCII");
  }
  
  public static String newStringUtf16(byte[] bytes)
  {
    return newString(bytes, "UTF-16");
  }
  
  public static String newStringUtf16Be(byte[] bytes)
  {
    return newString(bytes, "UTF-16BE");
  }
  
  public static String newStringUtf16Le(byte[] bytes)
  {
    return newString(bytes, "UTF-16LE");
  }
  
  public static String newStringUtf8(byte[] bytes)
  {
    return newString(bytes, "UTF-8");
  }
}

/* Location:
 * Qualified Name:     org.apache.commons.codec.binary.StringUtils
 * Java Class Version: 1.4 (48.0)
 * JD-Core Version:    0.7.1
 */
package org.apache.commons.codec;

public abstract interface BinaryDecoder
  extends Decoder
{
  public abstract byte[] decode(byte[] paramArrayOfByte)
    throws DecoderException;
}

/* Location:
 * Qualified Name:     org.apache.commons.codec.BinaryDecoder
 * Java Class Version: 1.4 (48.0)
 * JD-Core Version:    0.7.1
 */
package org.apache.commons.codec;

public abstract interface BinaryEncoder
  extends Encoder
{
  public abstract byte[] encode(byte[] paramArrayOfByte)
    throws EncoderException;
}

/* Location:
 * Qualified Name:     org.apache.commons.codec.BinaryEncoder
 * Java Class Version: 1.4 (48.0)
 * JD-Core Version:    0.7.1
 */
package org.apache.commons.codec;

public class CharEncoding
{
  public static final String ISO_8859_1 = "ISO-8859-1";
  public static final String US_ASCII = "US-ASCII";
  public static final String UTF_16 = "UTF-16";
  public static final String UTF_16BE = "UTF-16BE";
  public static final String UTF_16LE = "UTF-16LE";
  public static final String UTF_8 = "UTF-8";
}

/* Location:
 * Qualified Name:     org.apache.commons.codec.CharEncoding
 * Java Class Version: 1.4 (48.0)
 * JD-Core Version:    0.7.1
 */
package org.apache.commons.codec;

public abstract interface Decoder
{
  public abstract Object decode(Object paramObject)
    throws DecoderException;
}

/* Location:
 * Qualified Name:     org.apache.commons.codec.Decoder
 * Java Class Version: 1.4 (48.0)
 * JD-Core Version:    0.7.1
 */
package org.apache.commons.codec;

public class DecoderException
  extends Exception
{
  private static final long serialVersionUID = 1L;
  
  public DecoderException() {}
  
  public DecoderException(String message)
  {
    super(message);
  }
  
  public DecoderException(String message, Throwable cause)
  {
    super(message, cause);
  }
  
  public DecoderException(Throwable cause)
  {
    super(cause);
  }
}

/* Location:
 * Qualified Name:     org.apache.commons.codec.DecoderException
 * Java Class Version: 1.4 (48.0)
 * JD-Core Version:    0.7.1
 */
package org.apache.commons.codec.digest;

import java.io.IOException;
import java.io.InputStream;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import org.apache.commons.codec.binary.Hex;
import org.apache.commons.codec.binary.StringUtils;

public class DigestUtils
{
  private static final int STREAM_BUFFER_LENGTH = 1024;
  
  private static byte[] digest(MessageDigest digest, InputStream data)
    throws IOException
  {
    byte[] buffer = new byte['?'];
    int read = data.read(buffer, 0, 1024);
    while (read > -1)
    {
      digest.update(buffer, 0, read);
      read = data.read(buffer, 0, 1024);
    }
    return digest.digest();
  }
  
  private static byte[] getBytesUtf8(String data)
  {
    return StringUtils.getBytesUtf8(data);
  }
  
  static MessageDigest getDigest(String algorithm)
  {
    try
    {
      return MessageDigest.getInstance(algorithm);
    }
    catch (NoSuchAlgorithmException e)
    {
      throw new RuntimeException(e.getMessage());
    }
  }
  
  private static MessageDigest getMd5Digest()
  {
    return getDigest("MD5");
  }
  
  private static MessageDigest getSha256Digest()
  {
    return getDigest("SHA-256");
  }
  
  private static MessageDigest getSha384Digest()
  {
    return getDigest("SHA-384");
  }
  
  private static MessageDigest getSha512Digest()
  {
    return getDigest("SHA-512");
  }
  
  private static MessageDigest getShaDigest()
  {
    return getDigest("SHA");
  }
  
  public static byte[] md5(byte[] data)
  {
    return getMd5Digest().digest(data);
  }
  
  public static byte[] md5(InputStream data)
    throws IOException
  {
    return digest(getMd5Digest(), data);
  }
  
  public static byte[] md5(String data)
  {
    return md5(getBytesUtf8(data));
  }
  
  public static String md5Hex(byte[] data)
  {
    return Hex.encodeHexString(md5(data));
  }
  
  public static String md5Hex(InputStream data)
    throws IOException
  {
    return Hex.encodeHexString(md5(data));
  }
  
  public static String md5Hex(String data)
  {
    return Hex.encodeHexString(md5(data));
  }
  
  public static byte[] sha(byte[] data)
  {
    return getShaDigest().digest(data);
  }
  
  public static byte[] sha(InputStream data)
    throws IOException
  {
    return digest(getShaDigest(), data);
  }
  
  public static byte[] sha(String data)
  {
    return sha(getBytesUtf8(data));
  }
  
  public static byte[] sha256(byte[] data)
  {
    return getSha256Digest().digest(data);
  }
  
  public static byte[] sha256(InputStream data)
    throws IOException
  {
    return digest(getSha256Digest(), data);
  }
  
  public static byte[] sha256(String data)
  {
    return sha256(getBytesUtf8(data));
  }
  
  public static String sha256Hex(byte[] data)
  {
    return Hex.encodeHexString(sha256(data));
  }
  
  public static String sha256Hex(InputStream data)
    throws IOException
  {
    return Hex.encodeHexString(sha256(data));
  }
  
  public static String sha256Hex(String data)
  {
    return Hex.encodeHexString(sha256(data));
  }
  
  public static byte[] sha384(byte[] data)
  {
    return getSha384Digest().digest(data);
  }
  
  public static byte[] sha384(InputStream data)
    throws IOException
  {
    return digest(getSha384Digest(), data);
  }
  
  public static byte[] sha384(String data)
  {
    return sha384(getBytesUtf8(data));
  }
  
  public static String sha384Hex(byte[] data)
  {
    return Hex.encodeHexString(sha384(data));
  }
  
  public static String sha384Hex(InputStream data)
    throws IOException
  {
    return Hex.encodeHexString(sha384(data));
  }
  
  public static String sha384Hex(String data)
  {
    return Hex.encodeHexString(sha384(data));
  }
  
  public static byte[] sha512(byte[] data)
  {
    return getSha512Digest().digest(data);
  }
  
  public static byte[] sha512(InputStream data)
    throws IOException
  {
    return digest(getSha512Digest(), data);
  }
  
  public static byte[] sha512(String data)
  {
    return sha512(getBytesUtf8(data));
  }
  
  public static String sha512Hex(byte[] data)
  {
    return Hex.encodeHexString(sha512(data));
  }
  
  public static String sha512Hex(InputStream data)
    throws IOException
  {
    return Hex.encodeHexString(sha512(data));
  }
  
  public static String sha512Hex(String data)
  {
    return Hex.encodeHexString(sha512(data));
  }
  
  public static String shaHex(byte[] data)
  {
    return Hex.encodeHexString(sha(data));
  }
  
  public static String shaHex(InputStream data)
    throws IOException
  {
    return Hex.encodeHexString(sha(data));
  }
  
  public static String shaHex(String data)
  {
    return Hex.encodeHexString(sha(data));
  }
}

/* Location:
 * Qualified Name:     org.apache.commons.codec.digest.DigestUtils
 * Java Class Version: 1.4 (48.0)
 * JD-Core Version:    0.7.1
 */
package org.apache.commons.codec;

public abstract interface Encoder
{
  public abstract Object encode(Object paramObject)
    throws EncoderException;
}

/* Location:
 * Qualified Name:     org.apache.commons.codec.Encoder
 * Java Class Version: 1.4 (48.0)
 * JD-Core Version:    0.7.1
 */
package org.apache.commons.codec;

public class EncoderException
  extends Exception
{
  private static final long serialVersionUID = 1L;
  
  public EncoderException() {}
  
  public EncoderException(String message)
  {
    super(message);
  }
  
  public EncoderException(String message, Throwable cause)
  {
    super(message, cause);
  }
  
  public EncoderException(Throwable cause)
  {
    super(cause);
  }
}

/* Location:
 * Qualified Name:     org.apache.commons.codec.EncoderException
 * Java Class Version: 1.4 (48.0)
 * JD-Core Version:    0.7.1
 */
package org.apache.commons.codec.language;

import java.util.Locale;
import org.apache.commons.codec.EncoderException;
import org.apache.commons.codec.StringEncoder;

public class Caverphone
  implements StringEncoder
{
  public String caverphone(String txt)
  {
    if ((txt == null) || (txt.length() == 0)) {
      return "1111111111";
    }
    txt = txt.toLowerCase(Locale.ENGLISH);
    
    txt = txt.replaceAll("[^a-z]", "");
    
    txt = txt.replaceAll("e$", "");
    
    txt = txt.replaceAll("^cough", "cou2f");
    txt = txt.replaceAll("^rough", "rou2f");
    txt = txt.replaceAll("^tough", "tou2f");
    txt = txt.replaceAll("^enough", "enou2f");
    txt = txt.replaceAll("^trough", "trou2f");
    txt = txt.replaceAll("^gn", "2n");
    txt = txt.replaceAll("^mb", "m2");
    
    txt = txt.replaceAll("cq", "2q");
    txt = txt.replaceAll("ci", "si");
    txt = txt.replaceAll("ce", "se");
    txt = txt.replaceAll("cy", "sy");
    txt = txt.replaceAll("tch", "2ch");
    txt = txt.replaceAll("c", "k");
    txt = txt.replaceAll("q", "k");
    txt = txt.replaceAll("x", "k");
    txt = txt.replaceAll("v", "f");
    txt = txt.replaceAll("dg", "2g");
    txt = txt.replaceAll("tio", "sio");
    txt = txt.replaceAll("tia", "sia");
    txt = txt.replaceAll("d", "t");
    txt = txt.replaceAll("ph", "fh");
    txt = txt.replaceAll("b", "p");
    txt = txt.replaceAll("sh", "s2");
    txt = txt.replaceAll("z", "s");
    txt = txt.replaceAll("^[aeiou]", "A");
    txt = txt.replaceAll("[aeiou]", "3");
    txt = txt.replaceAll("j", "y");
    txt = txt.replaceAll("^y3", "Y3");
    txt = txt.replaceAll("^y", "A");
    txt = txt.replaceAll("y", "3");
    txt = txt.replaceAll("3gh3", "3kh3");
    txt = txt.replaceAll("gh", "22");
    txt = txt.replaceAll("g", "k");
    txt = txt.replaceAll("s+", "S");
    txt = txt.replaceAll("t+", "T");
    txt = txt.replaceAll("p+", "P");
    txt = txt.replaceAll("k+", "K");
    txt = txt.replaceAll("f+", "F");
    txt = txt.replaceAll("m+", "M");
    txt = txt.replaceAll("n+", "N");
    txt = txt.replaceAll("w3", "W3");
    
    txt = txt.replaceAll("wh3", "Wh3");
    txt = txt.replaceAll("w$", "3");
    
    txt = txt.replaceAll("w", "2");
    txt = txt.replaceAll("^h", "A");
    txt = txt.replaceAll("h", "2");
    txt = txt.replaceAll("r3", "R3");
    txt = txt.replaceAll("r$", "3");
    
    txt = txt.replaceAll("r", "2");
    txt = txt.replaceAll("l3", "L3");
    txt = txt.replaceAll("l$", "3");
    
    txt = txt.replaceAll("l", "2");
    
    txt = txt.replaceAll("2", "");
    txt = txt.replaceAll("3$", "A");
    txt = txt.replaceAll("3", "");
    
    txt = txt + "111111" + "1111";
    
    return txt.substring(0, 10);
  }
  
  public Object encode(Object pObject)
    throws EncoderException
  {
    if (!(pObject instanceof String)) {
      throw new EncoderException("Parameter supplied to Caverphone encode is not of type java.lang.String");
    }
    return caverphone((String)pObject);
  }
  
  public String encode(String pString)
  {
    return caverphone(pString);
  }
  
  public boolean isCaverphoneEqual(String str1, String str2)
  {
    return caverphone(str1).equals(caverphone(str2));
  }
}

/* Location:
 * Qualified Name:     org.apache.commons.codec.language.Caverphone
 * Java Class Version: 1.4 (48.0)
 * JD-Core Version:    0.7.1
 */
package org.apache.commons.codec.language;

public class DoubleMetaphone$DoubleMetaphoneResult
{
  private StringBuffer primary = new StringBuff
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-2017. Infinite Loop Ltd