Subversion Repositories SmartDukaan

Rev

Rev 4241 | Rev 9175 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 4241 Rev 4490
Line 81... Line 81...
81
    public void setAttachment(String attachment) {
81
    public void setAttachment(String attachment) {
82
        this.attachment = attachment;
82
        this.attachment = attachment;
83
    }
83
    }
84
    
84
    
85
    public void downloadAttachment() {
85
    public void downloadAttachment() {
86
        String fileName = CRMConstants.ATTACHMENTS_ARCHIVE_DIR + attachment;
-
 
87
        File file = new File(fileName);
-
 
88
        byte[] buffer = new byte[(int)file.length()];
86
        byte[] buffer = null;
89
        try {
87
        try {
-
 
88
            if (attachment == null || attachment.isEmpty()) {
-
 
89
                throw new Exception("File name is empty");
-
 
90
            }
-
 
91
            String fileName = CRMConstants.ATTACHMENTS_ARCHIVE_DIR + attachment;
-
 
92
            File file = new File(fileName);
-
 
93
            buffer = new byte[(int)file.length()];
90
            InputStream input = null;
94
            InputStream input = null;
91
            try {
95
            try {
92
                int totalBytesRead = 0;
96
                int totalBytesRead = 0;
93
                input = new BufferedInputStream(new FileInputStream(file));
97
                input = new BufferedInputStream(new FileInputStream(file));
94
                while(totalBytesRead < buffer.length){
98
                while(totalBytesRead < buffer.length){
Line 112... Line 116...
112
        catch (FileNotFoundException ex) {
116
        catch (FileNotFoundException ex) {
113
            System.out.println("FILE NOT FOUND : " + attachment);
117
            System.out.println("FILE NOT FOUND : " + attachment);
114
        }
118
        }
115
        catch (IOException ex) {
119
        catch (IOException ex) {
116
            System.out.println("FILE NOT FOUND : " + attachment);
120
            System.out.println("FILE NOT FOUND : " + attachment);
-
 
121
        } catch (Exception e) {
-
 
122
            System.out.println(e.getMessage());
117
        }
123
        }
118
        response.setHeader("Content-disposition", "inline; filename=" + attachment );
124
        response.setHeader("Content-disposition", "inline; filename=" + attachment );
119
 
125
 
120
        ServletOutputStream sos;
126
        ServletOutputStream sos;
121
        try {
127
        try {