Skip to content

Commit 60cd20e

Browse files
Charles Greersammefford
authored andcommitted
(merge 28f9395 plus minor modifications for this branch) issue #89 close input streams
1 parent 9653c13 commit 60cd20e

File tree

11 files changed

+195
-19
lines changed

11 files changed

+195
-19
lines changed

src/main/java/com/marklogic/client/example/handle/DOM4JHandle.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,14 @@ protected void receiveContent(InputStream content) {
149149
throw new MarkLogicIOException(e);
150150
} catch (DocumentException e) {
151151
throw new MarkLogicIOException(e);
152+
} finally {
153+
try {
154+
content.close();
155+
} catch (IOException e) {
156+
// ignore.
157+
}
152158
}
159+
153160
}
154161

155162
@Override

src/main/java/com/marklogic/client/example/handle/JDOMHandle.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,12 @@ protected void receiveContent(InputStream content) {
150150
throw new MarkLogicIOException(e);
151151
} catch (IOException e) {
152152
throw new MarkLogicIOException(e);
153+
} finally {
154+
try {
155+
content.close();
156+
} catch (IOException e) {
157+
// ignore.
158+
}
153159
}
154160
}
155161

src/main/java/com/marklogic/client/example/handle/JacksonHandle.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,12 @@ protected void receiveContent(InputStream content) {
137137
throw new MarkLogicIOException(e);
138138
} catch (IOException e) {
139139
throw new MarkLogicIOException(e);
140+
} finally {
141+
try {
142+
content.close();
143+
} catch (IOException e) {
144+
// ignore.
145+
}
140146
}
141147

142148
}

src/main/java/com/marklogic/client/example/handle/XOMHandle.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,12 @@ protected void receiveContent(InputStream content) {
142142
throw new MarkLogicIOException(e);
143143
} catch (IOException e) {
144144
throw new MarkLogicIOException(e);
145+
} finally {
146+
try {
147+
content.close();
148+
} catch (IOException e) {
149+
// ignore.
150+
}
145151
}
146152
}
147153

src/main/java/com/marklogic/client/io/DOMHandle.java

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -225,13 +225,16 @@ protected void receiveContent(InputStream content) {
225225
domInput.setByteStream(content);
226226

227227
this.content = parser.parse(domInput);
228-
content.close();
229-
} catch (IOException e) {
230-
logger.error("Failed to parse DOM document from input stream",e);
231-
throw new MarkLogicInternalException(e);
232228
} catch (ParserConfigurationException e) {
233229
logger.error("Failed to parse DOM document from input stream",e);
234230
throw new MarkLogicInternalException(e);
231+
} finally {
232+
try {
233+
content.close();
234+
} catch (IOException e) {
235+
//ignore
236+
}
237+
235238
}
236239
}
237240
@Override

src/main/java/com/marklogic/client/io/JAXBHandle.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,12 @@ protected void receiveContent(InputStream content) {
170170
} catch (UnsupportedEncodingException e) {
171171
logger.error("Failed to unmarshall object read from database document",e);
172172
throw new MarkLogicIOException(e);
173+
} finally {
174+
try {
175+
content.close();
176+
} catch (IOException e) {
177+
// ignore.
178+
}
173179
}
174180
}
175181
@Override

src/main/java/com/marklogic/client/io/QueryOptionsHandle.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1037,7 +1037,13 @@ protected void receiveContent(InputStream content) {
10371037
} catch (UnsupportedEncodingException e) {
10381038
// This can't actually happen...stupid checked exceptions
10391039
throw new MarkLogicBindingException(e);
1040-
}
1040+
} finally {
1041+
try {
1042+
content.close();
1043+
} catch (IOException e) {
1044+
// ignore.
1045+
}
1046+
}
10411047
}
10421048

10431049
protected OutputStreamSender sendContent() {

src/main/java/com/marklogic/client/io/TuplesHandle.java

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
*/
1616
package com.marklogic.client.io;
1717

18+
import java.io.IOException;
1819
import java.io.InputStream;
1920
import java.io.InputStreamReader;
2021
import java.io.UnsupportedEncodingException;
@@ -24,19 +25,19 @@
2425
import javax.xml.bind.JAXBException;
2526
import javax.xml.bind.Unmarshaller;
2627

27-
import com.marklogic.client.query.AggregateResult;
28-
import com.marklogic.client.query.ValuesMetrics;
2928
import org.slf4j.Logger;
3029
import org.slf4j.LoggerFactory;
3130

3231
import com.marklogic.client.MarkLogicBindingException;
3332
import com.marklogic.client.MarkLogicIOException;
34-
import com.marklogic.client.query.Tuple;
3533
import com.marklogic.client.impl.TuplesBuilder;
36-
import com.marklogic.client.query.TuplesResults;
37-
import com.marklogic.client.query.ValuesDefinition;
3834
import com.marklogic.client.io.marker.OperationNotSupported;
3935
import com.marklogic.client.io.marker.TuplesReadHandle;
36+
import com.marklogic.client.query.AggregateResult;
37+
import com.marklogic.client.query.Tuple;
38+
import com.marklogic.client.query.TuplesResults;
39+
import com.marklogic.client.query.ValuesDefinition;
40+
import com.marklogic.client.query.ValuesMetrics;
4041

4142
/**
4243
* A TuplesHandle represents a set of tuples returned by a query on the server.
@@ -109,7 +110,13 @@ protected void receiveContent(InputStream content) {
109110
} catch (JAXBException e) {
110111
logger.error("Failed to unmarshall tuples",e);
111112
throw new MarkLogicIOException(e);
112-
}
113+
} finally {
114+
try {
115+
content.close();
116+
} catch (IOException e) {
117+
// ignore.
118+
}
119+
}
113120
}
114121

115122
/**

src/main/java/com/marklogic/client/io/ValuesHandle.java

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
*/
1616
package com.marklogic.client.io;
1717

18+
import java.io.IOException;
1819
import java.io.InputStream;
1920
import java.io.InputStreamReader;
2021
import java.io.UnsupportedEncodingException;
@@ -24,19 +25,19 @@
2425
import javax.xml.bind.JAXBException;
2526
import javax.xml.bind.Unmarshaller;
2627

27-
import com.marklogic.client.query.AggregateResult;
28-
import com.marklogic.client.query.ValuesMetrics;
2928
import org.slf4j.Logger;
3029
import org.slf4j.LoggerFactory;
3130

3231
import com.marklogic.client.MarkLogicBindingException;
3332
import com.marklogic.client.MarkLogicIOException;
34-
import com.marklogic.client.query.CountedDistinctValue;
3533
import com.marklogic.client.impl.ValuesBuilder;
36-
import com.marklogic.client.query.ValuesDefinition;
37-
import com.marklogic.client.query.ValuesResults;
3834
import com.marklogic.client.io.marker.OperationNotSupported;
3935
import com.marklogic.client.io.marker.ValuesReadHandle;
36+
import com.marklogic.client.query.AggregateResult;
37+
import com.marklogic.client.query.CountedDistinctValue;
38+
import com.marklogic.client.query.ValuesDefinition;
39+
import com.marklogic.client.query.ValuesMetrics;
40+
import com.marklogic.client.query.ValuesResults;
4041

4142
/**
4243
* A ValuesHandle represents a list of values or of tuples
@@ -114,7 +115,13 @@ protected void receiveContent(InputStream content) {
114115
} catch (JAXBException e) {
115116
logger.error("Failed to unmarshall values",e);
116117
throw new MarkLogicIOException(e);
117-
}
118+
} finally {
119+
try {
120+
content.close();
121+
} catch (IOException e) {
122+
// ignore.
123+
}
124+
}
118125
}
119126

120127
/**

src/main/java/com/marklogic/client/io/ValuesListHandle.java

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
*/
1616
package com.marklogic.client.io;
1717

18+
import java.io.IOException;
1819
import java.io.InputStream;
1920
import java.io.InputStreamReader;
2021
import java.io.UnsupportedEncodingException;
@@ -30,9 +31,9 @@
3031
import com.marklogic.client.MarkLogicBindingException;
3132
import com.marklogic.client.MarkLogicIOException;
3233
import com.marklogic.client.impl.ValuesListBuilder;
33-
import com.marklogic.client.query.ValuesListResults;
3434
import com.marklogic.client.io.marker.OperationNotSupported;
3535
import com.marklogic.client.io.marker.ValuesListReadHandle;
36+
import com.marklogic.client.query.ValuesListResults;
3637

3738
public class ValuesListHandle
3839
extends BaseHandle<InputStream, OperationNotSupported>
@@ -123,7 +124,14 @@ protected void receiveContent(InputStream content) {
123124
} catch (JAXBException e) {
124125
logger.error("Failed to unmarshall values list",e);
125126
throw new MarkLogicIOException(e);
126-
}
127+
} finally {
128+
try {
129+
content.close();
130+
} catch (IOException e) {
131+
// ignore.
132+
}
133+
}
134+
127135
}
128136

129137
/**

0 commit comments

Comments
 (0)