commons-codec-1.6

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

public class Base32
  extends BaseNCodec
{
  private static final int BITS_PER_ENCODED_BYTE = 5;
  private static final int BYTES_PER_ENCODED_BLOCK = 8;
  private static final int BYTES_PER_UNENCODED_BLOCK = 5;
  private static final byte[] CHUNK_SEPARATOR = { 13, 10 };
  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, -1, -1, -1, -1, 63, -1, -1, 26, 27, 28, 29, 30, 31, -1, -1, -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 };
  private static final byte[] 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, 50, 51, 52, 53, 54, 55 };
  private static final byte[] HEX_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, -1, -1, -1, -1, 63, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, -1, -1, -1, -1, -1, -1, -1, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32 };
  private static final byte[] HEX_ENCODE_TABLE = { 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86 };
  private static final int MASK_5BITS = 31;
  private long bitWorkArea;
  private final int decodeSize;
  private final byte[] decodeTable;
  private final int encodeSize;
  private final byte[] encodeTable;
  private final byte[] lineSeparator;
  
  public Base32()
  {
    this(false);
  }
  
  public Base32(boolean useHex)
  {
    this(0, null, useHex);
  }
  
  public Base32(int lineLength)
  {
    this(lineLength, CHUNK_SEPARATOR);
  }
  
  public Base32(int lineLength, byte[] lineSeparator)
  {
    this(lineLength, lineSeparator, false);
  }
  
  public Base32(int lineLength, byte[] lineSeparator, boolean useHex)
  {
    super(5, 8, lineLength, lineSeparator == null ? 0 : lineSeparator.length);
    if (useHex)
    {
      encodeTable = HEX_ENCODE_TABLE;
      decodeTable = HEX_DECODE_TABLE;
    }
    else
    {
      encodeTable = ENCODE_TABLE;
      decodeTable = DECODE_TABLE;
    }
    if (lineLength > 0)
    {
      if (lineSeparator == null) {
        throw new IllegalArgumentException("lineLength " + lineLength + " > 0, but lineSeparator is null");
      }
      if (containsAlphabetOrPad(lineSeparator))
      {
        String sep = StringUtils.newStringUtf8(lineSeparator);
        throw new IllegalArgumentException("lineSeparator must not contain Base32 characters: [" + sep + "]");
      }
      encodeSize = (8 + lineSeparator.length);
      this.lineSeparator = new byte[lineSeparator.length];
      System.arraycopy(lineSeparator, 0, this.lineSeparator, 0, lineSeparator.length);
    }
    else
    {
      encodeSize = 8;
      this.lineSeparator = null;
    }
    decodeSize = (encodeSize - 1);
  }
  
  void decode(byte[] in, int inPos, int inAvail)
  {
    if (eof) {
      return;
    }
    if (inAvail < 0) {
      eof = true;
    }
    for (int i = 0; i < inAvail; i++)
    {
      byte b = in[(inPos++)];
      if (b == 61)
      {
        eof = true;
        break;
      }
      ensureBufferSize(decodeSize);
      if ((b >= 0) && (b < decodeTable.length))
      {
        int result = decodeTable[b];
        if (result >= 0)
        {
          modulus = ((modulus + 1) % 8);
          bitWorkArea = ((bitWorkArea << 5) + result);
          if (modulus == 0)
          {
            buffer[(pos++)] = ((byte)(int)(bitWorkArea >> 32 & 0xFF));
            buffer[(pos++)] = ((byte)(int)(bitWorkArea >> 24 & 0xFF));
            buffer[(pos++)] = ((byte)(int)(bitWorkArea >> 16 & 0xFF));
            buffer[(pos++)] = ((byte)(int)(bitWorkArea >> 8 & 0xFF));
            buffer[(pos++)] = ((byte)(int)(bitWorkArea & 0xFF));
          }
        }
      }
    }
    if ((eof) && (modulus >= 2))
    {
      ensureBufferSize(decodeSize);
      switch (modulus)
      {
      case 2: 
        buffer[(pos++)] = ((byte)(int)(bitWorkArea >> 2 & 0xFF));
        break;
      case 3: 
        buffer[(pos++)] = ((byte)(int)(bitWorkArea >> 7 & 0xFF));
        break;
      case 4: 
        bitWorkArea >>= 4;
        buffer[(pos++)] = ((byte)(int)(bitWorkArea >> 8 & 0xFF));
        buffer[(pos++)] = ((byte)(int)(bitWorkArea & 0xFF));
        break;
      case 5: 
        bitWorkArea >>= 1;
        buffer[(pos++)] = ((byte)(int)(bitWorkArea >> 16 & 0xFF));
        buffer[(pos++)] = ((byte)(int)(bitWorkArea >> 8 & 0xFF));
        buffer[(pos++)] = ((byte)(int)(bitWorkArea & 0xFF));
        break;
      case 6: 
        bitWorkArea >>= 6;
        buffer[(pos++)] = ((byte)(int)(bitWorkArea >> 16 & 0xFF));
        buffer[(pos++)] = ((byte)(int)(bitWorkArea >> 8 & 0xFF));
        buffer[(pos++)] = ((byte)(int)(bitWorkArea & 0xFF));
        break;
      case 7: 
        bitWorkArea >>= 3;
        buffer[(pos++)] = ((byte)(int)(bitWorkArea >> 24 & 0xFF));
        buffer[(pos++)] = ((byte)(int)(bitWorkArea >> 16 & 0xFF));
        buffer[(pos++)] = ((byte)(int)(bitWorkArea >> 8 & 0xFF));
        buffer[(pos++)] = ((byte)(int)(bitWorkArea & 0xFF));
      }
    }
  }
  
  void encode(byte[] in, int inPos, int inAvail)
  {
    if (eof) {
      return;
    }
    if (inAvail < 0)
    {
      eof = true;
      if ((0 == modulus) && (lineLength == 0)) {
        return;
      }
      ensureBufferSize(encodeSize);
      int savedPos = pos;
      switch (modulus)
      {
      case 1: 
        buffer[(pos++)] = encodeTable[((int)(bitWorkArea >> 3) & 0x1F)];
        buffer[(pos++)] = encodeTable[((int)(bitWorkArea << 2) & 0x1F)];
        buffer[(pos++)] = 61;
        buffer[(pos++)] = 61;
        buffer[(pos++)] = 61;
        buffer[(pos++)] = 61;
        buffer[(pos++)] = 61;
        buffer[(pos++)] = 61;
        break;
      case 2: 
        buffer[(pos++)] = encodeTable[((int)(bitWorkArea >> 11) & 0x1F)];
        buffer[(pos++)] = encodeTable[((int)(bitWorkArea >> 6) & 0x1F)];
        buffer[(pos++)] = encodeTable[((int)(bitWorkArea >> 1) & 0x1F)];
        buffer[(pos++)] = encodeTable[((int)(bitWorkArea << 4) & 0x1F)];
        buffer[(pos++)] = 61;
        buffer[(pos++)] = 61;
        buffer[(pos++)] = 61;
        buffer[(pos++)] = 61;
        break;
      case 3: 
        buffer[(pos++)] = encodeTable[((int)(bitWorkArea >> 19) & 0x1F)];
        buffer[(pos++)] = encodeTable[((int)(bitWorkArea >> 14) & 0x1F)];
        buffer[(pos++)] = encodeTable[((int)(bitWorkArea >> 9) & 0x1F)];
        buffer[(pos++)] = encodeTable[((int)(bitWorkArea >> 4) & 0x1F)];
        buffer[(pos++)] = encodeTable[((int)(bitWorkArea << 1) & 0x1F)];
        buffer[(pos++)] = 61;
        buffer[(pos++)] = 61;
        buffer[(pos++)] = 61;
        break;
      case 4: 
        buffer[(pos++)] = encodeTable[((int)(bitWorkArea >> 27) & 0x1F)];
        buffer[(pos++)] = encodeTable[((int)(bitWorkArea >> 22) & 0x1F)];
        buffer[(pos++)] = encodeTable[((int)(bitWorkArea >> 17) & 0x1F)];
        buffer[(pos++)] = encodeTable[((int)(bitWorkArea >> 12) & 0x1F)];
        buffer[(pos++)] = encodeTable[((int)(bitWorkArea >> 7) & 0x1F)];
        buffer[(pos++)] = encodeTable[((int)(bitWorkArea >> 2) & 0x1F)];
        buffer[(pos++)] = encodeTable[((int)(bitWorkArea << 3) & 0x1F)];
        buffer[(pos++)] = 61;
      }
      currentLinePos += pos - savedPos;
      if ((lineLength > 0) && (currentLinePos > 0))
      {
        System.arraycopy(lineSeparator, 0, buffer, pos, lineSeparator.length);
        pos += lineSeparator.length;
      }
    }
    else
    {
      for (int i = 0; i < inAvail; i++)
      {
        ensureBufferSize(encodeSize);
        modulus = ((modulus + 1) % 5);
        int b = in[(inPos++)];
        if (b < 0) {
          b += 256;
        }
        bitWorkArea = ((bitWorkArea << 8) + b);
        if (0 == modulus)
        {
          buffer[(pos++)] = encodeTable[((int)(bitWorkArea >> 35) & 0x1F)];
          buffer[(pos++)] = encodeTable[((int)(bitWorkArea >> 30) & 0x1F)];
          buffer[(pos++)] = encodeTable[((int)(bitWorkArea >> 25) & 0x1F)];
          buffer[(pos++)] = encodeTable[((int)(bitWorkArea >> 20) & 0x1F)];
          buffer[(pos++)] = encodeTable[((int)(bitWorkArea >> 15) & 0x1F)];
          buffer[(pos++)] = encodeTable[((int)(bitWorkArea >> 10) & 0x1F)];
          buffer[(pos++)] = encodeTable[((int)(bitWorkArea >> 5) & 0x1F)];
          buffer[(pos++)] = encodeTable[((int)bitWorkArea & 0x1F)];
          currentLinePos += 8;
          if ((lineLength > 0) && (lineLength <= currentLinePos))
          {
            System.arraycopy(lineSeparator, 0, buffer, pos, lineSeparator.length);
            pos += lineSeparator.length;
            currentLinePos = 0;
          }
        }
      }
    }
  }
  
  public boolean isInAlphabet(byte octet)
  {
    return (octet >= 0) && (octet < decodeTable.length) && (decodeTable[octet] != -1);
  }
}

/* Location:
 * Qualified Name:     org.apache.commons.codec.binary.Base32
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package org.apache.commons.codec.binary;

import java.io.InputStream;

public class Base32InputStream
  extends BaseNCodecInputStream
{
  public Base32InputStream(InputStream in)
  {
    this(in, false);
  }
  
  public Base32InputStream(InputStream in, boolean doEncode)
  {
    super(in, new Base32(false), doEncode);
  }
  
  public Base32InputStream(InputStream in, boolean doEncode, int lineLength, byte[] lineSeparator)
  {
    super(in, new Base32(lineLength, lineSeparator), doEncode);
  }
}

/* Location:
 * Qualified Name:     org.apache.commons.codec.binary.Base32InputStream
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package org.apache.commons.codec.binary;

import java.io.OutputStream;

public class Base32OutputStream
  extends BaseNCodecOutputStream
{
  public Base32OutputStream(OutputStream out)
  {
    this(out, true);
  }
  
  public Base32OutputStream(OutputStream out, boolean doEncode)
  {
    super(out, new Base32(false), doEncode);
  }
  
  public Base32OutputStream(OutputStream out, boolean doEncode, int lineLength, byte[] lineSeparator)
  {
    super(out, new Base32(lineLength, lineSeparator), doEncode);
  }
}

/* Location:
 * Qualified Name:     org.apache.commons.codec.binary.Base32OutputStream
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package org.apache.commons.codec.binary;

import java.math.BigInteger;

public class Base64
  extends BaseNCodec
{
  private static final int BITS_PER_ENCODED_BYTE = 6;
  private static final int BYTES_PER_UNENCODED_BLOCK = 3;
  private static final int BYTES_PER_ENCODED_BLOCK = 4;
  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[] 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 final byte[] encodeTable;
  private final byte[] decodeTable = DECODE_TABLE;
  private final byte[] lineSeparator;
  private final int decodeSize;
  private final int encodeSize;
  private int bitWorkArea;
  
  public Base64()
  {
    this(0);
  }
  
  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)
  {
    super(3, 4, lineLength, lineSeparator == null ? 0 : lineSeparator.length);
    if (lineSeparator != null)
    {
      if (containsAlphabetOrPad(lineSeparator))
      {
        String sep = StringUtils.newStringUtf8(lineSeparator);
        throw new IllegalArgumentException("lineSeparator must not contain base64 characters: [" + sep + "]");
      }
      if (lineLength > 0)
      {
        encodeSize = (4 + lineSeparator.length);
        this.lineSeparator = new byte[lineSeparator.length];
        System.arraycopy(lineSeparator, 0, this.lineSeparator, 0, lineSeparator.length);
      }
      else
      {
        encodeSize = 4;
        this.lineSeparator = null;
      }
    }
    else
    {
      encodeSize = 4;
      this.lineSeparator = null;
    }
    decodeSize = (encodeSize - 1);
    encodeTable = (urlSafe ? URL_SAFE_ENCODE_TABLE : STANDARD_ENCODE_TABLE);
  }
  
  public boolean isUrlSafe()
  {
    return encodeTable == URL_SAFE_ENCODE_TABLE;
  }
  
  void encode(byte[] in, int inPos, int inAvail)
  {
    if (eof) {
      return;
    }
    if (inAvail < 0)
    {
      eof = true;
      if ((0 == modulus) && (lineLength == 0)) {
        return;
      }
      ensureBufferSize(encodeSize);
      int savedPos = pos;
      switch (modulus)
      {
      case 1: 
        buffer[(pos++)] = encodeTable[(bitWorkArea >> 2 & 0x3F)];
        buffer[(pos++)] = encodeTable[(bitWorkArea << 4 & 0x3F)];
        if (encodeTable == STANDARD_ENCODE_TABLE)
        {
          buffer[(pos++)] = 61;
          buffer[(pos++)] = 61;
        }
        break;
      case 2: 
        buffer[(pos++)] = encodeTable[(bitWorkArea >> 10 & 0x3F)];
        buffer[(pos++)] = encodeTable[(bitWorkArea >> 4 & 0x3F)];
        buffer[(pos++)] = encodeTable[(bitWorkArea << 2 & 0x3F)];
        if (encodeTable == STANDARD_ENCODE_TABLE) {
          buffer[(pos++)] = 61;
        }
        break;
      }
      currentLinePos += pos - savedPos;
      if ((lineLength > 0) && (currentLinePos > 0))
      {
        System.arraycopy(lineSeparator, 0, buffer, pos, lineSeparator.length);
        pos += lineSeparator.length;
      }
    }
    else
    {
      for (int i = 0; i < inAvail; i++)
      {
        ensureBufferSize(encodeSize);
        modulus = ((modulus + 1) % 3);
        int b = in[(inPos++)];
        if (b < 0) {
          b += 256;
        }
        bitWorkArea = ((bitWorkArea << 8) + b);
        if (0 == modulus)
        {
          buffer[(pos++)] = encodeTable[(bitWorkArea >> 18 & 0x3F)];
          buffer[(pos++)] = encodeTable[(bitWorkArea >> 12 & 0x3F)];
          buffer[(pos++)] = encodeTable[(bitWorkArea >> 6 & 0x3F)];
          buffer[(pos++)] = encodeTable[(bitWorkArea & 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++)
    {
      ensureBufferSize(decodeSize);
      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 + 1) % 4);
          bitWorkArea = ((bitWorkArea << 6) + result);
          if (modulus == 0)
          {
            buffer[(pos++)] = ((byte)(bitWorkArea >> 16 & 0xFF));
            buffer[(pos++)] = ((byte)(bitWorkArea >> 8 & 0xFF));
            buffer[(pos++)] = ((byte)(bitWorkArea & 0xFF));
          }
        }
      }
    }
    if ((eof) && (modulus != 0))
    {
      ensureBufferSize(decodeSize);
      switch (modulus)
      {
      case 2: 
        bitWorkArea >>= 4;
        buffer[(pos++)] = ((byte)(bitWorkArea & 0xFF));
        break;
      case 3: 
        bitWorkArea >>= 2;
        buffer[(pos++)] = ((byte)(bitWorkArea >> 8 & 0xFF));
        buffer[(pos++)] = ((byte)(bitWorkArea & 0xFF));
      }
    }
  }
  
  /**
   * @deprecated
   */
  public static boolean isArrayByteBase64(byte[] arrayOctet)
  {
    return isBase64(arrayOctet);
  }
  
  public static boolean isBase64(byte octet)
  {
    return (octet == 61) || ((octet >= 0) && (octet < DECODE_TABLE.length) && (DECODE_TABLE[octet] != -1));
  }
  
  public static boolean isBase64(String base64)
  {
    return isBase64(StringUtils.getBytesUtf8(base64));
  }
  
  public static boolean isBase64(byte[] arrayOctet)
  {
    for (int i = 0; i < arrayOctet.length; i++) {
      if ((!isBase64(arrayOctet[i])) && (!isWhiteSpace(arrayOctet[i]))) {
        return false;
      }
    }
    return true;
  }
  
  public static byte[] encodeBase64(byte[] binaryData)
  {
    return encodeBase64(binaryData, false);
  }
  
  public static String encodeBase64String(byte[] binaryData)
  {
    return StringUtils.newStringUtf8(encodeBase64(binaryData, false));
  }
  
  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 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;
    }
    Base64 b64 = isChunked ? new Base64(urlSafe) : new Base64(0, CHUNK_SEPARATOR, urlSafe);
    long len = b64.getEncodedLength(binaryData);
    if (len > maxResultSize) {
      throw new IllegalArgumentException("Input array too big, the output array would be bigger (" + len + ") than the specified maximum size of " + maxResultSize);
    }
    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);
  }
  
  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;
  }
  
  protected boolean isInAlphabet(byte octet)
  {
    return (octet >= 0) && (octet < decodeTable.length) && (decodeTable[octet] != -1);
  }
}

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

import java.io.InputStream;

public class Base64InputStream
  extends BaseNCodecInputStream
{
  public Base64InputStream(InputStream in)
  {
    this(in, false);
  }
  
  public Base64InputStream(InputStream in, boolean doEncode)
  {
    super(in, new Base64(false), doEncode);
  }
  
  public Base64InputStream(InputStream in, boolean doEncode, int lineLength, byte[] lineSeparator)
  {
    super(in, new Base64(lineLength, lineSeparator), doEncode);
  }
}

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

import java.io.OutputStream;

public class Base64OutputStream
  extends BaseNCodecOutputStream
{
  public Base64OutputStream(OutputStream out)
  {
    this(out, true);
  }
  
  public Base64OutputStream(OutputStream out, boolean doEncode)
  {
    super(out, new Base64(false), doEncode);
  }
  
  public Base64OutputStream(OutputStream out, boolean doEncode, int lineLength, byte[] lineSeparator)
  {
    super(out, new Base64(lineLength, lineSeparator), doEncode);
  }
}

/* Location:
 * Qualified Name:     org.apache.commons.codec.binary.Base64OutputStream
 * Java Class Version: 5 (49.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 abstract class BaseNCodec
  implements BinaryEncoder, BinaryDecoder
{
  public static final int MIME_CHUNK_SIZE = 76;
  public static final int PEM_CHUNK_SIZE = 64;
  private static final int DEFAULT_BUFFER_RESIZE_FACTOR = 2;
  private static final int DEFAULT_BUFFER_SIZE = 8192;
  protected static final int MASK_8BITS = 255;
  protected static final byte PAD_DEFAULT = 61;
  protected final byte PAD = 61;
  private final int unencodedBlockSize;
  private final int encodedBlockSize;
  protected final int lineLength;
  private final int chunkSeparatorLength;
  protected byte[] buffer;
  protected int pos;
  private int readPos;
  protected boolean eof;
  protected int currentLinePos;
  protected int modulus;
  
  protected BaseNCodec(int unencodedBlockSize, int encodedBlockSize, int lineLength, int chunkSeparatorLength)
  {
    this.unencodedBlockSize = unencodedBlockSize;
    this.encodedBlockSize = encodedBlockSize;
    this.lineLength = ((lineLength > 0) && (chunkSeparatorLength > 0) ? lineLength / encodedBlockSize * encodedBlockSize : 0);
    this.chunkSeparatorLength = chunkSeparatorLength;
  }
  
  boolean hasData()
  {
    return buffer != null;
  }
  
  int available()
  {
    return buffer != null ? pos - readPos : 0;
  }
  
  protected int getDefaultBufferSize()
  {
    return 8192;
  }
  
  private void resizeBuffer()
  {
    if (buffer == null)
    {
      buffer = new byte[getDefaultBufferSize()];
      pos = 0;
      readPos = 0;
    }
    else
    {
      byte[] b = new byte[buffer.length * 2];
      System.arraycopy(buffer, 0, b, 0, buffer.length);
      buffer = b;
    }
  }
  
  protected void ensureBufferSize(int size)
  {
    if ((buffer == null) || (buffer.length < pos + size)) {
      resizeBuffer();
    }
  }
  
  int readResults(byte[] b, int bPos, int bAvail)
  {
    if (buffer != null)
    {
      int len = Math.min(available(), bAvail);
      System.arraycopy(buffer, readPos, b, bPos, len);
      readPos += len;
      if (readPos >= pos) {
        buffer = null;
      }
      return len;
    }
    return eof ? -1 : 0;
  }
  
  protected static boolean isWhiteSpace(byte byteToCheck)
  {
    switch (byteToCheck)
    {
    case 9: 
    case 10: 
    case 13: 
    case 32: 
      return true;
    }
    return false;
  }
  
  private void reset()
  {
    buffer = null;
    pos = 0;
    readPos = 0;
    currentLinePos = 0;
    modulus = 0;
    eof = false;
  }
  
  public Object encode(Object pObject)
    throws EncoderException
  {
    if (!(pObject instanceof byte[])) {
      throw new EncoderException("Parameter supplied to Base-N encode is not a byte[]");
    }
    return encode((byte[])pObject);
  }
  
  public String encodeToString(byte[] pArray)
  {
    return StringUtils.newStringUtf8(encode(pArray));
  }
  
  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 Base-N 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;
    }
    decode(pArray, 0, pArray.length);
    decode(pArray, 0, -1);
    byte[] result = new byte[pos];
    readResults(result, 0, result.length);
    return result;
  }
  
  public byte[] encode(byte[] pArray)
  {
    reset();
    if ((pArray == null) || (pArray.length == 0)) {
      return pArray;
    }
    encode(pArray, 0, pArray.length);
    encode(pArray, 0, -1);
    byte[] buf = new byte[pos - readPos];
    readResults(buf, 0, buf.length);
    return buf;
  }
  
  public String encodeAsString(byte[] pArray)
  {
    return StringUtils.newStringUtf8(encode(pArray));
  }
  
  abstract void encode(byte[] paramArrayOfByte, int paramInt1, int paramInt2);
  
  abstract void decode(byte[] paramArrayOfByte, int paramInt1, int paramInt2);
  
  protected abstract boolean isInAlphabet(byte paramByte);
  
  public boolean isInAlphabet(byte[] arrayOctet, boolean allowWSPad)
  {
    for (int i = 0; i < arrayOctet.length; i++) {
      if ((!isInAlphabet(arrayOctet[i])) && ((!allowWSPad) || ((arrayOctet[i] != 61) && (!isWhiteSpace(arrayOctet[i]))))) {
        return false;
      }
    }
    return true;
  }
  
  public boolean isInAlphabet(String basen)
  {
    return isInAlphabet(StringUtils.getBytesUtf8(basen), true);
  }
  
  protected boolean containsAlphabetOrPad(byte[] arrayOctet)
  {
    if (arrayOctet == null) {
      return false;
    }
    for (byte element : arrayOctet) {
      if ((61 == element) || (isInAlphabet(element))) {
        return true;
      }
    }
    return false;
  }
  
  public long getEncodedLength(byte[] pArray)
  {
    long len = (pArray.length + unencodedBlockSize - 1) / unencodedBlockSize * encodedBlockSize;
    if (lineLength > 0) {
      len += (len + lineLength - 1L) / lineLength * chunkSeparatorLength;
    }
    return len;
  }
}

/* Location:
 * Qualified Name:     org.apache.commons.codec.binary.BaseNCodec
 * Java Class Version: 5 (49.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 BaseNCodecInputStream
  extends FilterInputStream
{
  private final boolean doEncode;
  private final BaseNCodec baseNCodec;
  private final byte[] singleByte = new byte[1];
  
  protected BaseNCodecInputStream(InputStream in, BaseNCodec baseNCodec, boolean doEncode)
  {
    super(in);
    this.doEncode = doEncode;
    this.baseNCodec = baseNCodec;
  }
  
  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;
    }
    int readLen = 0;
    while (readLen == 0)
    {
      if (!baseNCodec.hasData())
      {
        byte[] buf = new byte[doEncode ? '?' : '?'];
        int c = in.read(buf);
        if (doEncode) {
          baseNCodec.encode(buf, 0, c);
        } else {
          baseNCodec.decode(buf, 0, c);
        }
      }
      readLen = baseNCodec.readResults(b, offset, len);
    }
    return readLen;
  }
  
  public boolean markSupported()
  {
    return false;
  }
}

/* Location:
 * Qualified Name:     org.apache.commons.codec.binary.BaseNCodecInputStream
 * Java Class Version: 5 (49.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 BaseNCodecOutputStream
  extends FilterOutputStream
{
  private final boolean doEncode;
  private final BaseNCodec baseNCodec;
  private final byte[] singleByte = new byte[1];
  
  public BaseNCodecOutputStream(OutputStream out, BaseNCodec basedCodec, boolean doEncode)
  {
    super(out);
    baseNCodec = basedCodec;
    this.doEncode = doEncode;
  }
  
  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) {
        baseNCodec.encode(b, offset, len);
      } else {
        baseNCodec.decode(b, offset, len);
      }
      flush(false);
    }
  }
  
  private void flush(boolean propogate)
    throws IOException
  {
    int avail = baseNCodec.available();
    if (avail > 0)
    {
      byte[] buf = new byte[avail];
      int c = baseNCodec.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) {
      baseNCodec.encode(singleByte, 0, -1);
    } else {
      baseNCodec.decode(singleByte, 0, -1);
    }
    flush();
    out.close();
  }
}

/* Location:
 * Qualified Name:     org.apache.commons.codec.binary.BaseNCodecOutputStream
 * Java Class Version: 5 (49.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: 5 (49.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 character " + 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: 5 (49.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[] ge
1 2 3 4 5

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