⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 littleendian.java

📁 java 报表 to office文档: 本包由java语言开发
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
/* ====================================================================   Copyright 2003-2004   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.poi.util;import java.io.IOException;import java.io.InputStream;import java.util.Arrays;/** *  a utility class for handling little-endian numbers, which the 80x86 world is *  replete with. The methods are all static, and input/output is from/to byte *  arrays, or from InputStreams. * *@author     Marc Johnson (mjohnson at apache dot org) *@author     Andrew Oliver (acoliver at apache dot org) */public class LittleEndian         implements LittleEndianConsts {    // all methods are static, so an accessible constructor makes no    // sense    /**     *  Constructor for the LittleEndian object     */    private LittleEndian() { }    /**     *  get a short value from a byte array     *     *@param  data    the byte array     *@param  offset  a starting offset into the byte array     *@return         the short (16-bit) value     */    public static short getShort(final byte[] data, final int offset) {        return (short) getNumber(data, offset, SHORT_SIZE);    }    /**     *  get an unsigned short value from a byte array     *     *@param  data    the byte array     *@param  offset  a starting offset into the byte array     *@return         the unsigned short (16-bit) value in an integer     */    public static int getUShort(final byte[] data, final int offset) {        short num = (short) getNumber(data, offset, SHORT_SIZE);        int retNum;        if (num < 0) {            retNum = ((int) Short.MAX_VALUE + 1) * 2 + (int) num;        } else {            retNum = (int) num;        }        return retNum;    }    /**     *  get a short array from a byte array.     *     *@param  data    Description of the Parameter     *@param  offset  Description of the Parameter     *@param  size    Description of the Parameter     *@return         The simpleShortArray value     */    public static short[] getSimpleShortArray(final byte[] data, final int offset, final int size) {        short[] results = new short[size];        for (int i = 0; i < size; i++) {            results[i] = getShort(data, offset + 2 + (i * 2));        }        return results;    }    /**     *  get a short array from a byte array. The short array is assumed to start     *  with a word describing the length of the array.     *     *@param  data    Description of the Parameter     *@param  offset  Description of the Parameter     *@return         The shortArray value     */    public static short[] getShortArray(final byte[] data, final int offset) {        int size = (int) getNumber(data, offset, SHORT_SIZE);        short[] results = getSimpleShortArray(data, offset, size);        return results;    }    /**     *  get a short value from the beginning of a byte array     *     *@param  data  the byte array     *@return       the short (16-bit) value     */    public static short getShort(final byte[] data) {        return getShort(data, 0);    }    /**     *  get an unsigned short value from the beginning of a byte array     *     *@param  data  the byte array     *@return       the unsigned short (16-bit) value in an int     */    public static int getUShort(final byte[] data) {        return getUShort(data, 0);    }    /**     *  get an int value from a byte array     *     *@param  data    the byte array     *@param  offset  a starting offset into the byte array     *@return         the int (32-bit) value     */    public static int getInt(final byte[] data, final int offset) {        return (int) getNumber(data, offset, INT_SIZE);    }    /**     *  get an int value from the beginning of a byte array     *     *@param  data  the byte array     *@return       the int (32-bit) value     */    public static int getInt(final byte[] data) {        return getInt(data, 0);    }    /**     *  get an unsigned int value from a byte array     *     *@param  data    the byte array     *@param  offset  a starting offset into the byte array     *@return         the unsigned int (32-bit) value in a long     */    public static long getUInt(final byte[] data, final int offset) {        int num = (int) getNumber(data, offset, INT_SIZE);        long retNum;        if (num < 0) {            retNum = ((long) Integer.MAX_VALUE + 1) * 2 + (long) num;        } else {            retNum = (int) num;        }        return retNum;    }    /**     *  get an unsigned int value from a byte array     *     *@param  data    the byte array     *@return         the unsigned int (32-bit) value in a long     */    public static long getUInt(final byte[] data) {	return getUInt(data,0);    }    /**     *  get a long value from a byte array     *     *@param  data    the byte array     *@param  offset  a starting offset into the byte array     *@return         the long (64-bit) value     */    public static long getLong(final byte[] data, final int offset) {        return getNumber(data, offset, LONG_SIZE);    }    /**     *  get a long value from the beginning of a byte array     *     *@param  data  the byte array     *@return       the long (64-bit) value     */    public static long getLong(final byte[] data) {        return getLong(data, 0);    }    /**     *  get a double value from a byte array, reads it in little endian format     *  then converts the resulting revolting IEEE 754 (curse them) floating     *  point number to a happy java double     *     *@param  data    the byte array     *@param  offset  a starting offset into the byte array     *@return         the double (64-bit) value     */    public static double getDouble(final byte[] data, final int offset) {        return Double.longBitsToDouble(getNumber(data, offset, DOUBLE_SIZE));    }    /**     *  get a double value from the beginning of a byte array     *     *@param  data  the byte array     *@return       the double (64-bit) value     */    public static double getDouble(final byte[] data) {        return getDouble(data, 0);    }    /**     *  put a short value into a byte array     *     *@param  data    the byte array     *@param  offset  a starting offset into the byte array     *@param  value   the short (16-bit) value     */    public static void putShort(final byte[] data, final int offset,            final short value) {        putNumber(data, offset, value, SHORT_SIZE);    }    /**     *  put a array of shorts into a byte array     *     *@param  data    the byte array     *@param  offset  a starting offset into the byte array     *@param  value   the short array     */    public static void putShortArray(final byte[] data, final int offset, final short[] value) {        putNumber(data, offset, value.length, SHORT_SIZE);        for (int i = 0; i < value.length; i++) {            putNumber(data, offset + 2 + (i * 2), value[i], SHORT_SIZE);        }    }    /**     * put an unsigned short value into a byte array     *     * @param data the byte array     * @param offset a starting offset into the byte array     * @param value the short (16-bit) value     *     * @exception ArrayIndexOutOfBoundsException may be thrown     */    public static void putUShort(final byte[] data, final int offset,                                final int value)    {        putNumber(data, offset, value, SHORT_SIZE);    }    /**     *  put a short value into beginning of a byte array     *     *@param  data   the byte array     *@param  value  the short (16-bit) value     */    public static void putShort(final byte[] data, final short value) {        putShort(data, 0, value);    }

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -