Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
cowtowncoder committed Jun 1, 2019
1 parent c427465 commit 7092c65
Show file tree
Hide file tree
Showing 4 changed files with 522 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -156,12 +156,14 @@ public CsvParser constructParser(int baseFeatures, int csvFeatures) throws IOExc
throw new RuntimeException("Internal error"); // should never get here
}
_context.setEncoding(enc);
final boolean autoClose = _context.isResourceManaged()
|| JsonParser.Feature.AUTO_CLOSE_SOURCE.enabledIn(baseFeatures);
return new CsvParser((CsvIOContext) _context, baseFeatures, csvFeatures, _codec,
_createReader(enc));
_createReader(enc, autoClose));
}

@SuppressWarnings("resource")
private Reader _createReader(JsonEncoding enc) throws IOException
private Reader _createReader(JsonEncoding enc, boolean autoClose) throws IOException
{
switch (enc) {
case UTF32_BE:
Expand All @@ -178,9 +180,8 @@ private Reader _createReader(JsonEncoding enc) throws IOException
if (in == null) {
in = new ByteArrayInputStream(_inputBuffer, _inputPtr, _inputEnd);
} else {
/* Also, if we have any read but unused input (usually true),
* need to merge that input in:
*/
// Also, if we have any read but unused input (usually true),
// need to merge that input in:
if (_inputPtr < _inputEnd) {
in = new MergedStream(_context, in, _inputBuffer, _inputPtr, _inputEnd);
}
Expand All @@ -189,7 +190,7 @@ private Reader _createReader(JsonEncoding enc) throws IOException
}
case UTF8:
// Important: do not pass context, if we got byte[], nothing to release
return new UTF8Reader((_in == null) ? null : _context, _in, _context.isResourceManaged(),
return new UTF8Reader((_in == null) ? null : _context, _in, autoClose,
_inputBuffer, _inputPtr, _inputEnd - _inputPtr);
default:
throw new RuntimeException();
Expand Down Expand Up @@ -287,7 +288,7 @@ private final static int skipSpace(InputAccessor acc, byte b) throws IOException
*/

/**
* @return True if a BOM was succesfully found, and encoding
* @return True if a BOM was successfully found, and encoding
* thereby recognized.
*/
private boolean handleBOM(int quad) throws IOException
Expand Down
Loading

0 comments on commit 7092c65

Please sign in to comment.