1
2
3
4
5
6
7
8
9
10 package org.eclipse.jgit.transport.http.apache;
11
12 import java.io.IOException;
13 import java.io.InputStream;
14 import java.io.OutputStream;
15
16 import org.apache.http.entity.AbstractHttpEntity;
17 import org.eclipse.jgit.util.TemporaryBuffer;
18
19
20
21
22
23
24
25 public class TemporaryBufferEntity extends AbstractHttpEntity
26 implements AutoCloseable {
27 private TemporaryBuffer buffer;
28
29 private Integer contentLength;
30
31
32
33
34
35
36
37 public TemporaryBufferEntity(TemporaryBuffer buffer) {
38 this.buffer = buffer;
39 }
40
41
42
43
44
45
46 public TemporaryBuffer getBuffer() {
47 return buffer;
48 }
49
50
51 @Override
52 public boolean isRepeatable() {
53 return true;
54 }
55
56
57 @Override
58 public long getContentLength() {
59 if (contentLength != null)
60 return contentLength.intValue();
61 return buffer.length();
62 }
63
64
65 @Override
66 public InputStream getContent() throws IOException, IllegalStateException {
67 return buffer.openInputStream();
68 }
69
70
71 @Override
72 public void writeTo(OutputStream outstream) throws IOException {
73
74 buffer.writeTo(outstream, null);
75 }
76
77
78 @Override
79 public boolean isStreaming() {
80 return false;
81 }
82
83
84
85
86
87
88 public void setContentLength(int contentLength) {
89 this.contentLength = Integer.valueOf(contentLength);
90 }
91
92
93
94
95
96
97
98 @Override
99 public void close() {
100 if (buffer != null) {
101 buffer.destroy();
102 }
103 }
104 }