jdk/test/java/io/InputStream/OpsAfterClose.java
author ohair
Tue, 28 Dec 2010 15:53:50 -0800
changeset 7668 d4a77089c587
parent 5810 e83d67ad8c96
permissions -rw-r--r--
6962318: Update copyright year Reviewed-by: xdono
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
7668
d4a77089c587 6962318: Update copyright year
ohair
parents: 5810
diff changeset
     2
 * Copyright (c) 2006, 2010, Oracle and/or its affiliates. All rights reserved.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
90ce3da70b43 Initial load
duke
parents:
diff changeset
     7
 * published by the Free Software Foundation.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    21
 * questions.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    22
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    23
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
 *  @test
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
 *  @bug  4181483
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
 *  @summary Test if InputStream methods will check if the stream
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
 *          has been closed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
import java.io.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
public enum OpsAfterClose {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
        READ { boolean check(InputStream is) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
                    try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
                        int read = is.read();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
                        System.out.println("read returns: " + read);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
                    } catch (IOException io) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
                        System.out.print("Excep Msg: "+ io.getMessage() + ", ");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
                        return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
                    return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
             } },
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
        READ_BUF { boolean check(InputStream is) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
                    try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
                        byte buf[] = new byte[2];
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
                        int read = is.read(buf);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
                        System.out.println("read(buf) returns: " + read);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
                    } catch (IOException io) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
                        System.out.print("Excep Msg: "+ io.getMessage() + ", ");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
                        return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
                    return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
            } },
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
        READ_BUF_OFF { boolean check(InputStream is) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
                    try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
                        byte buf[] = new byte[2];
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
                        int len = 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
                        int read = is.read(buf, 0, len);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
                        System.out.println("read(buf, 0, len) returns: " + read);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
                    } catch (IOException io) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
                        System.out.print("Excep Msg: "+ io.getMessage() + ", ");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
                        return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
                    return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
             } },
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
        AVAILABLE { boolean check(InputStream is) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
                    try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
                        int avail = is.available();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
                        System.out.println("available() returns: " + avail);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
                        return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
                    } catch (IOException io) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
                        System.out.print("Excep Msg: "+ io.getMessage() + ", ");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
                        return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
             } },
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
        SKIP { boolean check(InputStream is) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
                    try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
                        long skipped = is.skip(1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
                        System.out.println("skip() returns: " + skipped);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
                    } catch (IOException io) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
                        System.out.print("Excep Msg: "+ io.getMessage() + ", ");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
                        return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
                    return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
             } },
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
        MARK { boolean check(InputStream is) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
                    is.mark(20);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
                    return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
             } },
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
        RESET { boolean check(InputStream is) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
                    try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
                        is.reset();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
                    } catch (IOException io) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
                        System.out.print("Excep Msg: "+ io.getMessage() + ", ");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
                        return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
                    return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
             } },
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
        MARK_SUPPORTED { boolean check(InputStream is) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
                    is.markSupported();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
                    return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
             } },
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
        CLOSE { boolean check(InputStream is) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
                try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
                    is.close();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
                    return true; // No Exception thrown on windows for FileInputStream
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
                } catch (IOException io) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
                    System.out.print("Excep Msg: "+ io.getMessage() + ", ");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
                    return true; // Exception thrown on solaris and linux for FileInputStream
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
             } };
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
    abstract boolean check(InputStream is);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
    public static void main(String args[]) throws Exception {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
        boolean failed = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
        File f = new File(System.getProperty("test.dir", "."),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
                          "f.txt");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
        f.createNewFile();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
        f.deleteOnExit();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
        FileInputStream fis = new FileInputStream(f);
5810
e83d67ad8c96 6962419: TEST_BUG: java_io tests fails in samevm mode
alanb
parents: 5506
diff changeset
   128
        try {
e83d67ad8c96 6962419: TEST_BUG: java_io tests fails in samevm mode
alanb
parents: 5506
diff changeset
   129
            if (testInputStream(fis)) {
e83d67ad8c96 6962419: TEST_BUG: java_io tests fails in samevm mode
alanb
parents: 5506
diff changeset
   130
                failed = true;
e83d67ad8c96 6962419: TEST_BUG: java_io tests fails in samevm mode
alanb
parents: 5506
diff changeset
   131
            }
e83d67ad8c96 6962419: TEST_BUG: java_io tests fails in samevm mode
alanb
parents: 5506
diff changeset
   132
            if (testFileInputStream(fis)) {
e83d67ad8c96 6962419: TEST_BUG: java_io tests fails in samevm mode
alanb
parents: 5506
diff changeset
   133
                failed = true;
e83d67ad8c96 6962419: TEST_BUG: java_io tests fails in samevm mode
alanb
parents: 5506
diff changeset
   134
            }
e83d67ad8c96 6962419: TEST_BUG: java_io tests fails in samevm mode
alanb
parents: 5506
diff changeset
   135
        } finally {
e83d67ad8c96 6962419: TEST_BUG: java_io tests fails in samevm mode
alanb
parents: 5506
diff changeset
   136
            fis.close();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
        BufferedInputStream bs =  new BufferedInputStream(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
                                        new FileInputStream(f));
5810
e83d67ad8c96 6962419: TEST_BUG: java_io tests fails in samevm mode
alanb
parents: 5506
diff changeset
   141
        try {
e83d67ad8c96 6962419: TEST_BUG: java_io tests fails in samevm mode
alanb
parents: 5506
diff changeset
   142
            if (testInputStream(bs)) {
e83d67ad8c96 6962419: TEST_BUG: java_io tests fails in samevm mode
alanb
parents: 5506
diff changeset
   143
                failed = true;
e83d67ad8c96 6962419: TEST_BUG: java_io tests fails in samevm mode
alanb
parents: 5506
diff changeset
   144
            }
e83d67ad8c96 6962419: TEST_BUG: java_io tests fails in samevm mode
alanb
parents: 5506
diff changeset
   145
        } finally {
e83d67ad8c96 6962419: TEST_BUG: java_io tests fails in samevm mode
alanb
parents: 5506
diff changeset
   146
            bs.close();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
        DataInputStream dis = new DataInputStream(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
                                new FileInputStream(f));
5810
e83d67ad8c96 6962419: TEST_BUG: java_io tests fails in samevm mode
alanb
parents: 5506
diff changeset
   151
        try {
e83d67ad8c96 6962419: TEST_BUG: java_io tests fails in samevm mode
alanb
parents: 5506
diff changeset
   152
            if (testInputStream(dis)) {
e83d67ad8c96 6962419: TEST_BUG: java_io tests fails in samevm mode
alanb
parents: 5506
diff changeset
   153
                failed = true;
e83d67ad8c96 6962419: TEST_BUG: java_io tests fails in samevm mode
alanb
parents: 5506
diff changeset
   154
            }
e83d67ad8c96 6962419: TEST_BUG: java_io tests fails in samevm mode
alanb
parents: 5506
diff changeset
   155
        } finally {
e83d67ad8c96 6962419: TEST_BUG: java_io tests fails in samevm mode
alanb
parents: 5506
diff changeset
   156
            dis.close();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
        PushbackInputStream pbis = new PushbackInputStream(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
                                new ByteArrayInputStream(new byte[20]));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
        if (testInputStream(pbis)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
            failed = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
        if (testPushbackInputStream(pbis)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
            failed = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
        PipedInputStream pis = new PipedInputStream(new PipedOutputStream());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
        if (testInputStream(pis)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
            failed = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
         * The SequenceInputStream and  ObjectInputStream does not throw IOException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
        SequenceInputStream sqis = new SequenceInputStream(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
                                        new FileInputStream(f),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
                                        new PipedInputStream(new PipedOutputStream())
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
                                    );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
        if (testInputStream(sqis)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
            failed = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
        String serStr = "abc";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
        ObjectOutputStream oos = new ObjectOutputStream(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
                                    new FileOutputStream(f));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
        oos.writeObject(serStr);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
        oos.close();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
        ObjectInputStream ois = new ObjectInputStream(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
                                    new FileInputStream(f));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
        if (testInputStream(ois)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
            failed = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
        */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
        if (failed) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
            throw new Exception(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
                "Some Op for some Stream failed, check the failed status above");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
    private static boolean testInputStream(InputStream is)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
            throws Exception {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
        is.close();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
        boolean failed = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
        boolean result;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
        System.out.println("Testing :" + is);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
        for (OpsAfterClose op : OpsAfterClose.values()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
            if (op.equals(AVAILABLE) && (is instanceof PipedInputStream)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
                // skip the test as available() returns 0
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
                continue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
            result = op.check(is);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
            if (!result) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
                failed = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
           System.out.println(op + ":" + result);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
        if (failed) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
            System.out.println("Test failed for the failed operation{s}" +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
                        " above for :" + is);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
        return failed;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
    private static boolean testPushbackInputStream(PushbackInputStream pis)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
                throws Exception {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
        boolean failed = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
            pis.unread(1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
            System.out.println("Test failed for unread(int):" + pis);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
            failed = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
        } catch (IOException io) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
           System.out.println("UNREAD(int):true");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
        byte buf[] = new byte[2];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
            pis.unread(buf, 0, 2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
            System.out.println("Test failed for unread(buf, offset, len):" +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
                                pis);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
            failed = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
        } catch (IOException io) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
           System.out.println("UNREAD(buf, offset, len):true");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
            pis.unread(buf);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
            System.out.println("Test failed for unread(char[] buf):" + pis);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
            failed = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
        } catch (IOException io) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
           System.out.println("UNREAD(buf):true");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
        return failed;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
    private static boolean testFileInputStream(FileInputStream fis)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
                throws Exception {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
        boolean failed = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
            fis.getFD();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
            System.out.println("GetFD: true");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
        } catch (IOException io) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
           System.out.println("GetFD: false");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
           failed = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
        fis.getChannel();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
        System.out.println("GetChannel: true");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
        return failed;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
}