23
23
import java .io .File ;
24
24
import java .io .FileInputStream ;
25
25
import java .io .IOException ;
26
+ import java .io .InputStream ;
26
27
import java .io .OutputStream ;
27
28
import java .net .URI ;
28
29
import java .util .StringTokenizer ;
37
38
import javax .ws .rs .core .Response ;
38
39
import javax .ws .rs .core .Response .Status ;
39
40
import javax .ws .rs .core .StreamingOutput ;
41
+ import javax .ws .rs .core .UriBuilderException ;
40
42
41
43
import org .silverpeas .attachment .AttachmentServiceFactory ;
42
44
import org .silverpeas .attachment .model .SimpleDocument ;
@@ -125,7 +127,11 @@ public ZipEntity zipFiles(@PathParam("ids") String attachmentIds) {
125
127
token ).path ("zipcontent" ).path (zipFile .getName ()).build ();
126
128
long size = ZipManager .compressPathToZip (folderToZip , zipFile );
127
129
return new ZipEntity (getUriInfo ().getRequestUri (), downloadUri .toString (), size );
128
- } catch (Exception e ) {
130
+ } catch (IllegalArgumentException e ) {
131
+ throw new WebApplicationException (Status .INTERNAL_SERVER_ERROR );
132
+ } catch (UriBuilderException e ) {
133
+ throw new WebApplicationException (Status .INTERNAL_SERVER_ERROR );
134
+ } catch (IOException e ) {
129
135
throw new WebApplicationException (Status .INTERNAL_SERVER_ERROR );
130
136
} finally {
131
137
FileUtils .deleteQuietly (folderToZip );
@@ -142,13 +148,19 @@ public Response getZipContent(@PathParam("name") String zipFileName) {
142
148
return Response .ok ().build ();
143
149
} else {
144
150
ByteArrayOutputStream output = new ByteArrayOutputStream ();
151
+ InputStream in = null ;
145
152
try {
146
- output .write (new FileInputStream (realFile ));
147
- } catch (Exception e ) {
153
+ in = new FileInputStream (realFile );
154
+ output .write (in );
155
+ return Response .ok ().entity (output .toByteArray ()).type (MimeTypes .SHORT_ARCHIVE_MIME_TYPE ).
156
+ build ();
157
+ } catch (IOException e ) {
148
158
throw new WebApplicationException (Status .INTERNAL_SERVER_ERROR );
159
+ } finally {
160
+ IOUtils .closeQuietly (in );
161
+ IOUtils .closeQuietly (output );
149
162
}
150
- return Response .ok ().entity (output .toByteArray ()).type (MimeTypes .SHORT_ARCHIVE_MIME_TYPE ).
151
- build ();
163
+
152
164
}
153
165
}
154
166
0 commit comments