@SuppressWarnings("resource") public Reader constructReader() throws IOException { JsonEncoding enc = _context.getEncoding(); switch (enc.bits()) { case 8: // only in non-common case where we don't want to do direct mapping case 16: { // 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()); } case 32: return new UTF32Reader(_context, _in, _inputBuffer, _inputPtr, _inputEnd, _context.getEncoding().isBigEndian()); } throw new RuntimeException("Internal error"); // should never get here }
if (count < 0) { // -1 if (_managedBuffers) { freeBuffers(); // to help GC? reportStrangeStream(); if (count < 0) { // -1, EOF... no good! if (_managedBuffers) { freeBuffers(); // to help GC? reportUnexpectedEOF(_length, 4); reportStrangeStream();
reportBounds(cbuf, start, len); if (!loadMore(left)) { // (legal) EOF? reportUnexpectedEOF(_length - _ptr, 4); int ch = ((hi - 1) << 16) | lo; // ch -= 0x10000; to normalize starting with 0x0 if (hi > 0x10) { // last valid is 0x10FFFF reportInvalid(ch, outPtr-start, String.format(" (above 0x%08x)", LAST_VALID_UNICODE_CHAR));
reportBounds(cbuf, start, len); if (!loadMore(left)) { // (legal) EOF? return -1; reportInvalid(ch, outPtr-start, "(above "+Integer.toHexString(LAST_VALID_UNICODE_CHAR)+") ");
@Override public void close() throws IOException { InputStream in = _in; if (in != null) { _in = null; freeBuffers(); in.close(); } }
/** * Although this method is implemented by the base class, AND it should * never be called by main code, let's still implement it bit more * efficiently just in case */ @Override public int read() throws IOException { if (_tmpBuf == null) { _tmpBuf = new char[1]; } if (read(_tmpBuf, 0, 1) < 1) { return -1; } return _tmpBuf[0]; }
reportBounds(cbuf, start, len); if (!loadMore(left)) { // (legal) EOF? return -1; reportInvalid(ch, outPtr-start, "(above "+Integer.toHexString(LAST_VALID_UNICODE_CHAR)+") ");
@Override public void close() throws IOException { InputStream in = _in; if (in != null) { _in = null; freeBuffers(); in.close(); } }
/** * Although this method is implemented by the base class, AND it should * never be called by main code, let's still implement it bit more * efficiently just in case */ @Override public int read() throws IOException { if (_tmpBuf == null) { _tmpBuf = new char[1]; } if (read(_tmpBuf, 0, 1) < 1) { return -1; } return _tmpBuf[0]; }
if (count < 0) { // -1 if (_managedBuffers) { freeBuffers(); // to help GC? reportStrangeStream(); if (count < 0) { // -1, EOF... no good! if (_managedBuffers) { freeBuffers(); // to help GC? reportUnexpectedEOF(_length, 4); reportStrangeStream();
reportBounds(cbuf, start, len); if (!loadMore(left)) { // (legal) EOF? reportUnexpectedEOF(_length - _ptr, 4); int ch = ((hi - 1) << 16) | lo; // ch -= 0x10000; to normalize starting with 0x0 if (hi > 0x10) { // last valid is 0x10FFFF reportInvalid(ch, outPtr-start, String.format(" (above 0x%08x)", LAST_VALID_UNICODE_CHAR));
reportBounds(cbuf, start, len); if (!loadMore(left)) { // (legal) EOF? return -1; reportInvalid(ch, outPtr-start, "(above "+Integer.toHexString(LAST_VALID_UNICODE_CHAR)+") ");
@SuppressWarnings("resource") public Reader constructReader() throws IOException { JsonEncoding enc = _context.getEncoding(); switch (enc.bits()) { case 8: // only in non-common case where we don't want to do direct mapping case 16: { // 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()); } case 32: return new UTF32Reader(_context, _in, _inputBuffer, _inputPtr, _inputEnd, _context.getEncoding().isBigEndian()); } throw new RuntimeException("Internal error"); // should never get here }
@Override public void close() throws IOException { InputStream in = _in; if (in != null) { _in = null; freeBuffers(); in.close(); } }
/** * Although this method is implemented by the base class, AND it should * never be called by main code, let's still implement it bit more * efficiently just in case */ @Override public int read() throws IOException { if (_tmpBuf == null) { _tmpBuf = new char[1]; } if (read(_tmpBuf, 0, 1) < 1) { return -1; } return _tmpBuf[0]; }
_length = 0; if (count < 0) { // -1 freeBuffers(); // to help GC? return false; reportStrangeStream(); if (count < 1) { if (count < 0) { // -1, EOF... no good! freeBuffers(); // to help GC? reportUnexpectedEOF(_length, 4); reportStrangeStream();
reportBounds(cbuf, start, len); if (!loadMore(left)) { // (legal) EOF? reportUnexpectedEOF(_length - _ptr, 4); int ch = ((hi - 1) << 16) | lo; // ch -= 0x10000; to normalize starting with 0x0 if (hi > 0x10) { // last valid is 0x10FFFF reportInvalid(ch, outPtr-start, String.format(" (above 0x%08x)", LAST_VALID_UNICODE_CHAR));
reportBounds(cbuf, start, len); if (!loadMore(left)) { // (legal) EOF? return -1; reportInvalid(ch, outPtr-start, "(above "+Integer.toHexString(LAST_VALID_UNICODE_CHAR)+") ");
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 void close() throws IOException { InputStream in = _in; if (in != null) { _in = null; freeBuffers(); in.close(); } }