From: <otm...@us...> - 2006-10-29 23:23:18
|
Revision: 2969 http://svn.sourceforge.net/jython/?rev=2969&view=rev Author: otmarhumbel Date: 2006-10-29 15:23:12 -0800 (Sun, 29 Oct 2006) Log Message: ----------- try to work around problems on platforms with default encoding UTF-8 Modified Paths: -------------- trunk/installer/src/java/org/python/util/install/JarInfo.java Modified: trunk/installer/src/java/org/python/util/install/JarInfo.java =================================================================== --- trunk/installer/src/java/org/python/util/install/JarInfo.java 2006-10-29 23:18:18 UTC (rev 2968) +++ trunk/installer/src/java/org/python/util/install/JarInfo.java 2006-10-29 23:23:12 UTC (rev 2969) @@ -5,6 +5,7 @@ import java.io.IOException; import java.io.InputStreamReader; import java.net.URL; +import java.nio.charset.Charset; import java.util.ArrayList; import java.util.Enumeration; import java.util.List; @@ -145,22 +146,73 @@ } private String readTextFile(JarEntry entry, JarFile jarFile) throws IOException { - StringBuffer buffer = new StringBuffer(10000); + StringBuffer buffer = new StringBuffer(); BufferedReader reader = null; - try { - reader = new BufferedReader(new InputStreamReader(jarFile.getInputStream(entry))); - for (String s; (s = reader.readLine()) != null;) { - buffer.append(s); - buffer.append("\n"); + String charsetName = "US-ASCII"; + boolean ok = false; + if (Charset.isSupported(charsetName)) { + try { + reader = new BufferedReader(new InputStreamReader(jarFile.getInputStream(entry), Charset + .forName(charsetName))); + buffer = new StringBuffer(1000); + for (String s; (s = reader.readLine()) != null;) { + buffer.append(s); + buffer.append("\n"); + } + ok = true; + } catch (IOException ioe) { + // TODO:oti rewrite after 390 tests + ioe.printStackTrace(); + } finally { + if (reader != null) + try { + reader.close(); + } catch (IOException e) { + e.printStackTrace(); + } } - } finally { - if (reader != null) + } + if (!ok) { + charsetName = "ISO-8859-1"; + if (Charset.isSupported(charsetName)) { try { - reader.close(); - } catch (IOException e) { - e.printStackTrace(); + reader = new BufferedReader(new InputStreamReader(jarFile.getInputStream(entry), Charset + .forName(charsetName))); + buffer = new StringBuffer(1000); + for (String s; (s = reader.readLine()) != null;) { + buffer.append(s); + buffer.append("\n"); + } + } catch (IOException ioe) { + ioe.printStackTrace(); + } finally { + if (reader != null) + try { + reader.close(); + } catch (IOException e) { + e.printStackTrace(); + } } + } } + if (!ok) { + try { + reader = new BufferedReader(new InputStreamReader(jarFile.getInputStream(entry))); + buffer = new StringBuffer(1000); + for (String s; (s = reader.readLine()) != null;) { + buffer.append(s); + buffer.append("\n"); + } + } finally { + if (reader != null) + try { + reader.close(); + } catch (IOException e) { + e.printStackTrace(); + } + } + } return buffer.toString(); } + } \ No newline at end of file This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <otm...@us...> - 2006-10-31 23:05:00
|
Revision: 2970 http://svn.sourceforge.net/jython/?rev=2970&view=rev Author: otmarhumbel Date: 2006-10-31 15:04:53 -0800 (Tue, 31 Oct 2006) Log Message: ----------- Clarified reading of text files out of the installer .jar file. Installation was confirmed to run on a platform with default encoding = UTF-8 (z/Series SUSE Linux). Modified Paths: -------------- trunk/installer/src/java/org/python/util/install/JarInfo.java Modified: trunk/installer/src/java/org/python/util/install/JarInfo.java =================================================================== --- trunk/installer/src/java/org/python/util/install/JarInfo.java 2006-10-29 23:23:12 UTC (rev 2969) +++ trunk/installer/src/java/org/python/util/install/JarInfo.java 2006-10-31 23:04:53 UTC (rev 2970) @@ -145,13 +145,43 @@ jarFile.close(); } + /** + * Read the text file with the most appropriate Charset. + * + * @param entry + * @param jarFile + * + * @return the contents of the text file + * + * @throws IOException + */ private String readTextFile(JarEntry entry, JarFile jarFile) throws IOException { - StringBuffer buffer = new StringBuffer(); - BufferedReader reader = null; - String charsetName = "US-ASCII"; - boolean ok = false; + String contents = readTextFileWithCharset(jarFile, entry, "US-ASCII"); // expected to run on most platforms + if (contents == null) { + contents = readTextFileWithCharset(jarFile, entry, "ISO-8859-1"); + } + if (contents == null) { + contents = readTextFileWithDefaultCharset(jarFile, entry); + } + return contents; + } + + /** + * Try to read the text file (jarEntry) from the jarFile, using a given <code>charsetName</code>. + * + * @param jarFile + * @param entry + * @param charsetName the name of the Charset + * + * @return the contents of the text file as String (if reading was successful), <code>null</code> otherwise.<br> + * No exception is thrown + */ + private String readTextFileWithCharset(JarFile jarFile, JarEntry entry, String charsetName) { + String contents = null; if (Charset.isSupported(charsetName)) { + BufferedReader reader = null; try { + StringBuffer buffer = new StringBuffer(1000); reader = new BufferedReader(new InputStreamReader(jarFile.getInputStream(entry), Charset .forName(charsetName))); buffer = new StringBuffer(1000); @@ -159,60 +189,45 @@ buffer.append(s); buffer.append("\n"); } - ok = true; + contents = buffer.toString(); } catch (IOException ioe) { - // TODO:oti rewrite after 390 tests - ioe.printStackTrace(); } finally { if (reader != null) try { reader.close(); } catch (IOException e) { - e.printStackTrace(); } } } - if (!ok) { - charsetName = "ISO-8859-1"; - if (Charset.isSupported(charsetName)) { - try { - reader = new BufferedReader(new InputStreamReader(jarFile.getInputStream(entry), Charset - .forName(charsetName))); - buffer = new StringBuffer(1000); - for (String s; (s = reader.readLine()) != null;) { - buffer.append(s); - buffer.append("\n"); - } - } catch (IOException ioe) { - ioe.printStackTrace(); - } finally { - if (reader != null) - try { - reader.close(); - } catch (IOException e) { - e.printStackTrace(); - } - } + return contents; + } + + /** + * Read the text file (jarEntry) from the jarFile, using the platform default Charset. + * + * @param jarFile + * @param entry + * + * @return the contents of the text file as String. + * + * @throws IOException if a problem occurs + */ + private String readTextFileWithDefaultCharset(JarFile jarFile, JarEntry entry) throws IOException { + String contents = null; + BufferedReader reader = null; + try { + reader = new BufferedReader(new InputStreamReader(jarFile.getInputStream(entry))); + StringBuffer buffer = new StringBuffer(1000); + for (String s; (s = reader.readLine()) != null;) { + buffer.append(s); + buffer.append("\n"); } + contents = buffer.toString(); + } finally { + if (reader != null) + reader.close(); } - if (!ok) { - try { - reader = new BufferedReader(new InputStreamReader(jarFile.getInputStream(entry))); - buffer = new StringBuffer(1000); - for (String s; (s = reader.readLine()) != null;) { - buffer.append(s); - buffer.append("\n"); - } - } finally { - if (reader != null) - try { - reader.close(); - } catch (IOException e) { - e.printStackTrace(); - } - } - } - return buffer.toString(); + return contents; } } \ No newline at end of file This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <otm...@us...> - 2006-12-28 15:10:58
|
Revision: 3032 http://svn.sourceforge.net/jython/?rev=3032&view=rev Author: otmarhumbel Date: 2006-12-28 07:10:57 -0800 (Thu, 28 Dec 2006) Log Message: ----------- use URLDecoder instead of decoding "by hand" Modified Paths: -------------- trunk/installer/src/java/org/python/util/install/JarInfo.java Modified: trunk/installer/src/java/org/python/util/install/JarInfo.java =================================================================== --- trunk/installer/src/java/org/python/util/install/JarInfo.java 2006-12-28 15:10:49 UTC (rev 3031) +++ trunk/installer/src/java/org/python/util/install/JarInfo.java 2006-12-28 15:10:57 UTC (rev 3032) @@ -5,6 +5,7 @@ import java.io.IOException; import java.io.InputStreamReader; import java.net.URL; +import java.net.URLDecoder; import java.nio.charset.Charset; import java.util.ArrayList; import java.util.Enumeration; @@ -22,7 +23,6 @@ private static final String VERSION_ATTRIBUTE = "version"; private static final String EXCLUDE_DIRS_ATTRIBUTE = "exclude-dirs"; private static final String EXCLUDE_DIRS_DELIM = ";"; - private static final String URL_BLANK_REPLACEMENT = "%20"; private File _jarFile; private int _numberOfEntries; @@ -111,16 +111,12 @@ URL url = getClass().getResource(className + ".class"); // we expect an URL like: // jar:file:/C:/stuff/jython21i.jar!/org/python/util/install/JarInfo.class - String urlString = url.toString(); + String urlString = URLDecoder.decode(url.toString(), "UTF-8"); int jarSeparatorIndex = urlString.indexOf(JAR_SEPARATOR); if (!urlString.startsWith(JAR_URL_PREFIX) || jarSeparatorIndex <= 0) { throw new InstallerException(Installation.getText(TextKeys.UNEXPECTED_URL, urlString)); } String jarFileName = urlString.substring(JAR_URL_PREFIX.length(), jarSeparatorIndex); - // handle directories containing blanks - if (jarFileName.indexOf(URL_BLANK_REPLACEMENT) >= 0) { - jarFileName = jarFileName.replaceAll(URL_BLANK_REPLACEMENT, " "); - } _jarFile = new File(jarFileName); if (!_jarFile.exists()) { throw new InstallerException(Installation.getText(TextKeys.JAR_NOT_FOUND, _jarFile.getAbsolutePath())); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |