Skip to content

Commit 7092c65

Browse files
committed
Fix #134
1 parent c427465 commit 7092c65

File tree

4 files changed

+522
-8
lines changed

4 files changed

+522
-8
lines changed

csv/src/main/java/com/fasterxml/jackson/dataformat/csv/impl/CsvParserBootstrapper.java

+9-8
Original file line numberDiff line numberDiff line change
@@ -156,12 +156,14 @@ public CsvParser constructParser(int baseFeatures, int csvFeatures) throws IOExc
156156
throw new RuntimeException("Internal error"); // should never get here
157157
}
158158
_context.setEncoding(enc);
159+
final boolean autoClose = _context.isResourceManaged()
160+
|| JsonParser.Feature.AUTO_CLOSE_SOURCE.enabledIn(baseFeatures);
159161
return new CsvParser((CsvIOContext) _context, baseFeatures, csvFeatures, _codec,
160-
_createReader(enc));
162+
_createReader(enc, autoClose));
161163
}
162-
164+
163165
@SuppressWarnings("resource")
164-
private Reader _createReader(JsonEncoding enc) throws IOException
166+
private Reader _createReader(JsonEncoding enc, boolean autoClose) throws IOException
165167
{
166168
switch (enc) {
167169
case UTF32_BE:
@@ -178,9 +180,8 @@ private Reader _createReader(JsonEncoding enc) throws IOException
178180
if (in == null) {
179181
in = new ByteArrayInputStream(_inputBuffer, _inputPtr, _inputEnd);
180182
} else {
181-
/* Also, if we have any read but unused input (usually true),
182-
* need to merge that input in:
183-
*/
183+
// Also, if we have any read but unused input (usually true),
184+
// need to merge that input in:
184185
if (_inputPtr < _inputEnd) {
185186
in = new MergedStream(_context, in, _inputBuffer, _inputPtr, _inputEnd);
186187
}
@@ -189,7 +190,7 @@ private Reader _createReader(JsonEncoding enc) throws IOException
189190
}
190191
case UTF8:
191192
// Important: do not pass context, if we got byte[], nothing to release
192-
return new UTF8Reader((_in == null) ? null : _context, _in, _context.isResourceManaged(),
193+
return new UTF8Reader((_in == null) ? null : _context, _in, autoClose,
193194
_inputBuffer, _inputPtr, _inputEnd - _inputPtr);
194195
default:
195196
throw new RuntimeException();
@@ -287,7 +288,7 @@ private final static int skipSpace(InputAccessor acc, byte b) throws IOException
287288
*/
288289

289290
/**
290-
* @return True if a BOM was succesfully found, and encoding
291+
* @return True if a BOM was successfully found, and encoding
291292
* thereby recognized.
292293
*/
293294
private boolean handleBOM(int quad) throws IOException

0 commit comments

Comments
 (0)