20161027

来源:互联网 发布:阿里巴巴淘宝城 编辑:程序博客网 时间:2024/06/05 09:32

2016-10-27

System.arraycopy();

jdk1.8source

下载链接:http://download.java.net/openjdk/jdk8/

//jdk:jdk1.8.0_73public static native void arraycopy(Object src, int srcPos,        Object dst, int dstPos, int length);

本地方法源码分析:http://m.blog.csdn.net/article/details?id=49512643

注意事项:srcPos,dstPos,length引发数组越界;src与dst可以相同

阅读链接:
http://blog.csdn.net/kesalin/article/details/566354

Arrays.fill();

    /**     * Fills the specified array with the specified element.     *     * @param array the {@code byte} array to fill.     * @param value the {@code byte} element.     */    public static void fill(type[] array, type value) {        for (int i = 0; i < array.length; i++) {            array[i] = value;        }    }    /**     * Fills the specified range in the array with the specified element.     *     * @param array the {@code byte} array to fill.     * @param start the first index to fill.     * @param end the last + 1 index to fill.     * @param value the {@code byte} element.     * @throws IllegalArgumentException if {@code start > end}.     * @throws ArrayIndexOutOfBoundsException     *                if {@code start < 0} or {@code end > array.length}.     */    public static void fill(type[] array, int start, int end, type value) {        //检查是否越界        Arrays.checkStartAndEnd(array.length, start, end);        for (int i = start; i < end; i++) {            array[i] = value;        }    }    /**     * Checks that the range described by {@code start} and {@code end} doesn't exceed     * {@code len}.     *     * @hide     */    public static void checkStartAndEnd(int len, int start, int end) {        if (start < 0 || end > len) {            throw new ArrayIndexOutOfBoundsException("start < 0 || end > len."                    + " start=" + start + ", end=" + end + ", len=" + len);        }        if (start > end) {            throw new IllegalArgumentException("start > end: " + start + " > " + end);        }    }

异常

hisync.STUtils: java.lang.IllegalArgumentException: input.length=0; inputOffset=16; inputLen=-16   at javax.crypto.Cipher.checkInputOffsetAndCount(Cipher.java:1203)   at javax.crypto.Cipher.doFinal(Cipher.java:1539)   at com.huawei.android.hicloud.util.a.a(Aes128Cbc.java:264)   at com.huawei.android.hicloud.util.a.b(Aes128Cbc.java:131)   at com.huawei.android.hicloud.util.z.c(STUtils.java:105)   at com.huawei.android.hicloud.common.account.a.b(AccountInfo.java:203)   at com.huawei.android.hicloud.common.account.a.a(AccountInfo.java:158)   at com.huawei.android.hicloud.HicloudApplication.onCreate(HicloudApplication.java:70)   at android.app.Instrumentation.callApplicationOnCreate(Instrumentation.java:1015)   at android.app.ActivityThread.handleBindApplication(ActivityThread.java:4837)   at android.app.ActivityThread.access$1600(ActivityThread.java:168)   at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1440)   at android.os.Handler.dispatchMessage(Handler.java:102)   at android.os.Looper.loop(Looper.java:150)   at android.app.ActivityThread.main(ActivityThread.java:5665)   at java.lang.reflect.Method.invoke(Native Method)   at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:799)   at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:689)

S:应用提示更新,点击更新安装,在安装的过程中出现闪退

    private static void checkInputOffsetAndCount(int inputArrayLength,                                                 int inputOffset,                                                 int inputLen) {        if ((inputOffset | inputLen) < 0                || inputOffset > inputArrayLength                || inputArrayLength - inputOffset < inputLen) {            throw new IllegalArgumentException("input.length=" + inputArrayLength                                               + "; inputOffset=" + inputOffset                                               + "; inputLen=" + inputLen);        }    }

javax.crypto.Cipher是干什么?

文档链接
https://docs.oracle.com/javase/7/docs/api/javax/crypto/Cipher.html
http://blog.csdn.net/wuwenlong527/article/details/2037931

Arrays.copyof()

    public static byte[] copyOf(byte[] original, int newLength) {        if (newLength < 0) {            throw new NegativeArraySizeException(Integer.toString(newLength));        }        return copyOfRange(original, 0, newLength);    }    /**     * Copies elements from {@code original} into a new array, from indexes start (inclusive) to     * end (exclusive). The original order of elements is preserved.     * If {@code end} is greater than {@code original.length}, the result is padded     * with the value {@code (byte) 0}.     *     * @param original the original array     * @param start the start index, inclusive     * @param end the end index, exclusive     * @return the new array     * @throws ArrayIndexOutOfBoundsException if {@code start < 0 || start > original.length}     * @throws IllegalArgumentException if {@code start > end}     * @throws NullPointerException if {@code original == null}     * @since 1.6     */    public static byte[] copyOfRange(byte[] original, int start, int end) {        if (start > end) {            throw new IllegalArgumentException();        }        int originalLength = original.length;        if (start < 0 || start > originalLength) {            throw new ArrayIndexOutOfBoundsException();        }        int resultLength = end - start;        int copyLength = Math.min(resultLength, originalLength - start);        byte[] result = new byte[resultLength];        System.arraycopy(original, start, result, 0, copyLength);        return result;    }
0 0
原创粉丝点击