-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathZipEncoder.java
More file actions
34 lines (29 loc) · 962 Bytes
/
ZipEncoder.java
File metadata and controls
34 lines (29 loc) · 962 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
package org.javaee7.chapter08;
import java.io.IOException;
import java.util.zip.ZipEntry;
import java.util.zip.ZipException;
import java.util.zip.ZipOutputStream;
import javax.ws.rs.WebApplicationException;
import javax.ws.rs.ext.Provider;
import javax.ws.rs.ext.WriterInterceptor;
import javax.ws.rs.ext.WriterInterceptorContext;
/**
*
* @author Juneau
*/
// Uncomment to see the Zip Encoder in action
//@Provider
public class ZipEncoder implements WriterInterceptor {
public void aroundWriteTo(WriterInterceptorContext ctx) throws IOException, WebApplicationException {
ZipOutputStream zip = new ZipOutputStream(ctx.getOutputStream());
try {
zip.putNextEntry(new ZipEntry("Test Entry"));
ctx.setOutputStream(zip);
ctx.proceed();
} catch (ZipException ex){
System.out.println("ZipEncoder ERROR: " + ex);
} finally {
zip.finish();
}
}
}