Path: blob/master/test/jdk/java/io/LineNumberInputStream/Available.java
41152 views
/*1* Copyright (c) 1997, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/2223/* @test24@bug 123894425@summary Check for correct implementation of LineNumberInputStream.available26*/2728import java.io.*;293031public class Available {3233static void check(int a, int bound) throws Exception {34if (a > bound) {35throw new Exception("Available returned " + a + " > " + bound);36}37}3839public static void main(String args[]) throws Exception {40LineNumberInputStream in = new LineNumberInputStream(new MyInStream());41check(in.available(), 5);42in.read();43in.read();44check(in.available(), 4);45in.read();46in.read();47in.read();48check(in.available(), 2);49}5051}525354class MyInStream extends InputStream {5556char[] buf = {'a', 'b', 'c', 'd', '\n',57'e', 'f', '\r', '\n', 'g'};58int ctr = 0;5960public int read() {61return ((ctr == 12) ? -1 : (int)buf[ctr++]);62}6364public int available() {65return (10 - ctr);66}6768}697071