r1897 - trunk/nuiton-i18n/src/main/java/org/nuiton/i18n/bundle
Author: fdesbois Date: 2011-05-04 00:29:45 +0200 (Wed, 04 May 2011) New Revision: 1897 Url: http://nuiton.org/repositories/revision/i18n/1897 Log: #1495 : Add methods to use specific encoding with File. The one from instance is renamed defaultEncoding. Keep same implementation as superclass for overriden methods (need only removeHeader management) Modified: trunk/nuiton-i18n/src/main/java/org/nuiton/i18n/bundle/I18nBundleEntry.java Modified: trunk/nuiton-i18n/src/main/java/org/nuiton/i18n/bundle/I18nBundleEntry.java =================================================================== --- trunk/nuiton-i18n/src/main/java/org/nuiton/i18n/bundle/I18nBundleEntry.java 2011-05-03 09:40:22 UTC (rev 1896) +++ trunk/nuiton-i18n/src/main/java/org/nuiton/i18n/bundle/I18nBundleEntry.java 2011-05-03 22:29:45 UTC (rev 1897) @@ -122,51 +122,46 @@ * * @param resource the save of resources already loaded * @throws IOException if any pb while reading resource file + * @deprecated since 2.4 use {@link #load(Properties, String)} instead, charset must be provided to avoid encoding problems */ + @Deprecated public void load(Properties resource) throws IOException { + String encoding = I18nUtil.ISO_8859_1_ENCONDING; + load(resource, encoding); + } + + /** + * For a given language, load the resource file of this entry into the + * <code>resource</code> properties object. Use {@code charset} to load + * properties. It could be different from resulting properties store. + * + * @param resource the save of resources already loaded + * @param encoding Encoding used to store the properties + * @throws IOException if any pb while reading resource file + * @since 2.4 + */ + public void load(Properties resource, String encoding) throws IOException { InputStream inputStream = null; StringBuilder sb = new StringBuilder(); try { -// I18nFileReader fileReader = new I18nFileReader(); - Properties fileReader = new Properties() { - private static final long serialVersionUID = 1L; - - @Override - public synchronized void load(InputStream inStream) throws IOException { - String charset = I18nUtil.ISO_8859_1_ENCONDING; - Charset charsetTo = Charset.forName(charset); - - BufferedReader readerFile = new BufferedReader( - new InputStreamReader(inStream, charsetTo)); - try { - String lineFile; - StringBuilder builderFile; - builderFile = new StringBuilder(); - while ((lineFile = readerFile.readLine()) != null) { - builderFile.append(lineFile).append('\n'); - } - super.load(new ByteArrayInputStream( - builderFile.toString().getBytes())); - } finally { - readerFile.close(); - } - } - }; - inputStream = getPath().openStream(); - //String encoding = language.getEncoding(); if (I18nBundle.log.isDebugEnabled()) { sb.append(getPath()).append("\n"); } - // TC 20081117 always use ISO_8859_1_ENCONDING, since java does - // it like this. - fileReader.load(inputStream); -// fileReader.load(inputStream, I18nUtil.ISO_8859_1_ENCONDING); + // Prepare new Properties using charset to load entries + Properties fileReader = new Properties(); + Reader reader = new InputStreamReader(inputStream, encoding); + try { + fileReader.load(reader); + } finally { + reader.close(); + } + if (I18nBundle.log.isDebugEnabled()) { for (Entry<Object, Object> entry : fileReader.entrySet()) { - sb.append(I18nUtil.ISO_8859_1_ENCONDING); + sb.append(encoding); sb.append(" : "); sb.append(entry); sb.append("\n");
participants (1)
-
fdesbois@users.nuiton.org