Warning fixes.
Few more try-with-resources.
Change-Id: Ifc92de32422ed7ea079a2f800bfa50a1e1fa1913
Signed-off-by: Alexander Kurtakov <akurtako@redhat.com>
diff --git a/org.eclipse.help.base/src/org/eclipse/help/internal/protocols/HelpURLConnection.java b/org.eclipse.help.base/src/org/eclipse/help/internal/protocols/HelpURLConnection.java
index f7ae95a..1100661 100644
--- a/org.eclipse.help.base/src/org/eclipse/help/internal/protocols/HelpURLConnection.java
+++ b/org.eclipse.help.base/src/org/eclipse/help/internal/protocols/HelpURLConnection.java
@@ -154,10 +154,9 @@
}
private InputStream getLocalHelp(Bundle plugin) {
- InputStream in;
// first try using content provider, then try to find the file
// inside doc.zip, and finally try the file system
- in = ResourceLocator.openFromProducer(plugin,
+ InputStream in = ResourceLocator.openFromProducer(plugin,
query == null ? getFile() : getFile() + "?" + query, //$NON-NLS-1$
getLocale());
@@ -504,14 +503,13 @@
try{
if (in!=null)
{
- BufferedReader br = new BufferedReader(new InputStreamReader(in));
- String line,result=""; //$NON-NLS-1$
+ String line, result = ""; //$NON-NLS-1$
+ try (BufferedReader br = new BufferedReader(new InputStreamReader(in))) {
- while ((line = br.readLine())!=null)
- {
- result+=line+'\n';
+ while ((line = br.readLine()) != null) {
+ result += line + '\n';
+ }
}
- br.close();
in.close();
return result;
}
diff --git a/org.eclipse.help.webapp/src/org/eclipse/help/internal/webapp/data/PrintData.java b/org.eclipse.help.webapp/src/org/eclipse/help/internal/webapp/data/PrintData.java
index 2cc7c64..ff30e50 100644
--- a/org.eclipse.help.webapp/src/org/eclipse/help/internal/webapp/data/PrintData.java
+++ b/org.eclipse.help.webapp/src/org/eclipse/help/internal/webapp/data/PrintData.java
@@ -391,11 +391,12 @@
in = HelpSystem.getHelpContent(href, locale);
}
- Reader reader = new BufferedReader(new InputStreamReader(in, charset));
- char[] cbuf = new char[4096];
- int num;
- while ((num = reader.read(cbuf)) > 0) {
- buf.append(cbuf, 0, num);
+ try (Reader reader = new BufferedReader(new InputStreamReader(in, charset))) {
+ char[] cbuf = new char[4096];
+ int num;
+ while ((num = reader.read(cbuf)) > 0) {
+ buf.append(cbuf, 0, num);
+ }
}
}
catch (Exception e) {