@@ -156,12 +156,14 @@ public CsvParser constructParser(int baseFeatures, int csvFeatures) throws IOExc
156
156
throw new RuntimeException ("Internal error" ); // should never get here
157
157
}
158
158
_context .setEncoding (enc );
159
+ final boolean autoClose = _context .isResourceManaged ()
160
+ || JsonParser .Feature .AUTO_CLOSE_SOURCE .enabledIn (baseFeatures );
159
161
return new CsvParser ((CsvIOContext ) _context , baseFeatures , csvFeatures , _codec ,
160
- _createReader (enc ));
162
+ _createReader (enc , autoClose ));
161
163
}
162
-
164
+
163
165
@ SuppressWarnings ("resource" )
164
- private Reader _createReader (JsonEncoding enc ) throws IOException
166
+ private Reader _createReader (JsonEncoding enc , boolean autoClose ) throws IOException
165
167
{
166
168
switch (enc ) {
167
169
case UTF32_BE :
@@ -178,9 +180,8 @@ private Reader _createReader(JsonEncoding enc) throws IOException
178
180
if (in == null ) {
179
181
in = new ByteArrayInputStream (_inputBuffer , _inputPtr , _inputEnd );
180
182
} 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:
184
185
if (_inputPtr < _inputEnd ) {
185
186
in = new MergedStream (_context , in , _inputBuffer , _inputPtr , _inputEnd );
186
187
}
@@ -189,7 +190,7 @@ private Reader _createReader(JsonEncoding enc) throws IOException
189
190
}
190
191
case UTF8 :
191
192
// 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 ,
193
194
_inputBuffer , _inputPtr , _inputEnd - _inputPtr );
194
195
default :
195
196
throw new RuntimeException ();
@@ -287,7 +288,7 @@ private final static int skipSpace(InputAccessor acc, byte b) throws IOException
287
288
*/
288
289
289
290
/**
290
- * @return True if a BOM was succesfully found, and encoding
291
+ * @return True if a BOM was successfully found, and encoding
291
292
* thereby recognized.
292
293
*/
293
294
private boolean handleBOM (int quad ) throws IOException
0 commit comments