Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // DOWNLOAD DOCUMENT SECTION BEGIN
- public void downloadFileListener(FacesContext facesContext, OutputStream outputStream) throws IOException {
- if (null != (String)getSelectedRow(docTable).getAttribute("FilePath") &&
- !((String)getSelectedRow(docTable).getAttribute("FilePath")).isEmpty()) {
- File file = new File((String)getSelectedRow(docTable).getAttribute("FilePath"));
- downloadFile(outputStream, file);
- }
- }
- public void downloadFileListenerFromIterator(FacesContext facesContext,
- OutputStream outputStream) throws IOException {
- JUCtrlHierNodeBinding node = (JUCtrlHierNodeBinding)this.iteratorCurrentRow;
- Object filePath = node.getAttribute("FilePath");
- if (null != filePath && !((String)node.getAttribute("FilePath")).isEmpty()) {
- File file = new File((String)filePath);
- log.debug(" DOWNLOAD FILE called second ");
- downloadFile(outputStream, file);
- }
- }
- private void downloadFile(OutputStream outputStream, File file) throws java.io.IOException {
- FileInputStream fis = null;
- byte[] b;
- try {
- fis = new FileInputStream(file);
- int n;
- while ((n = fis.available()) > 0) {
- b = new byte[n];
- int result = fis.read(b);
- outputStream.write(b, 0, b.length);
- if (result == -1)
- break;
- }
- } catch (IOException e) {
- log.error(e.getMessage(), e);
- e.printStackTrace();
- } finally {
- fis.close();
- outputStream.flush();
- outputStream.close(); //close added recently
- }
- }
- // DOWNLOAD DOCUMENT SECTION END
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement