File tree Expand file tree Collapse file tree 1 file changed +11
-3
lines changed
marklogic-client-api/src/main/java/com/marklogic/client/io Expand file tree Collapse file tree 1 file changed +11
-3
lines changed Original file line number Diff line number Diff line change @@ -109,6 +109,9 @@ public InputStreamHandle(InputStream content) {
109109 */
110110 @ Override
111111 public InputStream get () {
112+ if (contentBytes != null ) {
113+ return new ByteArrayInputStream (contentBytes );
114+ }
112115 return content ;
113116 }
114117 /**
@@ -177,6 +180,7 @@ public void fromBuffer(byte[] buffer) {
177180 public byte [] toBuffer () {
178181 if (contentBytes == null && content != null ) {
179182 contentBytes = contentToBytes (get ());
183+ content = null ;
180184 }
181185 return contentBytes ;
182186 }
@@ -231,25 +235,29 @@ protected void receiveContent(InputStream content) {
231235 }
232236 @ Override
233237 protected InputStream sendContent () {
234- if (content == null ) {
238+ InputStream sendableContent = get ();
239+ if (sendableContent == null ) {
235240 throw new IllegalStateException ("No stream to write" );
236241 }
237242
238- return content ;
243+ return sendableContent ;
239244 }
240245
241246 /** Either call close() or get().close() when finished with this handle to close the underlying InputStream.
242247 */
243248 @ Override
244249 public void close () {
250+ if (contentBytes != null ) {
251+ contentBytes = null ;
252+ }
245253 if (content != null ) {
246254 try {
247255 content .close ();
248256 } catch (IOException e ) {
249257 logger .error ("Failed to close underlying InputStream" , e );
250258 throw new MarkLogicIOException (e );
251259 } finally {
252- set ( null , null ) ;
260+ content = null ;
253261 }
254262 }
255263 }
You can’t perform that action at this time.
0 commit comments