Author: markt Date: Wed Mar 26 14:40:03 2014 New Revision: 1581867 URL: http://svn.apache.org/r1581867 Log: More try-with-resources
Modified: tomcat/trunk/TOMCAT-NEXT.txt tomcat/trunk/java/org/apache/catalina/storeconfig/StandardContextSF.java tomcat/trunk/java/org/apache/catalina/storeconfig/StoreConfig.java Modified: tomcat/trunk/TOMCAT-NEXT.txt URL: http://svn.apache.org/viewvc/tomcat/trunk/TOMCAT-NEXT.txt?rev=1581867&r1=1581866&r2=1581867&view=diff ============================================================================== --- tomcat/trunk/TOMCAT-NEXT.txt (original) +++ tomcat/trunk/TOMCAT-NEXT.txt Wed Mar 26 14:40:03 2014 @@ -214,7 +214,7 @@ but possibly 7.1.x). - Use of try with resources - Started. - javax.* complete - - o.a.catalina.[ant to startup] complete + - o.a.catalina.[ant to storeconfig] complete - remainder TODO - Catching multiple exceptions - Started Modified: tomcat/trunk/java/org/apache/catalina/storeconfig/StandardContextSF.java URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/catalina/storeconfig/StandardContextSF.java?rev=1581867&r1=1581866&r2=1581867&view=diff ============================================================================== --- tomcat/trunk/java/org/apache/catalina/storeconfig/StandardContextSF.java (original) +++ tomcat/trunk/java/org/apache/catalina/storeconfig/StandardContextSF.java Wed Mar 26 14:40:03 2014 @@ -116,7 +116,6 @@ public class StandardContextSF extends S protected void storeContextSeparate(PrintWriter aWriter, int indent, StandardContext aContext) throws Exception { URL configFile = aContext.getConfigFile(); - PrintWriter writer = null; if (configFile != null) { File config = new File(configFile.toURI()); if (!config.isAbsolute()) { @@ -133,25 +132,11 @@ public class StandardContextSF extends S if (log.isInfoEnabled()) log.info("Store Context " + aContext.getPath() + " separate at file " + config); - try { - writer = new PrintWriter(new OutputStreamWriter( - new FileOutputStream(config), getRegistry() - .getEncoding())); + try (FileOutputStream fos = new FileOutputStream(config); + PrintWriter writer = new PrintWriter(new OutputStreamWriter( + fos , getRegistry().getEncoding()))) { storeXMLHead(writer); super.store(writer, -2, aContext); - } finally { - if (writer != null) { - try { - writer.flush(); - } catch (Exception e) { - // Ignore - } - try { - writer.close(); - } catch (Throwable t) { - // Ignore - } - } } } else { super.store(aWriter, indent, aContext); @@ -190,25 +175,9 @@ public class StandardContextSF extends S + " separate with backup (at file " + mover.getConfigSave() + " )"); - PrintWriter writer = null; - try { - writer = mover.getWriter(); + try (PrintWriter writer = mover.getWriter()) { storeXMLHead(writer); super.store(writer, -2, aContext); - } finally { - if (writer != null) { - // Flush and close the output file - try { - writer.flush(); - } catch (Exception e) { - log.error(e); - } - try { - writer.close(); - } catch (Exception e) { - throw (e); - } - } } mover.move(); } Modified: tomcat/trunk/java/org/apache/catalina/storeconfig/StoreConfig.java URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/catalina/storeconfig/StoreConfig.java?rev=1581867&r1=1581866&r2=1581867&view=diff ============================================================================== --- tomcat/trunk/java/org/apache/catalina/storeconfig/StoreConfig.java (original) +++ tomcat/trunk/java/org/apache/catalina/storeconfig/StoreConfig.java Wed Mar 26 14:40:03 2014 @@ -230,24 +230,8 @@ public class StoreConfig implements ISto getRegistry().getEncoding()); // Open an output writer for the new configuration file try { - PrintWriter writer = null; - try { - writer = mover.getWriter(); + try (PrintWriter writer = mover.getWriter()) { store(writer, -2, aServer); - } finally { - if (writer != null) { - // Flush and close the output file - try { - writer.flush(); - } catch (Exception e) { - log.error(e); - } - try { - writer.close(); - } catch (Exception e) { - throw (e); - } - } } mover.move(); } catch (Exception e) { --------------------------------------------------------------------- To unsubscribe, e-mail: dev-unsubscr...@tomcat.apache.org For additional commands, e-mail: dev-h...@tomcat.apache.org