亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频

? 歡迎來到蟲蟲下載站! | ?? 資源下載 ?? 資源專輯 ?? 關于我們
? 蟲蟲下載站

?? binarycodec.java

?? 一個很實用的東東
?? JAVA
字號:
/*
 * Copyright 2001-2004 The Apache Software Foundation.
 * 
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * 
 *      http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */ 

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;

/**
 * Translates between byte arrays and strings of "0"s and "1"s.
 * 
 * @todo may want to add more bit vector functions like and/or/xor/nand 
 * @todo also might be good to generate boolean[]
 * from byte[] et. cetera.
 * 
 * @author Apache Software Foundation
 * @since 1.3
 * @version $Id $
 */
public class BinaryCodec implements BinaryDecoder, BinaryEncoder {
    /*
     * tried to avoid using ArrayUtils to minimize dependencies while using these empty arrays - dep is just not worth
     * it.
     */
    /** Empty char array. */
    private static final char[] EMPTY_CHAR_ARRAY = new char[0];

    /** Empty byte array. */
    private static final byte[] EMPTY_BYTE_ARRAY = new byte[0];

    /** Mask for bit 0 of a byte. */
    private static final int BIT_0 = 1;

    /** Mask for bit 1 of a byte. */
    private static final int BIT_1 = 0x02;

    /** Mask for bit 2 of a byte. */
    private static final int BIT_2 = 0x04;

    /** Mask for bit 3 of a byte. */
    private static final int BIT_3 = 0x08;

    /** Mask for bit 4 of a byte. */
    private static final int BIT_4 = 0x10;

    /** Mask for bit 5 of a byte. */
    private static final int BIT_5 = 0x20;

    /** Mask for bit 6 of a byte. */
    private static final int BIT_6 = 0x40;

    /** Mask for bit 7 of a byte. */
    private static final int BIT_7 = 0x80;

    private static final int[] BITS = {BIT_0, BIT_1, BIT_2, BIT_3, BIT_4, BIT_5, BIT_6, BIT_7};

    /**
     * Converts an array of raw binary data into an array of ascii 0 and 1 characters.
     * 
     * @param raw
     *                  the raw binary data to convert
     * @return 0 and 1 ascii character bytes one for each bit of the argument
     * @see org.apache.commons.codec.BinaryEncoder#encode(byte[])
     */
    public byte[] encode(byte[] raw) {
        return toAsciiBytes(raw);
    }

    /**
     * Converts an array of raw binary data into an array of ascii 0 and 1 chars.
     * 
     * @param raw
     *                  the raw binary data to convert
     * @return 0 and 1 ascii character chars one for each bit of the argument
     * @throws EncoderException
     *                  if the argument is not a byte[]
     * @see org.apache.commons.codec.Encoder#encode(java.lang.Object)
     */
    public Object encode(Object raw) throws EncoderException {
        if (!(raw instanceof byte[])) {
            throw new EncoderException("argument not a byte array");
        }
        return toAsciiChars((byte[]) raw);
    }

    /**
     * Decodes a byte array where each byte represents an ascii '0' or '1'.
     * 
     * @param ascii
     *                  each byte represents an ascii '0' or '1'
     * @return the raw encoded binary where each bit corresponds to a byte in the byte array argument
     * @throws DecoderException
     *                  if argument is not a byte[], char[] or String
     * @see org.apache.commons.codec.Decoder#decode(java.lang.Object)
     */
    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");
    }

    /**
     * Decodes a byte array where each byte represents an ascii '0' or '1'.
     * 
     * @param ascii
     *                  each byte represents an ascii '0' or '1'
     * @return the raw encoded binary where each bit corresponds to a byte in the byte array argument
     * @see org.apache.commons.codec.Decoder#decode(Object)
     */
    public byte[] decode(byte[] ascii) {
        return fromAscii(ascii);
    }

    /**
     * Decodes a String where each char of the String represents an ascii '0' or '1'.
     * 
     * @param ascii
     *                  String of '0' and '1' characters
     * @return the raw encoded binary where each bit corresponds to a byte in the byte array argument
     * @see org.apache.commons.codec.Decoder#decode(Object)
     */
    public byte[] toByteArray(String ascii) {
        if (ascii == null) {
            return EMPTY_BYTE_ARRAY;
        }
        return fromAscii(ascii.toCharArray());
    }

    // ------------------------------------------------------------------------
    //
    // static codec operations
    //
    // ------------------------------------------------------------------------
    /**
     * Decodes a byte array where each char represents an ascii '0' or '1'.
     * 
     * @param ascii
     *                  each char represents an ascii '0' or '1'
     * @return the raw encoded binary where each bit corresponds to a char in the char array argument
     */
    public static byte[] fromAscii(char[] ascii) {
        if (ascii == null || ascii.length == 0) {
            return EMPTY_BYTE_ARRAY;
        }
        // get length/8 times bytes with 3 bit shifts to the right of the length
        byte[] l_raw = new byte[ascii.length >> 3];
        /*
         * We decr index jj by 8 as we go along to not recompute indices using multiplication every time inside the
         * loop.
         */
        for (int ii = 0, jj = ascii.length - 1; ii < l_raw.length; ii++, jj -= 8) {
            for (int bits = 0; bits < BITS.length; ++bits) {
                if (ascii[jj - bits] == '1') {
                    l_raw[ii] |= BITS[bits];
                }
            }
        }
        return l_raw;
    }

    /**
     * Decodes a byte array where each byte represents an ascii '0' or '1'.
     * 
     * @param ascii
     *                  each byte represents an ascii '0' or '1'
     * @return the raw encoded binary where each bit corresponds to a byte in the byte array argument
     */
    public static byte[] fromAscii(byte[] ascii) {
        if (ascii == null || ascii.length == 0) {
            return EMPTY_BYTE_ARRAY;
        }
        // get length/8 times bytes with 3 bit shifts to the right of the length
        byte[] l_raw = new byte[ascii.length >> 3];
        /*
         * We decr index jj by 8 as we go along to not recompute indices using multiplication every time inside the
         * loop.
         */
        for (int ii = 0, jj = ascii.length - 1; ii < l_raw.length; ii++, jj -= 8) {
            for (int bits = 0; bits < BITS.length; ++bits) {
                if (ascii[jj - bits] == '1') {
                    l_raw[ii] |= BITS[bits];
                }
            }
        }
        return l_raw;
    }

    /**
     * Converts an array of raw binary data into an array of ascii 0 and 1 character bytes - each byte is a truncated
     * char.
     * 
     * @param raw
     *                  the raw binary data to convert
     * @return an array of 0 and 1 character bytes for each bit of the argument
     * @see org.apache.commons.codec.BinaryEncoder#encode(byte[])
     */
    public static byte[] toAsciiBytes(byte[] raw) {
        if (raw == null || raw.length == 0) {
            return EMPTY_BYTE_ARRAY;
        }
        // get 8 times the bytes with 3 bit shifts to the left of the length
        byte[] l_ascii = new byte[raw.length << 3];
        /*
         * We decr index jj by 8 as we go along to not recompute indices using multiplication every time inside the
         * loop.
         */
        for (int ii = 0, jj = l_ascii.length - 1; ii < raw.length; ii++, 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';
                }
            }
        }
        return l_ascii;
    }

    /**
     * Converts an array of raw binary data into an array of ascii 0 and 1 characters.
     * 
     * @param raw
     *                  the raw binary data to convert
     * @return an array of 0 and 1 characters for each bit of the argument
     * @see org.apache.commons.codec.BinaryEncoder#encode(byte[])
     */
    public static char[] toAsciiChars(byte[] raw) {
        if (raw == null || raw.length == 0) {
            return EMPTY_CHAR_ARRAY;
        }
        // get 8 times the bytes with 3 bit shifts to the left of the length
        char[] l_ascii = new char[raw.length << 3];
        /*
         * We decr index jj by 8 as we go along to not recompute indices using multiplication every time inside the
         * loop.
         */
        for (int ii = 0, jj = l_ascii.length - 1; ii < raw.length; ii++, 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';
                }
            }
        }
        return l_ascii;
    }

    /**
     * Converts an array of raw binary data into a String of ascii 0 and 1 characters.
     * 
     * @param raw
     *                  the raw binary data to convert
     * @return a String of 0 and 1 characters representing the binary data
     * @see org.apache.commons.codec.BinaryEncoder#encode(byte[])
     */
    public static String toAsciiString(byte[] raw) {
        return new String(toAsciiChars(raw));
    }
}

?? 快捷鍵說明

復制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
欧美性感一区二区三区| 欧美性受xxxx| 欧洲一区二区av| 日韩一级片网站| 日韩美女精品在线| 另类小说视频一区二区| 一本久道久久综合中文字幕| 欧美一区永久视频免费观看| 欧美激情在线看| 日韩av电影免费观看高清完整版| 国产mv日韩mv欧美| 日韩一卡二卡三卡国产欧美| 亚洲另类色综合网站| 国模套图日韩精品一区二区| 欧美日韩国产成人在线91| 中文字幕不卡在线播放| 久久精品国产秦先生| 欧美吻胸吃奶大尺度电影| 欧美激情在线看| 国产高清亚洲一区| 日韩片之四级片| 亚洲高清视频在线| 色综合色狠狠综合色| 国产午夜精品久久| 黄色小说综合网站| 精品国偷自产国产一区| 免费看欧美女人艹b| 欧美久久一区二区| 午夜精品久久久| 欧美丝袜丝nylons| 亚洲成av人综合在线观看| 日本韩国精品一区二区在线观看| 国产精品免费观看视频| 国产精品伊人色| 国产片一区二区| 国产成人小视频| 国产欧美日韩一区二区三区在线观看| 久久精品72免费观看| 精品乱人伦小说| 国产一区二区调教| 国产婷婷色一区二区三区在线| 精品一区二区三区在线播放视频| 91精品久久久久久蜜臀| 欧美a一区二区| 欧美精品一区二| 国产在线观看一区二区| 久久精品欧美一区二区三区不卡| 国产乱子轮精品视频| 欧美国产日韩亚洲一区| aa级大片欧美| 夜夜嗨av一区二区三区中文字幕| 欧亚一区二区三区| 日韩精品亚洲一区二区三区免费| 欧美一区二区福利在线| 精品一区二区三区影院在线午夜| 精品成人一区二区三区| 高清在线成人网| 亚洲欧美国产77777| 欧美日韩视频一区二区| 蜜桃精品在线观看| 国产亚洲一二三区| 91同城在线观看| 日韩国产精品久久久久久亚洲| 欧美va亚洲va国产综合| 波多野结衣亚洲| 亚洲成a人在线观看| 精品区一区二区| 99精品热视频| 日本亚洲电影天堂| 国产精品你懂的| 欧美视频一区在线| 国产麻豆欧美日韩一区| 亚洲欧美日韩一区| 欧美一区二区成人6969| 成人aa视频在线观看| 午夜成人免费电影| 日本一区二区三区电影| 欧美体内she精高潮| 国产做a爰片久久毛片| 亚洲精品自拍动漫在线| 欧美成va人片在线观看| 91在线精品一区二区| 美腿丝袜在线亚洲一区| 亚洲日穴在线视频| 精品国产一区二区三区久久影院| 99精品视频中文字幕| 蜜桃久久久久久| 一区二区三区蜜桃| 国产日韩欧美高清| 欧美成人r级一区二区三区| 97se亚洲国产综合自在线观| 美女一区二区视频| 夜夜夜精品看看| 国产精品嫩草影院av蜜臀| 欧美不卡一区二区三区| 欧美日韩精品一二三区| av亚洲精华国产精华精华| 精品伊人久久久久7777人| 亚洲成人动漫在线免费观看| 国产精品不卡一区二区三区| 精品国产乱码久久久久久久久| 91高清视频在线| 不卡欧美aaaaa| 国产剧情在线观看一区二区| 欧美96一区二区免费视频| 一区二区三区在线视频免费| 国产精品久久久久影院| 久久婷婷综合激情| 精品国产不卡一区二区三区| 91麻豆精品国产91久久久资源速度| 91蜜桃视频在线| av电影天堂一区二区在线| 国产.精品.日韩.另类.中文.在线.播放| 看电视剧不卡顿的网站| 美女视频一区在线观看| 日韩高清电影一区| 日韩精品欧美精品| 亚洲成av人影院| 亚洲午夜视频在线观看| 亚洲午夜精品网| 亚洲自拍偷拍av| 亚洲一区在线观看网站| 亚洲国产成人av| 五月婷婷综合激情| 日韩精品电影在线| 亚洲成人av一区| 亚洲超碰97人人做人人爱| 五月激情综合色| 男人的天堂久久精品| 麻豆国产欧美一区二区三区| 另类中文字幕网| 国产精品乡下勾搭老头1| 国产精品123| 9l国产精品久久久久麻豆| 不卡欧美aaaaa| 欧洲亚洲国产日韩| 在线综合+亚洲+欧美中文字幕| 日韩一级大片在线观看| 精品成人一区二区三区| 欧美国产精品v| 亚洲色图欧美激情| 性久久久久久久久久久久| 蜜臀久久99精品久久久久宅男| 国内精品伊人久久久久av影院| 国产精品影视天天线| av日韩在线网站| 欧美三区免费完整视频在线观看| 欧美日韩精品是欧美日韩精品| 欧美一级久久久| 久久久777精品电影网影网| 中文字幕亚洲成人| 天堂午夜影视日韩欧美一区二区| 蜜桃在线一区二区三区| caoporn国产精品| 7777精品伊人久久久大香线蕉| 精品免费国产二区三区| 亚洲人一二三区| 免费看欧美女人艹b| 99久久精品国产一区| 欧美精品在线一区二区三区| 久久久久久一二三区| 亚洲柠檬福利资源导航| 麻豆成人综合网| 色综合中文字幕| 欧美v日韩v国产v| 亚洲激情在线播放| 国产精品自在在线| 欧美日韩中文国产| 欧美国产精品专区| 免费在线看成人av| 91免费在线看| 久久久噜噜噜久久人人看| 亚洲一区二区三区四区在线免费观看 | 色老汉av一区二区三区| 91精品国产综合久久香蕉麻豆| 欧美经典一区二区| 美国毛片一区二区| 欧美性生活大片视频| 中文字幕一区二区不卡| 国产美女精品一区二区三区| 欧美日本在线视频| 亚洲乱码一区二区三区在线观看| 另类欧美日韩国产在线| 欧美视频在线一区二区三区| 国产精品久久久久7777按摩| 国产在线播精品第三| 欧美一级精品大片| 亚洲国产毛片aaaaa无费看| www.av亚洲| 国产欧美日韩另类一区| 久久福利资源站| 91精品国产综合久久精品麻豆| 一区二区三区精品久久久| 99热在这里有精品免费| 亚洲国产成人一区二区三区| 国产在线麻豆精品观看| 欧美电视剧在线观看完整版| 日韩精品国产欧美| 欧美精品免费视频| 亚洲成人激情综合网|