Permalink
Browse files

Closing Output stream when necessary.

  • Loading branch information...
1 parent 5848c29 commit 386d318445f98779ac774eda040dc00d8d24000c @rbpark committed Mar 21, 2012
Showing with 24 additions and 14 deletions.
  1. +24 −14 azkaban/src/java/azkaban/web/pages/HdfsBrowserServlet.java
@@ -182,7 +182,6 @@ public FileSystem run() {
finally {
fs.close();
}
- fs.close();
}
}
@@ -252,21 +251,32 @@ private void displayFile(FileSystem fs, HttpServletRequest req, HttpServletRespo
// use registered viewers to show the file content
boolean outputed = false;
- OutputStream output = resp.getOutputStream();
- for(HdfsFileViewer viewer: _viewers) {
- if(viewer.canReadFile(fs, path)) {
- viewer.displayFile(fs, path, output, startLine, endLine);
- outputed = true;
- break; // don't need to try other viewers
+ OutputStream output = null;
+
+ try {
+ output = resp.getOutputStream();
+ for(HdfsFileViewer viewer: _viewers) {
+ if(viewer.canReadFile(fs, path)) {
+ viewer.displayFile(fs, path, output, startLine, endLine);
+ outputed = true;
+ break; // don't need to try other viewers
+ }
}
+
+ // use default text viewer
+ if(!outputed) {
+ if(_defaultViewer.canReadFile(fs, path)) {
+ _defaultViewer.displayFile(fs, path, output, startLine, endLine);
+ } else {
+ output.write(("Sorry, no viewer available for this file. ").getBytes("UTF-8"));
+ }
+ }
+ } catch (IOException e) {
+ throw e;
}
-
- // use default text viewer
- if(!outputed) {
- if(_defaultViewer.canReadFile(fs, path)) {
- _defaultViewer.displayFile(fs, path, output, startLine, endLine);
- } else {
- output.write(("Sorry, no viewer available for this file. ").getBytes("UTF-8"));
+ finally {
+ if (output != null) {
+ output.close();
}
}
}

0 comments on commit 386d318

Please sign in to comment.