/** * Method to use for accessing input for which format detection has been done. * This <b>must</b> be used instead of using stream passed to detector * unless given stream itself can do buffering. * Stream will return all content that was read during matching process, as well * as remaining contents of the underlying stream. */ public InputStream getDataStream() { if (_originalStream == null) { return new ByteArrayInputStream(_bufferedData, 0, _bufferedLength); } return new MergedStream(null, _originalStream, _bufferedData, 0, _bufferedLength); } }
@Override public void close() throws IOException { freeMergedBuffer(); _in.close(); }
@Override public int read(byte[] b) throws IOException { return read(b, 0, b.length); }
@Override public int read() throws IOException { if (_buffer != null) { int c = _buffer[_ptr++] & 0xFF; if (_ptr >= _end) { freeMergedBuffer(); } return c; } return _in.read(); }
public Reader constructReader() throws IOException { JsonEncoding enc = _context.getEncoding(); switch (enc) { case UTF32_BE: case UTF32_LE: return new UTF32Reader(_context, _in, _inputBuffer, _inputPtr, _inputEnd, _context.getEncoding().isBigEndian()); case UTF16_BE: case UTF16_LE: case UTF8: // only in non-common case where we don't want to do direct mapping { // First: do we have a Stream? If not, need to create one: InputStream in = _in; 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: */ if (_inputPtr < _inputEnd) { in = new MergedStream(_context, in, _inputBuffer, _inputPtr, _inputEnd); } } return new InputStreamReader(in, enc.getJavaName()); } } throw new RuntimeException("Internal error"); // should never get here }
@Override public int read(byte[] b) throws IOException { return read(b, 0, b.length); }
@Override public long skip(long n) throws IOException { long count = 0L; if (_buffer != null) { int amount = _end - _ptr; if (amount > n) { // all in pushed back segment? _ptr += (int) n; return n; } freeMergedBuffer(); count += amount; n -= amount; } if (n > 0) { count += _in.skip(n); } return count; }
/** * Method to use for accessing input for which format detection has been done. * This <b>must</b> be used instead of using stream passed to detector * unless given stream itself can do buffering. * Stream will return all content that was read during matching process, as well * as remaining contents of the underlying stream. */ public InputStream getDataStream() { if (_originalStream == null) { return new ByteArrayInputStream(_bufferedData, 0, _bufferedLength); } return new MergedStream(null, _originalStream, _bufferedData, 0, _bufferedLength); } }
@Override public int read(byte[] b) throws IOException { return read(b, 0, b.length); }
@Override public int read(byte[] b, int off, int len) throws IOException { if (_buffer != null) { int avail = _end - _ptr; if (len > avail) { len = avail; } System.arraycopy(_buffer, _ptr, b, off, len); _ptr += len; if (_ptr >= _end) { freeMergedBuffer(); } return len; } return _in.read(b, off, len); }
public Reader constructReader() throws IOException { JsonEncoding enc = _context.getEncoding(); switch (enc) { case UTF32_BE: case UTF32_LE: return new UTF32Reader(_context, _in, _inputBuffer, _inputPtr, _inputEnd, _context.getEncoding().isBigEndian()); case UTF16_BE: case UTF16_LE: case UTF8: // only in non-common case where we don't want to do direct mapping { // First: do we have a Stream? If not, need to create one: InputStream in = _in; 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: */ if (_inputPtr < _inputEnd) { in = new MergedStream(_context, in, _inputBuffer, _inputPtr, _inputEnd); } } return new InputStreamReader(in, enc.getJavaName()); } } throw new RuntimeException("Internal error"); // should never get here }
@Override public int read(byte[] b) throws IOException { return read(b, 0, b.length); }
@Override public int read() throws IOException { if (_buffer != null) { int c = _buffer[_ptr++] & 0xFF; if (_ptr >= _end) { freeMergedBuffer(); } return c; } return _in.read(); }
/** * Method to use for accessing input for which format detection has been done. * This <b>must</b> be used instead of using stream passed to detector * unless given stream itself can do buffering. * Stream will return all content that was read during matching process, as well * as remaining contents of the underlying stream. */ public InputStream getDataStream() { if (_originalStream == null) { return new ByteArrayInputStream(_bufferedData, 0, _bufferedLength); } return new MergedStream(null, _originalStream, _bufferedData, 0, _bufferedLength); } }
public int read(byte[] b) throws IOException { return read(b, 0, b.length); }
@Override public void close() throws IOException { freeMergedBuffer(); _in.close(); }
/** * Method to use for accessing input for which format detection has been done. * This <b>must</b> be used instead of using stream passed to detector * unless given stream itself can do buffering. * Stream will return all content that was read during matching process, as well * as remaining contents of the underlying stream. */ public InputStream getDataStream() { if (_originalStream == null) { return new ByteArrayInputStream(_bufferedData, 0, _bufferedLength); } return new MergedStream(null, _originalStream, _bufferedData, 0, _bufferedLength); } }
@Override public long skip(long n) throws IOException { long count = 0L; if (_buffer != null) { int amount = _end - _ptr; if (amount > n) { // all in pushed back segment? _ptr += (int) n; return n; } freeMergedBuffer(); count += amount; n -= amount; } if (n > 0) { count += _in.skip(n); } return count; }
in = new MergedStream(_context, in, _inputBuffer, _inputPtr, _inputEnd);
@Override public int read(byte[] b, int off, int len) throws IOException { if (_buffer != null) { int avail = _end - _ptr; if (len > avail) { len = avail; } System.arraycopy(_buffer, _ptr, b, off, len); _ptr += len; if (_ptr >= _end) { freeMergedBuffer(); } return len; } return _in.read(b, off, len); }