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

📄 variantsupport.java

📁 java 读写word excel ppt
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
    /**     * <p>Turns a codepage number into the equivalent character encoding's      * name.</p>     *     * @param codepage The codepage number     *      * @return The character encoding's name. If the codepage number is 65001,      * the encoding name is "UTF-8". All other positive numbers are mapped to     * "cp" followed by the number, e.g. if the codepage number is 1252 the      * returned character encoding name will be "cp1252".     *      * @exception UnsupportedEncodingException if the specified codepage is     * less than zero.     */    public static String codepageToEncoding(final int codepage)    throws UnsupportedEncodingException    {        if (codepage <= 0)            throw new UnsupportedEncodingException                ("Codepage number may not be " + codepage);        switch (codepage)        {            case Constants.CP_UTF16:                return "UTF-16";            case Constants.CP_UTF16_BE:                return "UTF-16BE";            case Constants.CP_UTF8:                return "UTF-8";            case Constants.CP_037:                return "cp037";            case Constants.CP_GBK:                return "GBK";            case Constants.CP_MS949:                return "ms949";            case Constants.CP_WINDOWS_1250:                return "windows-1250";            case Constants.CP_WINDOWS_1251:                return "windows-1251";            case Constants.CP_WINDOWS_1252:                return "windows-1252";            case Constants.CP_WINDOWS_1253:                return "windows-1253";            case Constants.CP_WINDOWS_1254:                return "windows-1254";            case Constants.CP_WINDOWS_1255:                return "windows-1255";            case Constants.CP_WINDOWS_1256:                return "windows-1256";            case Constants.CP_WINDOWS_1257:                return "windows-1257";            case Constants.CP_WINDOWS_1258:                return "windows-1258";            case Constants.CP_JOHAB:                return "johab";            case Constants.CP_MAC_ROMAN:                return "MacRoman";            case Constants.CP_MAC_JAPAN:                return "SJIS";            case Constants.CP_MAC_CHINESE_TRADITIONAL:                return "Big5";            case Constants.CP_MAC_KOREAN:                return "EUC-KR";            case Constants.CP_MAC_ARABIC:                return "MacArabic";            case Constants.CP_MAC_HEBREW:                return "MacHebrew";            case Constants.CP_MAC_GREEK:                return "MacGreek";            case Constants.CP_MAC_CYRILLIC:                return "MacCyrillic";            case Constants.CP_MAC_CHINESE_SIMPLE:                return "EUC_CN";            case Constants.CP_MAC_ROMANIA:                return "MacRomania";            case Constants.CP_MAC_UKRAINE:                return "MacUkraine";            case Constants.CP_MAC_THAI:                return "MacThai";            case Constants.CP_MAC_CENTRAL_EUROPE:                return "MacCentralEurope";            case Constants.CP_MAC_ICELAND:                  return "MacIceland";            case Constants.CP_MAC_TURKISH:                return "MacTurkish";            case Constants.CP_MAC_CROATIAN:                return "MacCroatian";            case Constants.CP_US_ACSII:            case Constants.CP_US_ASCII2:                return "US-ASCII";            case Constants.CP_KOI8_R:                return "KOI8-R";            case Constants.CP_ISO_8859_1:                return "ISO-8859-1";            case Constants.CP_ISO_8859_2:                return "ISO-8859-2";            case Constants.CP_ISO_8859_3:                return "ISO-8859-3";            case Constants.CP_ISO_8859_4:                return "ISO-8859-4";            case Constants.CP_ISO_8859_5:                return "ISO-8859-5";            case Constants.CP_ISO_8859_6:                return "ISO-8859-6";            case Constants.CP_ISO_8859_7:                return "ISO-8859-7";            case Constants.CP_ISO_8859_8:                return "ISO-8859-8";            case Constants.CP_ISO_8859_9:                return "ISO-8859-9";            case Constants.CP_ISO_2022_JP1:            case Constants.CP_ISO_2022_JP2:            case Constants.CP_ISO_2022_JP3:                return "ISO-2022-JP";            case Constants.CP_ISO_2022_KR:                return "ISO-2022-KR";            case Constants.CP_EUC_JP:                return "EUC-JP";            case Constants.CP_EUC_KR:                return "EUC-KR";            case Constants.CP_GB2312:                return "GB2312";            case Constants.CP_GB18030:                return "GB18030";            case Constants.CP_SJIS:                return "SJIS";            default:                return "cp" + codepage;        }    }    /**     * <p>Writes a variant value to an output stream. This method ensures that     * always a multiple of 4 bytes is written.</p>     *     * <p>If the codepage is UTF-16, which is encouraged, strings     * <strong>must</strong> always be written as {@link Variant#VT_LPWSTR}     * strings, not as {@link Variant#VT_LPSTR} strings. This method ensure this     * by converting strings appropriately, if needed.</p>     *     * @param out The stream to write the value to.     * @param type The variant's type.     * @param value The variant's value.     * @param codepage The codepage to use to write non-wide strings     * @return The number of entities that have been written. In many cases an     * "entity" is a byte but this is not always the case.     * @exception IOException if an I/O exceptions occurs     * @exception WritingNotSupportedException if a property is to be written     * who's variant type HPSF does not yet support     */    public static int write(final OutputStream out, final long type,                            final Object value, final int codepage)        throws IOException, WritingNotSupportedException    {        int length = 0;        switch ((int) type)        {            case Variant.VT_BOOL:            {                int trueOrFalse;                if (((Boolean) value).booleanValue())                    trueOrFalse = 1;                else                    trueOrFalse = 0;                length = TypeWriter.writeUIntToStream(out, trueOrFalse);                break;            }            case Variant.VT_LPSTR:            {                final byte[] bytes =                    (codepage == -1 ?                    ((String) value).getBytes() :                    ((String) value).getBytes(codepageToEncoding(codepage)));                length = TypeWriter.writeUIntToStream(out, bytes.length + 1);                final byte[] b = new byte[bytes.length + 1];                System.arraycopy(bytes, 0, b, 0, bytes.length);                b[b.length - 1] = 0x00;                out.write(b);                length += b.length;                break;            }            case Variant.VT_LPWSTR:            {                final int nrOfChars = ((String) value).length() + 1;                 length += TypeWriter.writeUIntToStream(out, nrOfChars);                char[] s = Util.pad4((String) value);                for (int i = 0; i < s.length; i++)                {                    final int high = ((s[i] & 0x0000ff00) >> 8);                    final int low = (s[i] & 0x000000ff);                    final byte highb = (byte) high;                    final byte lowb = (byte) low;                    out.write(lowb);                    out.write(highb);                    length += 2;                }                out.write(0x00);                out.write(0x00);                length += 2;                break;            }            case Variant.VT_CF:            {                final byte[] b = (byte[]) value;                 out.write(b);                length = b.length;                break;            }            case Variant.VT_EMPTY:            {                TypeWriter.writeUIntToStream(out, Variant.VT_EMPTY);                length = LittleEndianConsts.INT_SIZE;                break;            }            case Variant.VT_I2:            {                TypeWriter.writeToStream(out, ((Integer) value).shortValue());                length = LittleEndianConsts.SHORT_SIZE;                break;            }            case Variant.VT_I4:            {                if (!(value instanceof Integer))                {                    throw new ClassCastException("Could not cast an object to "                            + Integer.class.toString() + ": "                            + value.getClass().toString() + ", "                            + value.toString());                }                length += TypeWriter.writeToStream(out,                           ((Integer) value).intValue());                break;            }            case Variant.VT_I8:            {                TypeWriter.writeToStream(out, ((Long) value).longValue());                length = LittleEndianConsts.LONG_SIZE;                break;            }            case Variant.VT_R8:            {                length += TypeWriter.writeToStream(out,                           ((Double) value).doubleValue());                break;            }            case Variant.VT_FILETIME:            {                long filetime = Util.dateToFileTime((Date) value);                int high = (int) ((filetime >> 32) & 0x00000000FFFFFFFFL);                int low = (int) (filetime & 0x00000000FFFFFFFFL);                length += TypeWriter.writeUIntToStream                    (out, 0x0000000FFFFFFFFL & low);                length += TypeWriter.writeUIntToStream                    (out, 0x0000000FFFFFFFFL & high);                break;            }            default:            {                /* The variant type is not supported yet. However, if the value                 * is a byte array we can write it nevertheless. */                if (value instanceof byte[])                {                    final byte[] b = (byte[]) value;                     out.write(b);                    length = b.length;                    writeUnsupportedTypeMessage                        (new WritingNotSupportedException(type, value));                }                else                    throw new WritingNotSupportedException(type, value);                break;            }        }        return length;    }}

⌨️ 快捷键说明

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