src/java.base/share/classes/java/io/LineNumberInputStream.java
changeset 58242 94bb65cb37d3
parent 47216 71c04702a3d5
child 59201 b24f4caa1411
equal deleted inserted replaced
58241:33de7752835c 58242:94bb65cb37d3
     1 /*
     1 /*
     2  * Copyright (c) 1995, 2012, Oracle and/or its affiliates. All rights reserved.
     2  * Copyright (c) 1995, 2019, Oracle and/or its affiliates. All rights reserved.
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     4  *
     4  *
     5  * This code is free software; you can redistribute it and/or modify it
     5  * This code is free software; you can redistribute it and/or modify it
     6  * under the terms of the GNU General Public License version 2 only, as
     6  * under the terms of the GNU General Public License version 2 only, as
     7  * published by the Free Software Foundation.  Oracle designates this
     7  * published by the Free Software Foundation.  Oracle designates this
    81      * a carriage return followed by a newline character are both
    81      * a carriage return followed by a newline character are both
    82      * converted into a single newline character.
    82      * converted into a single newline character.
    83      *
    83      *
    84      * @return     the next byte of data, or {@code -1} if the end of this
    84      * @return     the next byte of data, or {@code -1} if the end of this
    85      *             stream is reached.
    85      *             stream is reached.
    86      * @exception  IOException  if an I/O error occurs.
    86      * @throws     IOException  if an I/O error occurs.
    87      * @see        java.io.FilterInputStream#in
    87      * @see        java.io.FilterInputStream#in
    88      * @see        java.io.LineNumberInputStream#getLineNumber()
    88      * @see        java.io.LineNumberInputStream#getLineNumber()
    89      */
    89      */
    90     @SuppressWarnings("fallthrough")
    90     @SuppressWarnings("fallthrough")
    91     public int read() throws IOException {
    91     public int read() throws IOException {
   122      * @param      off   the start offset of the data.
   122      * @param      off   the start offset of the data.
   123      * @param      len   the maximum number of bytes read.
   123      * @param      len   the maximum number of bytes read.
   124      * @return     the total number of bytes read into the buffer, or
   124      * @return     the total number of bytes read into the buffer, or
   125      *             {@code -1} if there is no more data because the end of
   125      *             {@code -1} if there is no more data because the end of
   126      *             this stream has been reached.
   126      *             this stream has been reached.
   127      * @exception  IOException  if an I/O error occurs.
   127      * @throws     IOException  if an I/O error occurs.
   128      * @see        java.io.LineNumberInputStream#read()
   128      * @see        java.io.LineNumberInputStream#read()
   129      */
   129      */
   130     public int read(byte b[], int off, int len) throws IOException {
   130     public int read(byte b[], int off, int len) throws IOException {
   131         if (b == null) {
   131         if (b == null) {
   132             throw new NullPointerException();
   132             throw new NullPointerException();
   171      * {@code n} bytes have been read or the end of the stream has
   171      * {@code n} bytes have been read or the end of the stream has
   172      * been reached.
   172      * been reached.
   173      *
   173      *
   174      * @param      n   the number of bytes to be skipped.
   174      * @param      n   the number of bytes to be skipped.
   175      * @return     the actual number of bytes skipped.
   175      * @return     the actual number of bytes skipped.
   176      * @exception  IOException  if an I/O error occurs.
   176      * @throws     IOException  if an I/O error occurs.
   177      * @see        java.io.FilterInputStream#in
   177      * @see        java.io.FilterInputStream#in
   178      */
   178      */
   179     public long skip(long n) throws IOException {
   179     public long skip(long n) throws IOException {
   180         int chunk = 2048;
   180         int chunk = 2048;
   181         long remaining = n;
   181         long remaining = n;
   232      * {@code '\u005Cn'}, which are converted to just
   232      * {@code '\u005Cn'}, which are converted to just
   233      * <i>k</i>/2 {@code '\u005Cn'} characters.
   233      * <i>k</i>/2 {@code '\u005Cn'} characters.
   234      *
   234      *
   235      * @return     the number of bytes that can be read from this input stream
   235      * @return     the number of bytes that can be read from this input stream
   236      *             without blocking.
   236      *             without blocking.
   237      * @exception  IOException  if an I/O error occurs.
   237      * @throws     IOException  if an I/O error occurs.
   238      * @see        java.io.FilterInputStream#in
   238      * @see        java.io.FilterInputStream#in
   239      */
   239      */
   240     public int available() throws IOException {
   240     public int available() throws IOException {
   241         return (pushBack == -1) ? super.available()/2 : super.available()/2 + 1;
   241         return (pushBack == -1) ? super.available()/2 : super.available()/2 + 1;
   242     }
   242     }
   279      * parser, it just chugs along happily. If the stream is not of
   279      * parser, it just chugs along happily. If the stream is not of
   280      * that type, the parser should toss an exception when it fails,
   280      * that type, the parser should toss an exception when it fails,
   281      * which, if it happens within readlimit bytes, allows the outer
   281      * which, if it happens within readlimit bytes, allows the outer
   282      * code to reset the stream and try another parser.
   282      * code to reset the stream and try another parser.
   283      *
   283      *
   284      * @exception  IOException  if an I/O error occurs.
   284      * @throws     IOException  if an I/O error occurs.
   285      * @see        java.io.FilterInputStream#in
   285      * @see        java.io.FilterInputStream#in
   286      * @see        java.io.LineNumberInputStream#mark(int)
   286      * @see        java.io.LineNumberInputStream#mark(int)
   287      */
   287      */
   288     public void reset() throws IOException {
   288     public void reset() throws IOException {
   289         lineNumber = markLineNumber;
   289         lineNumber = markLineNumber;