0N/A/*
2362N/A * Copyright (c) 1997, Oracle and/or its affiliates. All rights reserved.
0N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
0N/A *
0N/A * This code is free software; you can redistribute it and/or modify it
0N/A * under the terms of the GNU General Public License version 2 only, as
0N/A * published by the Free Software Foundation.
0N/A *
0N/A * This code is distributed in the hope that it will be useful, but WITHOUT
0N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
0N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
0N/A * version 2 for more details (a copy is included in the LICENSE file that
0N/A * accompanied this code).
0N/A *
0N/A * You should have received a copy of the GNU General Public License version
0N/A * 2 along with this work; if not, write to the Free Software Foundation,
0N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
0N/A *
2362N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
2362N/A * or visit www.oracle.com if you need additional information or have any
2362N/A * questions.
0N/A */
0N/A
0N/A
0N/A/* @test
0N/A @bug 4016710
0N/A @summary check for correct implementation of InputStream.skip
0N/A */
0N/A
0N/Aimport java.io.*;
0N/A
0N/A
0N/Apublic class Skip{
0N/A
0N/A private static void dotest(InputStream in , int curpos ,
0N/A long total , long toskip , long expected)
0N/A throws Exception
0N/A {
0N/A
0N/A try {
0N/A
0N/A System.err.println("\n\nCurrently at pos = " + curpos +
0N/A "\nTotal bytes in the Stream = " + total +
0N/A "\nNumber of bytes to skip = " + toskip +
0N/A "\nNumber of bytes that should be skipped = " +
0N/A expected);
0N/A
0N/A long skipped = in.skip(toskip);
0N/A
0N/A System.err.println("actual number skipped: "+ skipped);
0N/A
0N/A if ((skipped < 0) || (skipped > expected)) {
0N/A throw new RuntimeException("Unexpected number of bytes skipped");
0N/A }
0N/A
0N/A } catch (IOException e) {
0N/A System.err.println("IOException is thrown - possible result");
0N/A } catch (Throwable e) {
0N/A throw new RuntimeException("Unexpected "+e+" is thrown!");
0N/A }
0N/A
0N/A }
0N/A
0N/A public static void main( String argv[] ) throws Exception {
0N/A
0N/A MyInputStream in = new MyInputStream(11);
0N/A
0N/A /* test for negative skip */
0N/A dotest(in, 0, 11, -23, 0);
0N/A
0N/A /* check for skip beyond EOF starting from before EOF */
0N/A dotest(in, 0, 11, 20, 11);
0N/A
0N/A /* check for skip after EOF */
0N/A dotest(in, -1, 11, 20, 0);
0N/A
0N/A in = new MyInputStream(9000);
0N/A /* check for skip equal to the read chunk size in InputStream.java */
0N/A dotest(in, 0, 9000, 2048, 2048);
0N/A
0N/A /* check for skip greater than the read chunk size in InputStream.java */
0N/A dotest(in, 2048, 9000, 5000, 5000);
0N/A
0N/A /* check for skip beyond EOF starting from before EOF */
0N/A dotest(in, 7048, 9000, 5000, 1952);
0N/A
0N/A in = new MyInputStream(5000);
0N/A
0N/A /* check for multiple chunk reads */
0N/A dotest(in, 0, 5000, 6000, 5000);
0N/A
0N/A /*
0N/A * check for skip larger than Integer.MAX_VALUE
0N/A * (Takes about 2 hrs on a sparc ultra-1)
0N/A * long total = (long)Integer.MAX_VALUE + (long)10;
0N/A * long toskip = total - (long)6;
0N/A * in = new MyInputStream(total);
0N/A * dotest(in, 0, total, toskip, toskip);
0N/A */
0N/A
0N/A }
0N/A
0N/A}
0N/A
0N/Aclass MyInputStream extends InputStream {
0N/A
0N/A private int readctr = 0;
0N/A private long endoffile;
0N/A
0N/A public MyInputStream(long endoffile) {
0N/A this.endoffile = endoffile;
0N/A }
0N/A
0N/A public int read() {
0N/A
0N/A if (readctr == endoffile) {
0N/A return -1;
0N/A }
0N/A else {
0N/A readctr++;
0N/A return 0;
0N/A }
0N/A }
0N/A
0N/A public int available() { return 0; }
0N/A}