日期:2014-05-20  浏览次数:20694 次

谁可以告诉我下static后面的代码是什么意思啊 ?
private static final byte[] encodingTable = {
  (byte) 'A', (byte) 'B', (byte) 'C', (byte) 'D', (byte) 'E',
  (byte) 'F', (byte) 'G', (byte) 'H', (byte) 'I', (byte) 'J',
  (byte) 'K', (byte) 'L', (byte) 'M', (byte) 'N', (byte) 'O',
  (byte) 'P', (byte) 'Q', (byte) 'R', (byte) 'S', (byte) 'T',
  (byte) 'U', (byte) 'V', (byte) 'W', (byte) 'X', (byte) 'Y',
  (byte) 'Z', (byte) 'a', (byte) 'b', (byte) 'c', (byte) 'd',
  (byte) 'e', (byte) 'f', (byte) 'g', (byte) 'h', (byte) 'i',
  (byte) 'j', (byte) 'k', (byte) 'l', (byte) 'm', (byte) 'n',
  (byte) 'o', (byte) 'p', (byte) 'q', (byte) 'r', (byte) 's',
  (byte) 't', (byte) 'u', (byte) 'v', (byte) 'w', (byte) 'x',
  (byte) 'y', (byte) 'z', (byte) '0', (byte) '1', (byte) '2',
  (byte) '3', (byte) '4', (byte) '5', (byte) '6', (byte) '7',
  (byte) '8', (byte) '9', (byte) '+', (byte) '/'
  };
  private static final byte[] decodingTable;//定义一个静态decodingTable字节数组
  static {
  decodingTable = new byte[128]; //实例化decodingTable数组
  for (int i = 0; i < 128; i++) {
  decodingTable[i] = (byte) -1;
  }
  for (int i = 'A'; i <= 'Z'; i++) {
  decodingTable[i] = (byte) (i - 'A');
  }
  for (int i = 'a'; i <= 'z'; i++) {
  decodingTable[i] = (byte) (i - 'a' + 26);
  }
  for (int i = '0'; i <= '9'; i++) {
  decodingTable[i] = (byte) (i - '0' + 52);
  }
  decodingTable['+'] = 62;
  decodingTable['/'] = 63;
  }


------解决方案--------------------
Java code

private static final byte[] encodingTable = { 
            (byte) 'A', (byte) 'B', (byte) 'C', (byte) 'D', (byte) 'E', 
            (byte) 'F', (byte) 'G', (byte) 'H', (byte) 'I', (byte) 'J', 
            (byte) 'K', (byte) 'L', (byte) 'M', (byte) 'N', (byte) 'O', 
            (byte) 'P', (byte) 'Q', (byte) 'R', (byte) 'S', (byte) 'T', 
            (byte) 'U', (byte) 'V', (byte) 'W', (byte) 'X', (byte) 'Y', 
            (byte) 'Z', (byte) 'a', (byte) 'b', (byte) 'c', (byte) 'd', 
            (byte) 'e', (byte) 'f', (byte) 'g', (byte) 'h', (byte) 'i', 
            (byte) 'j', (byte) 'k', (byte) 'l', (byte) 'm', (byte) 'n', 
            (byte) 'o', (byte) 'p', (byte) 'q', (byte) 'r', (byte) 's', 
            (byte) 't', (byte) 'u', (byte) 'v', (byte) 'w', (byte) 'x', 
            (byte) 'y', (byte) 'z', (byte) '0', (byte) '1', (byte) '2', 
            (byte) '3', (byte) '4', (byte) '5', (byte) '6', (byte) '7', 
            (byte) '8', (byte) '9', (byte) '+', (byte) '/' 
        }; 
    private static final byte[] decodingTable;//定义一个静态decodingTable字节数组 
    static {//这个是加载到内存的,不依靠该类的对象的。
        decodingTable = new byte[128]; //实例化decodingTable数组 
        for (int i = 0; i < 128; i++) { 
            decodingTable[i] = (byte) -1; 
        } 
        for (int i = 'A'; i <= 'Z'; i++) { 
            decodingTable[i] = (byte) (i - 'A'); 
        } 
        for (int i = 'a'; i <= 'z'; i++) { 
            decodingTable[i] = (byte) (i - 'a' + 26); 
        } 
        for (int i = '0'; i <= '9'; i++) { 
            decodingTable[i] = (byte) (i - '0' + 52); 
        } 
        decodingTable['+'] = 62; 
        decodingTable['/'] = 63; 
    }

------解决方案--------------------
编码而已,把A-z以及数字/ +重新编码,对应上(byte)1-(byte)63,其它为-1
利用char的值喵~`
------解决方案--------------------