1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.springframework.http.client;
18
19 import java.io.ByteArrayOutputStream;
20 import java.io.IOException;
21 import java.io.OutputStream;
22
23 import org.springframework.http.HttpHeaders;
24
25
26
27
28
29
30
31
32 abstract class AbstractBufferingClientHttpRequest extends AbstractClientHttpRequest {
33
34 private ByteArrayOutputStream bufferedOutput = new ByteArrayOutputStream(1024);
35
36
37 @Override
38 protected OutputStream getBodyInternal(HttpHeaders headers) throws IOException {
39 return this.bufferedOutput;
40 }
41
42 @Override
43 protected ClientHttpResponse executeInternal(HttpHeaders headers) throws IOException {
44 byte[] bytes = this.bufferedOutput.toByteArray();
45 if (headers.getContentLength() == -1) {
46 headers.setContentLength(bytes.length);
47 }
48 ClientHttpResponse result = executeInternal(headers, bytes);
49 this.bufferedOutput = null;
50 return result;
51 }
52
53
54
55
56
57
58
59 protected abstract ClientHttpResponse executeInternal(HttpHeaders headers, byte[] bufferedOutput)
60 throws IOException;
61
62
63 }