From: <ma...@rh...> - 2008-11-07 19:34:18
|
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head><style type="text/css"><!-- #msg DL { border : 1px #006 solid; background-color : #369; padding : 6px; color : #fff; } #msg DT { float : left; width : 6em; font-weight : bold; } #msg DL, #msg DT, #msg UL, #msg LI { font-family : arial,helvetica,sans-serif; font-size : 10pt; } h3 { font-family : arial,helvetica,sans-serif; font-size : 10pt; font-weight : bold; } #msg PRE { overflow : auto; white-space : normal; background-color : #ffc; border : 1px #fc0 solid; padding : 6px; } #msg UL, PRE, .diff { overflow : auto; } #patch h4 { font-family : arial,helvetica,sans-serif; font-size : 10pt; } #patch h4 { padding: 8px; background : #369; color : #fff; margin : 0; } #patch .propset h4, #patch .binary h4 {margin: 0;} #patch pre {padding:0;line-height:1.2em;margin:0;} #patch .diff {background:#eeeeee;padding: 0 0 10px 0;} #patch .propset .diff, #patch .binary .diff {padding: 10px 0;} #patch span {display:block;padding:0 10px;} #patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;} #patch .add {background:#ddffdd;} #patch .rem {background:#ffdddd;} #patch .lines, .info {color:#888888;background:#ffffff;} .diff { width : 100%; } #msg DL { border : 1px #006 solid; background-color : #369; padding : 6px; color : #fff; } #msg DT { float : left; width : 6em; font-weight : bold; } #msg DL, #msg DT, #msg UL, #msg LI { font-family : arial,helvetica,sans-serif; font-size : 10pt; } h3 { font-family : arial,helvetica,sans-serif; font-size : 10pt; font-weight : bold; } #msg PRE { overflow : auto; white-space : normal; background-color : #ffc; border : 1px #fc0 solid; padding : 6px; } #msg UL, PRE, .diff { overflow : auto; } #patch h4 { font-family : arial,helvetica,sans-serif; font-size : 10pt; } #patch h4 { padding: 8px; background : #369; color : #fff; margin : 0; } #patch .propset h4, #patch .binary h4 {margin: 0;} #patch pre {padding:0;line-height:1.2em;margin:0;} #patch .diff {background:#eeeeee;padding: 0 0 10px 0;} #patch .propset .diff, #patch .binary .diff {padding: 10px 0;} #patch span {display:block;padding:0 10px;} #patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;} #patch .add {background:#ddffdd;} #patch .rem {background:#ffdddd;} #patch .lines, .info {color:#888888;background:#ffffff;} .diff { width : 100%; } --></style> <title>[rhq-project.org rhq] [1920] close the streams properly</title> </head> <body> <div id="msg"> <dl> <dt>Revision</dt> <dd>1920</dd> <dt>Author</dt> <dd>mazz</dd> <dt>Date</dt> <dd>2008-11-07 13:34:13 -0600 (Fri, 07 Nov 2008)</dd> </dl> <h3>Log Message</h3> <pre>close the streams properly</pre> <h3>Modified Paths</h3> <ul> <li><a href="#rhqtrunkmodulesenterpriseserverjarsrcmainjavaorgrhqenterpriseserverplugincontentContentSourcePluginClassLoaderjava">rhq/trunk/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/plugin/content/ContentSourcePluginClassLoader.java</a></li> </ul> </div> <div id="patch"> <h3>Diff</h3> <a id="rhqtrunkmodulesenterpriseserverjarsrcmainjavaorgrhqenterpriseserverplugincontentContentSourcePluginClassLoaderjava"></a> <div class="modfile"><h4>Modified: rhq/trunk/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/plugin/content/ContentSourcePluginClassLoader.java (1919 => 1920)</h4> <pre class="diff"> <span class="info">--- rhq/trunk/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/plugin/content/ContentSourcePluginClassLoader.java 2008-11-07 19:31:00 UTC (rev 1919) +++ rhq/trunk/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/plugin/content/ContentSourcePluginClassLoader.java 2008-11-07 19:34:13 UTC (rev 1920) </span><span class="lines">@@ -100,75 +100,79 @@ </span><span class="cx"> ZipEntry entry; File extractionDirectory = null; // this is where we will actually store the files we extract </span><span class="rem">- while ((entry = zis.getNextEntry()) != null) { - String entryName = entry.getName(); </span><span class="add">+ try { + while ((entry = zis.getNextEntry()) != null) { + String entryName = entry.getName(); </span><span class="cx"> </span><span class="rem">- // Only care about entries in the lib directory - if (entryName.startsWith("lib") && (entryName.length() > 4)) { - if (extractionDirectory == null) { - extractionDirectory = createTempDirectory(tmpDirectory, pluginJarName); - } </span><span class="add">+ // Only care about entries in the lib directory + if (entryName.startsWith("lib") && (entryName.length() > 4)) { + if (extractionDirectory == null) { + extractionDirectory = createTempDirectory(tmpDirectory, pluginJarName); + } </span><span class="cx"> </span><span class="rem">- int i = entryName.lastIndexOf('/'); - if (i < 0) { - i = entryName.lastIndexOf('\\'); - } </span><span class="add">+ int i = entryName.lastIndexOf('/'); + if (i < 0) { + i = entryName.lastIndexOf('\\'); + } </span><span class="cx"> </span><span class="rem">- String s = entryName.substring(i + 1); </span><span class="add">+ String s = entryName.substring(i + 1); </span><span class="cx"> </span><span class="rem">- File file = null; - try { - if (s.endsWith(".jar")) { - file = File.createTempFile(s, null, extractionDirectory); - urls.add(file.toURL()); - } else { - // All non-jar files are extracted as-is with the - // same filename. - file = new File(extractionDirectory, s); </span><span class="add">+ File file = null; + try { + if (s.endsWith(".jar")) { + file = File.createTempFile(s, null, extractionDirectory); + urls.add(file.toURI().toURL()); + } else { + // All non-jar files are extracted as-is with the + // same filename. + file = new File(extractionDirectory, s); </span><span class="cx"> </span><span class="rem">- // since we have a regular file, we need to make sure the tmp dir is in classpath so it can be found - URL tmpUrl = extractionDirectory.toURL(); - if (!urls.contains(tmpUrl)) { - urls.add(tmpUrl); </span><span class="add">+ // since we have a regular file, we need to make sure the tmp dir is in classpath so it can be found + URL tmpUrl = extractionDirectory.toURI().toURL(); + if (!urls.contains(tmpUrl)) { + urls.add(tmpUrl); + } </span><span class="cx"> } </span><span class="rem">- } </span><span class="cx"> </span><span class="rem">- BufferedOutputStream outputStream; - try { - outputStream = new BufferedOutputStream(new FileOutputStream(file)); - } catch (FileNotFoundException ex) { - if (file.exists() && (file.length() > 0)) { - // e.g. on win32, agent running w/ dll loaded PluginDumper cannot overwrite file inuse. - continue; </span><span class="add">+ BufferedOutputStream outputStream; + try { + outputStream = new BufferedOutputStream(new FileOutputStream(file)); + } catch (FileNotFoundException ex) { + if (file.exists() && (file.length() > 0)) { + // e.g. on win32, agent running w/ dll loaded PluginDumper cannot overwrite file inuse. + continue; + } + + throw ex; </span><span class="cx"> } </span><span class="rem">- throw ex; - } </span><span class="add">+ try { + file.deleteOnExit(); </span><span class="cx"> </span><span class="rem">- file.deleteOnExit(); </span><span class="add">+ BufferedInputStream inputStream = new BufferedInputStream(zis); </span><span class="cx"> </span><span class="rem">- BufferedInputStream inputStream = new BufferedInputStream(zis); </span><span class="add">+ int count = 0; + byte[] b = new byte[8192]; + while ((count = inputStream.read(b)) > -1) { + outputStream.write(b, 0, count); + } + } finally { + outputStream.flush(); + outputStream.close(); + } + } catch (IOException ioe) { + if (file != null) { + file.delete(); + } </span><span class="cx"> </span><span class="rem">- int count = 0; - byte[] b = new byte[8192]; - while ((count = inputStream.read(b)) > -1) { - outputStream.write(b, 0, count); </span><span class="add">+ throw ioe; </span><span class="cx"> } </span><span class="rem">- - outputStream.flush(); - outputStream.close(); - } catch (IOException ioe) { - if (file != null) { - file.delete(); - } - - throw ioe; </span><span class="cx"> } } </span><span class="add">+ } finally { + zis.close(); </span><span class="cx"> } </span><span class="rem">- zis.close(); - </span><span class="cx"> return extractionDirectory; } </span> </pre> </div> </div> </body> </html> |