ReadZero.java revision 3261:a06412e13bf7
190075Sobrien/* 2110611Skan * Copyright (c) 2008, 2010, Oracle and/or its affiliates. All rights reserved. 390075Sobrien * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 490075Sobrien * 590075Sobrien * This code is free software; you can redistribute it and/or modify it 690075Sobrien * under the terms of the GNU General Public License version 2 only, as 790075Sobrien * published by the Free Software Foundation. 890075Sobrien * 990075Sobrien * This code is distributed in the hope that it will be useful, but WITHOUT 1090075Sobrien * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 1190075Sobrien * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 1290075Sobrien * version 2 for more details (a copy is included in the LICENSE file that 1390075Sobrien * accompanied this code). 1490075Sobrien * 1590075Sobrien * You should have received a copy of the GNU General Public License version 1690075Sobrien * 2 along with this work; if not, write to the Free Software Foundation, 1790075Sobrien * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 1890075Sobrien * 1990075Sobrien * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 2090075Sobrien * or visit www.oracle.com if you need additional information or have any 2190075Sobrien * questions. 2290075Sobrien */ 2390075Sobrien 2490075Sobrien/* @test 2590075Sobrien * @summary Verify that if InputStream.read returns 0 we throw an exception. 2690075Sobrien * @bug 4684515 2790075Sobrien */ 2890075Sobrien 2990075Sobrienimport java.io.*; 3090075Sobrien 3190075Sobrienpublic class ReadZero { 3290075Sobrien 3390075Sobrien public static void main(String [] args) throws IOException { 3490075Sobrien ReadZero r = new ReadZero(); 3590075Sobrien r.testInputStream(); 3690075Sobrien } 3790075Sobrien 3890075Sobrien private void testInputStream() throws IOException { 3990075Sobrien File f = new File(System.getProperty("test.src", "."), "ReadZero.java"); 4090075Sobrien InputStream is = new FileInputStream(f) { 4190075Sobrien public int read(byte [] b, int off, int len) { 4290075Sobrien System.out.println("FileInputStream.read"); 4390075Sobrien return 0; 4490075Sobrien } 4590075Sobrien }; 4690075Sobrien try { 4790075Sobrien is.read(new byte[1], 0, 1); // ok 4890075Sobrien InputStreamReader isr = new InputStreamReader(is); 4990075Sobrien 5090075Sobrien try { 5190075Sobrien int res = isr.read(new char[1], 0, 1); 5290075Sobrien } catch (IOException x) { 5390075Sobrien System.out.println("IOException caught"); 5490075Sobrien return; 5590075Sobrien } 5690075Sobrien } finally { 5790075Sobrien is.close(); 5890075Sobrien } 5990075Sobrien throw new RuntimeException("IOException not thrown"); 6090075Sobrien } 6190075Sobrien} 6290075Sobrien