/** * <p>Turns a codepage number into the equivalent character encoding's * name (in Java NIO canonical naming format).</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 * their Java NIO names, normally either "windows-" followed by the number, * eg "windows-1251", or "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 { return codepageToEncoding(codepage, false); }
/** * Converts the bytes into a String, based on the equivalent character encoding * to the supplied codepage number. * @param string The byte of the string to convert * @param codepage The codepage number */ public static String getStringFromCodePage(final byte[] string, final int offset, final int length, final int codepage) throws UnsupportedEncodingException { String encoding = codepageToEncoding(codepage); return new String(string, offset, length, encoding); }
/** * Converts a string into bytes, in the equivalent character encoding * to the supplied codepage number. * @param string The string to convert * @param codepage The codepage number */ public static byte[] getBytesInCodePage(final String string, final int codepage) throws UnsupportedEncodingException { String encoding = codepageToEncoding(codepage); return string.getBytes(encoding); }
private String decodeValueFromID() { try { switch((int)getID()) { case PropertyIDMap.PID_CODEPAGE: return CodePageUtil.codepageToEncoding(((Number)value).intValue()); case PropertyIDMap.PID_LOCALE: return LocaleUtil.getLocaleFromLCID(((Number)value).intValue()); } } catch (Exception e) { LOG.log(POILogger.WARN, "Can't decode id "+getID()); } return null; }
private void checkCodePage(String value) { int cp = getCodepage(); if (cp == -1) { cp = Property.DEFAULT_CODEPAGE; } if (cp == CodePageUtil.CP_UNICODE) { return; } String cps = ""; try { cps = CodePageUtil.codepageToEncoding(cp, false); } catch (UnsupportedEncodingException e) { LOG.log(POILogger.ERROR, "Codepage '"+cp+"' can't be found."); } if (!cps.isEmpty() && Charset.forName(cps).newEncoder().canEncode(value)) { return; } LOG.log(POILogger.DEBUG, "Charset '"+cps+"' can't encode '"+value+"' - switching to unicode."); setCodepage(CodePageUtil.CP_UNICODE); } }
String csStr = CodePageUtil.codepageToEncoding(codepage > 0 ? codepage : Property.DEFAULT_CODEPAGE); if (!Charset.forName(csStr).newEncoder().canEncode((String)value)) { variantType = Variant.VT_LPWSTR;
modules.charset = Charset.forName(CodePageUtil.codepageToEncoding(codepage, true)); break; case MODULE_STREAM_NAME:
String encoding = null; try { encoding = CodePageUtil.codepageToEncoding(codepage, true); } catch (UnsupportedEncodingException e) {
/** * <p>Turns a codepage number into the equivalent character encoding's * name (in Java NIO canonical naming format).</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 * their Java NIO names, normally either "windows-" followed by the number, * eg "windows-1251", or "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 { return codepageToEncoding(codepage, false); }
/** * Converts the bytes into a String, based on the equivalent character encoding * to the supplied codepage number. * @param string The byte of the string to convert * @param codepage The codepage number */ public static String getStringFromCodePage(final byte[] string, final int offset, final int length, final int codepage) throws UnsupportedEncodingException { String encoding = codepageToEncoding(codepage); return new String(string, offset, length, encoding); }
/** * Converts a string into bytes, in the equivalent character encoding * to the supplied codepage number. * @param string The string to convert * @param codepage The codepage number */ public static byte[] getBytesInCodePage(final String string, final int codepage) throws UnsupportedEncodingException { String encoding = codepageToEncoding(codepage); return string.getBytes(encoding); }
private String decodeValueFromID() { try { switch((int)getID()) { case PropertyIDMap.PID_CODEPAGE: return CodePageUtil.codepageToEncoding(((Number)value).intValue()); case PropertyIDMap.PID_LOCALE: return LocaleUtil.getLocaleFromLCID(((Number)value).intValue()); } } catch (Exception e) { LOG.log(POILogger.WARN, "Can't decode id "+getID()); } return null; }
private void checkCodePage(String value) { int cp = getCodepage(); if (cp == -1) { cp = Property.DEFAULT_CODEPAGE; } if (cp == CodePageUtil.CP_UNICODE) { return; } String cps = ""; try { cps = CodePageUtil.codepageToEncoding(cp, false); } catch (UnsupportedEncodingException e) { LOG.log(POILogger.ERROR, "Codepage '"+cp+"' can't be found."); } if (!cps.isEmpty() && Charset.forName(cps).newEncoder().canEncode(value)) { return; } LOG.log(POILogger.DEBUG, "Charset '"+cps+"' can't encode '"+value+"' - switching to unicode."); setCodepage(CodePageUtil.CP_UNICODE); } }
String csStr = CodePageUtil.codepageToEncoding(codepage > 0 ? codepage : Property.DEFAULT_CODEPAGE); if (!Charset.forName(csStr).newEncoder().canEncode((String)value)) { variantType = Variant.VT_LPWSTR;
int codepage = ((LongPropertyValue)val.get(0)).getValue(); try { String encoding = CodePageUtil.codepageToEncoding(codepage, true); set7BitEncoding(encoding); return;
String encoding = null; try { encoding = CodePageUtil.codepageToEncoding(codepage, true); } catch (UnsupportedEncodingException e) {
String encoding = null; try { encoding = CodePageUtil.codepageToEncoding(codepage, true); } catch (UnsupportedEncodingException e) {
String encoding = null; try { encoding = CodePageUtil.codepageToEncoding(codepage, true); } catch (UnsupportedEncodingException e) {
modules.charset = Charset.forName(CodePageUtil.codepageToEncoding(codepage, true)); break; case MODULE_STREAM_NAME: