You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomcat.apache.org by vi...@apache.org on 2015/12/29 19:16:29 UTC
svn commit: r1722205 - in /tomcat/trunk/test/org/apache:
catalina/connector/TestSendFile.java catalina/loader/TestVirtualContext.java
tomcat/util/descriptor/web/TestWebRuleSet.java
Author: violetagg
Date: Tue Dec 29 18:16:28 2015
New Revision: 1722205
URL: http://svn.apache.org/viewvc?rev=1722205&view=rev
Log:
Close streams
Modified:
tomcat/trunk/test/org/apache/catalina/connector/TestSendFile.java
tomcat/trunk/test/org/apache/catalina/loader/TestVirtualContext.java
tomcat/trunk/test/org/apache/tomcat/util/descriptor/web/TestWebRuleSet.java
Modified: tomcat/trunk/test/org/apache/catalina/connector/TestSendFile.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/test/org/apache/catalina/connector/TestSendFile.java?rev=1722205&r1=1722204&r2=1722205&view=diff
==============================================================================
--- tomcat/trunk/test/org/apache/catalina/connector/TestSendFile.java (original)
+++ tomcat/trunk/test/org/apache/catalina/connector/TestSendFile.java Tue Dec 29 18:16:28 2015
@@ -86,21 +86,21 @@ public class TestSendFile extends Tomcat
}
public File generateFile(String dir, String suffix, int size) throws IOException {
- String name = "testSendFile-"+System.currentTimeMillis()+suffix+".txt";
- File f = new File(dir,name);
- FileWriter fw = new FileWriter(f, false);
- BufferedWriter w = new BufferedWriter(fw);
- int defSize = 8192;
- while (size > 0) {
- int bytes = Math.min(size, defSize);
- char[] b = new char[bytes];
- Arrays.fill(b, 'X');
- w.write(b);
- size = size - bytes;
+ String name = "testSendFile-" + System.currentTimeMillis() + suffix + ".txt";
+ File f = new File(dir, name);
+ try (FileWriter fw = new FileWriter(f, false); BufferedWriter w = new BufferedWriter(fw);) {
+ int defSize = 8192;
+ while (size > 0) {
+ int bytes = Math.min(size, defSize);
+ char[] b = new char[bytes];
+ Arrays.fill(b, 'X');
+ w.write(b);
+ size = size - bytes;
+ }
+ w.flush();
}
- w.flush();
- w.close();
- System.out.println("Created file:"+f.getAbsolutePath()+" with "+f.length()+" bytes.");
+ System.out.println("Created file:" + f.getAbsolutePath() + " with " + f.length()
+ + " bytes.");
return f;
}
Modified: tomcat/trunk/test/org/apache/catalina/loader/TestVirtualContext.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/test/org/apache/catalina/loader/TestVirtualContext.java?rev=1722205&r1=1722204&r2=1722205&view=diff
==============================================================================
--- tomcat/trunk/test/org/apache/catalina/loader/TestVirtualContext.java (original)
+++ tomcat/trunk/test/org/apache/catalina/loader/TestVirtualContext.java Tue Dec 29 18:16:28 2015
@@ -266,15 +266,13 @@ public class TestVirtualContext extends
new File(additionWebInfClasses,
MyAnnotatedServlet.class.getPackage().getName().replace('.', '/'));
Assert.assertTrue(targetPackageForAnnotatedClass.mkdirs());
- InputStream annotatedServletClassInputStream =
- this.getClass().getResourceAsStream(
+ try (InputStream annotatedServletClassInputStream = this.getClass().getResourceAsStream(
MyAnnotatedServlet.class.getSimpleName() + ".class");
- FileOutputStream annotatedServletClassOutputStream =
- new FileOutputStream(new File(targetPackageForAnnotatedClass,
- MyAnnotatedServlet.class.getSimpleName() + ".class"));
- IOUtils.copy(annotatedServletClassInputStream, annotatedServletClassOutputStream);
- annotatedServletClassInputStream.close();
- annotatedServletClassOutputStream.close();
+ FileOutputStream annotatedServletClassOutputStream = new FileOutputStream(new File(
+ targetPackageForAnnotatedClass, MyAnnotatedServlet.class.getSimpleName()
+ + ".class"));) {
+ IOUtils.copy(annotatedServletClassInputStream, annotatedServletClassOutputStream);
+ }
ctx.setResources(new StandardRoot(ctx));
File f1 = new File("test/webapp-virtual-webapp/target/classes");
Modified: tomcat/trunk/test/org/apache/tomcat/util/descriptor/web/TestWebRuleSet.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/test/org/apache/tomcat/util/descriptor/web/TestWebRuleSet.java?rev=1722205&r1=1722204&r2=1722205&view=diff
==============================================================================
--- tomcat/trunk/test/org/apache/tomcat/util/descriptor/web/TestWebRuleSet.java (original)
+++ tomcat/trunk/test/org/apache/tomcat/util/descriptor/web/TestWebRuleSet.java Tue Dec 29 18:16:28 2015
@@ -18,7 +18,6 @@ package org.apache.tomcat.util.descripto
import java.io.File;
import java.io.FileInputStream;
-import java.io.FileNotFoundException;
import java.io.InputStream;
import static org.junit.Assert.assertEquals;
@@ -123,7 +122,7 @@ public class TestWebRuleSet {
}
private synchronized void parse(WebXml webXml, String target,
- boolean fragment, boolean expected) throws FileNotFoundException {
+ boolean fragment, boolean expected) {
Digester d;
if (fragment) {
@@ -137,11 +136,10 @@ public class TestWebRuleSet {
d.push(webXml);
File f = new File("test/org/apache/catalina/startup/" + target);
- InputStream is = new FileInputStream(f);
boolean result = true;
- try {
+ try (InputStream is = new FileInputStream(f);) {
d.parse(is);
} catch (Exception e) {
if (expected) {
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org