Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
DeflateEncoding |
|
| 0.0;0 | ||||
DeflateEncoding$InflaterEntity |
|
| 0.0;0 |
1 | /* | |
2 | * Copyright 2003-2008 the original author or authors. | |
3 | * | |
4 | * Licensed under the Apache License, Version 2.0 (the "License"); | |
5 | * you may not use this file except in compliance with the License. | |
6 | * You may obtain a copy of the License at | |
7 | * | |
8 | * http://www.apache.org/licenses/LICENSE-2.0 | |
9 | * | |
10 | * Unless required by applicable law or agreed to in writing, software | |
11 | * distributed under the License is distributed on an "AS IS" BASIS, | |
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
13 | * See the License for the specific language governing permissions and | |
14 | * limitations under the License. | |
15 | * | |
16 | * You are receiving this code free of charge, which represents many hours of | |
17 | * effort from other individuals and corporations. As a responsible member | |
18 | * of the community, you are asked (but not required) to donate any | |
19 | * enhancements or improvements back to the community under a similar open | |
20 | * source license. Thank you. -TMN | |
21 | */ | |
22 | package groovyx.net.http; | |
23 | ||
24 | import static groovyx.net.http.ContentEncoding.Type.DEFLATE; | |
25 | ||
26 | import java.io.IOException; | |
27 | import java.io.InputStream; | |
28 | import java.util.zip.DeflaterInputStream; | |
29 | import java.util.zip.InflaterInputStream; | |
30 | ||
31 | import org.apache.http.HttpEntity; | |
32 | import org.apache.http.entity.HttpEntityWrapper; | |
33 | ||
34 | /** | |
35 | * Content encoding used to handle Deflate responses. | |
36 | * @author <a href='mailto:tnichols@enernoc.com'>Tom Nichols</a> | |
37 | */ | |
38 | 15 | public class DeflateEncoding extends ContentEncoding { |
39 | ||
40 | @Override | |
41 | public String getContentEncoding() { | |
42 | 30 | return DEFLATE.toString(); |
43 | } | |
44 | ||
45 | ||
46 | /** | |
47 | * Wraps the raw entity in a {@link InflaterEntity}. | |
48 | */ | |
49 | @Override | |
50 | public HttpEntity wrapResponseEntity( HttpEntity raw ) { | |
51 | 0 | return new InflaterEntity( raw ); |
52 | } | |
53 | ||
54 | /** | |
55 | * Entity used to interpret a Deflate-encoded response | |
56 | * @author <a href='mailto:tnichols@enernoc.com'>Tom Nichols</a> | |
57 | */ | |
58 | 15 | public static class InflaterEntity extends HttpEntityWrapper { |
59 | ||
60 | public InflaterEntity(final HttpEntity entity) { | |
61 | 0 | super(entity); |
62 | 0 | } |
63 | ||
64 | /** | |
65 | * returns a {@link DeflaterInputStream} which wraps the original entity's | |
66 | * content stream | |
67 | * @see HttpEntity#getContent() | |
68 | */ | |
69 | @Override | |
70 | public InputStream getContent() throws IOException, IllegalStateException { | |
71 | 0 | return new InflaterInputStream( wrappedEntity.getContent() ); |
72 | } | |
73 | ||
74 | /** | |
75 | * @return -1 | |
76 | */ | |
77 | @Override | |
78 | public long getContentLength() { | |
79 | // length of ungzipped content is not known | |
80 | 0 | return -1; |
81 | } | |
82 | } | |
83 | ||
84 | } |