aboutsummaryrefslogtreecommitdiffstats
path: root/server/src/com/vaadin/ui
diff options
context:
space:
mode:
authorDenis Anisimov <denis@vaadin.com>2014-09-26 20:44:32 +0300
committerSauli Tähkäpää <sauli@vaadin.com>2014-10-13 09:54:56 +0300
commitb3de415c25f89b7a23d977caa47bc7fafa3344ed (patch)
tree1937d24fb57885205fdfe1e684b1b84172ebeb1b /server/src/com/vaadin/ui
parentfbdbd0cf1e078034890fdd75379716648af1706c (diff)
downloadvaadin-framework-b3de415c25f89b7a23d977caa47bc7fafa3344ed.tar.gz
vaadin-framework-b3de415c25f89b7a23d977caa47bc7fafa3344ed.zip
Read input stream logic is corrected (#14533).
Change-Id: I1a8a895d631889e04f7acbde29306e86da344a23
Diffstat (limited to 'server/src/com/vaadin/ui')
-rw-r--r--server/src/com/vaadin/ui/CustomLayout.java25
1 files changed, 12 insertions, 13 deletions
diff --git a/server/src/com/vaadin/ui/CustomLayout.java b/server/src/com/vaadin/ui/CustomLayout.java
index 7f1aa1ce46..f4fe7fa66c 100644
--- a/server/src/com/vaadin/ui/CustomLayout.java
+++ b/server/src/com/vaadin/ui/CustomLayout.java
@@ -16,6 +16,7 @@
package com.vaadin.ui;
+import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
@@ -101,22 +102,20 @@ public class CustomLayout extends AbstractLayout implements LegacyComponent {
protected void initTemplateContentsFromInputStream(
InputStream templateStream) throws IOException {
- InputStreamReader reader = new InputStreamReader(templateStream,
- "UTF-8");
- StringBuilder b = new StringBuilder(BUFFER_SIZE);
-
- char[] cbuf = new char[BUFFER_SIZE];
- int offset = 0;
-
- while (true) {
- int nrRead = reader.read(cbuf, offset, BUFFER_SIZE);
- b.append(cbuf, 0, nrRead);
- if (nrRead < BUFFER_SIZE) {
- break;
+ BufferedReader reader = new BufferedReader(new InputStreamReader(
+ templateStream, "UTF-8"));
+ StringBuilder builder = new StringBuilder(BUFFER_SIZE);
+ try {
+ char[] cbuf = new char[BUFFER_SIZE];
+ int nRead;
+ while ((nRead = reader.read(cbuf, 0, BUFFER_SIZE)) > 0) {
+ builder.append(cbuf, 0, nRead);
}
+ } finally {
+ reader.close();
}
- setTemplateContents(b.toString());
+ setTemplateContents(builder.toString());
}
@Override