File tree 4 files changed +38
-5
lines changed
src/main/java/com/ning/http/client/providers/netty 4 files changed +38
-5
lines changed Original file line number Diff line number Diff line change
1
+ /*
2
+ * Copyright 2010 Ning, Inc.
3
+ *
4
+ * Ning licenses this file to you under the Apache License, version 2.0
5
+ * (the "License"); you may not use this file except in compliance with the
6
+ * License. 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, WITHOUT
12
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13
+ * License for the specific language governing permissions and limitations
14
+ * under the License.
15
+ */
16
+ package com .ning .http .client .providers .netty ;
17
+
18
+ import org .jboss .netty .buffer .ChannelBuffer ;
19
+
20
+ public class ChannelBufferUtil {
21
+
22
+ public static byte [] channelBuffer2bytes (ChannelBuffer b ) {
23
+ int readable = b .readableBytes ();
24
+ int readerIndex = b .readerIndex ();
25
+ if (b .hasArray ()) {
26
+ byte [] array = b .array ();
27
+ if (b .arrayOffset () == 0 && readerIndex == 0 && array .length == readable ) {
28
+ return array ;
29
+ }
30
+ }
31
+ byte [] array = new byte [readable ];
32
+ b .getBytes (readerIndex , array );
33
+ return array ;
34
+ }
35
+ }
Original file line number Diff line number Diff line change @@ -76,7 +76,7 @@ public String getStatusText() {
76
76
77
77
/* @Override */
78
78
public byte [] getResponseBodyAsBytes () throws IOException {
79
- return getResponseBodyAsByteBuffer (). array ( );
79
+ return ChannelBufferUtil . channelBuffer2bytes ( getResponseBodyAsChannelBuffer () );
80
80
}
81
81
82
82
public ByteBuffer getResponseBodyAsByteBuffer () throws IOException {
Original file line number Diff line number Diff line change @@ -34,7 +34,7 @@ public class ResponseBodyPart extends HttpResponseBodyPart {
34
34
35
35
private final HttpChunk chunk ;
36
36
private final HttpResponse response ;
37
- private final AtomicReference <byte []> bytes = new AtomicReference (null );
37
+ private final AtomicReference <byte []> bytes = new AtomicReference < byte []> (null );
38
38
private final boolean isLast ;
39
39
private boolean closeConnection = false ;
40
40
@@ -63,8 +63,7 @@ public byte[] getBodyPartBytes() {
63
63
return bytes .get ();
64
64
}
65
65
66
- ChannelBuffer b = getChannelBuffer ();
67
- byte [] rb = b .toByteBuffer ().array ();
66
+ byte [] rb = ChannelBufferUtil .channelBuffer2bytes (getChannelBuffer ());
68
67
bytes .set (rb );
69
68
return rb ;
70
69
}
Original file line number Diff line number Diff line change 13
13
package com .ning .http .client .providers .netty ;
14
14
15
15
import com .ning .http .util .Base64 ;
16
- import org .jboss .netty .util .CharsetUtil ;
17
16
18
17
import java .io .UnsupportedEncodingException ;
19
18
import java .security .MessageDigest ;
You can’t perform that action at this time.
0 commit comments