aboutsummaryrefslogtreecommitdiffstats
path: root/server
diff options
context:
space:
mode:
authorAhmed Ashour <asashour@yahoo.com>2017-03-07 09:38:05 +0100
committerHenri Sara <henri.sara@gmail.com>2017-03-07 15:43:00 +0200
commit205fd1843228be9ab9248975c5308ac3b5efe19a (patch)
treee0043aa35343662fa4205b0cec07ace4e794e475 /server
parentd865eeae2e5d72059c59584078bf0b532de2b7bd (diff)
downloadvaadin-framework-205fd1843228be9ab9248975c5308ac3b5efe19a.tar.gz
vaadin-framework-205fd1843228be9ab9248975c5308ac3b5efe19a.zip
Use try-with-resources (#8757)
To ensure the resource is automatically closed
Diffstat (limited to 'server')
-rw-r--r--server/src/main/java/com/vaadin/server/themeutils/SASSAddonImportFileCreator.java5
-rw-r--r--server/src/test/java/com/vaadin/tests/server/ClassesSerializableTest.java19
-rw-r--r--server/src/test/java/com/vaadin/tests/server/SimpleMultiPartInputStreamTest.java31
3 files changed, 28 insertions, 27 deletions
diff --git a/server/src/main/java/com/vaadin/server/themeutils/SASSAddonImportFileCreator.java b/server/src/main/java/com/vaadin/server/themeutils/SASSAddonImportFileCreator.java
index a087a1ed31..79d87f960a 100644
--- a/server/src/main/java/com/vaadin/server/themeutils/SASSAddonImportFileCreator.java
+++ b/server/src/main/java/com/vaadin/server/themeutils/SASSAddonImportFileCreator.java
@@ -85,9 +85,8 @@ public class SASSAddonImportFileCreator {
LocationInfo info = ClassPathExplorer
.getAvailableWidgetSetsAndStylesheets();
- try {
- PrintStream printStream = new PrintStream(
- new FileOutputStream(addonImports));
+ try (PrintStream printStream = new PrintStream(
+ new FileOutputStream(addonImports))) {
printStream.println("/* " + ADDON_IMPORTS_FILE_TEXT + " */");
diff --git a/server/src/test/java/com/vaadin/tests/server/ClassesSerializableTest.java b/server/src/test/java/com/vaadin/tests/server/ClassesSerializableTest.java
index a3375585c7..5659ec7c56 100644
--- a/server/src/test/java/com/vaadin/tests/server/ClassesSerializableTest.java
+++ b/server/src/test/java/com/vaadin/tests/server/ClassesSerializableTest.java
@@ -352,15 +352,16 @@ public class ClassesSerializableTest {
private Collection<String> findClassesInJar(File file) throws IOException {
Collection<String> classes = new ArrayList<>();
- JarFile jar = new JarFile(file);
- Enumeration<JarEntry> e = jar.entries();
- while (e.hasMoreElements()) {
- JarEntry entry = e.nextElement();
- if (entry.getName().endsWith(".class")) {
- String nameWithoutExtension = entry.getName()
- .replaceAll("\\.class", "");
- String className = nameWithoutExtension.replace('/', '.');
- classes.add(className);
+ try (JarFile jar = new JarFile(file)) {
+ Enumeration<JarEntry> e = jar.entries();
+ while (e.hasMoreElements()) {
+ JarEntry entry = e.nextElement();
+ if (entry.getName().endsWith(".class")) {
+ String nameWithoutExtension = entry.getName()
+ .replaceAll("\\.class", "");
+ String className = nameWithoutExtension.replace('/', '.');
+ classes.add(className);
+ }
}
}
return classes;
diff --git a/server/src/test/java/com/vaadin/tests/server/SimpleMultiPartInputStreamTest.java b/server/src/test/java/com/vaadin/tests/server/SimpleMultiPartInputStreamTest.java
index 14b839be6a..06ae1570b2 100644
--- a/server/src/test/java/com/vaadin/tests/server/SimpleMultiPartInputStreamTest.java
+++ b/server/src/test/java/com/vaadin/tests/server/SimpleMultiPartInputStreamTest.java
@@ -22,22 +22,23 @@ public class SimpleMultiPartInputStreamTest {
protected void checkBoundaryDetection(byte[] input, String boundary,
byte[] expected) throws Exception {
ByteArrayInputStream bais = new ByteArrayInputStream(input);
- SimpleMultiPartInputStream smpis = new SimpleMultiPartInputStream(bais,
- boundary);
- ByteArrayOutputStream resultStream = new ByteArrayOutputStream();
- int outbyte;
- try {
- while ((outbyte = smpis.read()) != -1) {
- resultStream.write(outbyte);
+ try (SimpleMultiPartInputStream smpis = new SimpleMultiPartInputStream(bais,
+ boundary)) {
+ ByteArrayOutputStream resultStream = new ByteArrayOutputStream();
+ int outbyte;
+ try {
+ while ((outbyte = smpis.read()) != -1) {
+ resultStream.write(outbyte);
+ }
+ } catch (IOException e) {
+ throw new IOException(
+ e.getMessage() + "; expected " + new String(expected)
+ + " but got " + resultStream.toString());
+ }
+ if (!Arrays.equals(expected, resultStream.toByteArray())) {
+ throw new Exception("Mismatch: expected " + new String(expected)
+ + " but got " + resultStream.toString());
}
- } catch (IOException e) {
- throw new IOException(
- e.getMessage() + "; expected " + new String(expected)
- + " but got " + resultStream.toString());
- }
- if (!Arrays.equals(expected, resultStream.toByteArray())) {
- throw new Exception("Mismatch: expected " + new String(expected)
- + " but got " + resultStream.toString());
}
}