jdk/test/java/io/DataInputStream/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 DataInputStream 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(DataInputStream 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(DataInputStream 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(DataInputStream 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(DataInputStream 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(DataInputStream 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(DataInputStream 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(DataInputStream 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(DataInputStream 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(DataInputStream 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
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
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
            }},
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
        READ_BYTE { boolean check(DataInputStream is) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
                try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
                    is.readByte();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
                } catch (IOException io) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
                    System.out.print("Excep Msg: "+ io.getMessage() + ", ");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
                    return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
                return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
             } },
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
        READ_CHAR { boolean check(DataInputStream is) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
                try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
                    is.readChar();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
                } catch (IOException io) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
                    System.out.print("Excep Msg: "+ io.getMessage() + ", ");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
                    return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
                return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
             } },
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
        READ_DOUBLE { boolean check(DataInputStream is) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
                try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
                    is.readDouble();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
                } catch (IOException io) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
                    System.out.print("Excep Msg: "+ io.getMessage() + ", ");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
                    return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
                return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
             } },
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
        READ_FLOAT { boolean check(DataInputStream is) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
                try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
                    is.readFloat();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
                } catch (IOException io) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
                    System.out.print("Excep Msg: "+ io.getMessage() + ", ");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
                    return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
                return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
             } },
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
        READ_INT { boolean check(DataInputStream is) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
                try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
                    is.readInt();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
                } catch (IOException io) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
                    System.out.print("Excep Msg: "+ io.getMessage() + ", ");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
                    return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
                return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
             } },
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
        READ_LONG { boolean check(DataInputStream is) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
                try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
                    is.readLong();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
                } catch (IOException io) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
                    System.out.print("Excep Msg: "+ io.getMessage() + ", ");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
                    return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
                return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
             } },
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
        READ_SHORT { boolean check(DataInputStream is) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
                try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
                    is.readShort();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
                } catch (IOException io) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
                    System.out.print("Excep Msg: "+ io.getMessage() + ", ");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
                    return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
                return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
             } },
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
        READ_UnsignedByte { boolean check(DataInputStream is) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
                try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
                    is.readUnsignedByte();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
                } catch (IOException io) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
                    System.out.print("Excep Msg: "+ io.getMessage() + ", ");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
                    return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
                return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
             } },
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
        READ_UnsignedShort { boolean check(DataInputStream is) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
                try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
                    is.readUnsignedShort();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
                } catch (IOException io) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
                    System.out.print("Excep Msg: "+ io.getMessage() + ", ");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
                    return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
                return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
             } },
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
        READ_UTF { boolean check(DataInputStream is) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
                try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
                    is.readUTF();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
                } catch (IOException io) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
                    System.out.print("Excep Msg: "+ io.getMessage() + ", ");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
                    return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
                return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
             } },
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
        SKIP_BYTES { boolean check(DataInputStream is) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
                try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
                    is.skipBytes(1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
                } catch (IOException io) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
                    System.out.print("Excep Msg: "+ io.getMessage() + ", ");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
                    return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
                return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
             } },
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
        READ_FULLY { boolean check(DataInputStream is) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
                try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
                    is.readFully(new byte[1]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
                } catch (IOException io) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
                    System.out.print("Excep Msg: "+ io.getMessage() + ", ");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
                    return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
                return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
             } },
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
        READ_FULLY_BUF { boolean check(DataInputStream is) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
                try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
                    is.readFully(new byte[1], 0, 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
                } catch (IOException io) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
                    System.out.print("Excep Msg: "+ io.getMessage() + ", ");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
                    return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
                return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
             } };
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
    abstract boolean check(DataInputStream is);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
    public static void main(String args[]) throws Exception {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
        boolean failed = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
        File f = new File(System.getProperty("test.dir", "."),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
                          "f.txt");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
        f.createNewFile();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
        f.deleteOnExit();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
        FileInputStream fis = new FileInputStream(f);
5810
e83d67ad8c96 6962419: TEST_BUG: java_io tests fails in samevm mode
alanb
parents: 5506
diff changeset
   247
        try {
e83d67ad8c96 6962419: TEST_BUG: java_io tests fails in samevm mode
alanb
parents: 5506
diff changeset
   248
            DataInputStream dis = new DataInputStream(
e83d67ad8c96 6962419: TEST_BUG: java_io tests fails in samevm mode
alanb
parents: 5506
diff changeset
   249
                                    new FileInputStream(f));
e83d67ad8c96 6962419: TEST_BUG: java_io tests fails in samevm mode
alanb
parents: 5506
diff changeset
   250
            try {
e83d67ad8c96 6962419: TEST_BUG: java_io tests fails in samevm mode
alanb
parents: 5506
diff changeset
   251
                if (testDataInputStream(dis)) {
e83d67ad8c96 6962419: TEST_BUG: java_io tests fails in samevm mode
alanb
parents: 5506
diff changeset
   252
                    failed = true;
e83d67ad8c96 6962419: TEST_BUG: java_io tests fails in samevm mode
alanb
parents: 5506
diff changeset
   253
                }
e83d67ad8c96 6962419: TEST_BUG: java_io tests fails in samevm mode
alanb
parents: 5506
diff changeset
   254
            } finally {
e83d67ad8c96 6962419: TEST_BUG: java_io tests fails in samevm mode
alanb
parents: 5506
diff changeset
   255
                dis.close();
e83d67ad8c96 6962419: TEST_BUG: java_io tests fails in samevm mode
alanb
parents: 5506
diff changeset
   256
            }
e83d67ad8c96 6962419: TEST_BUG: java_io tests fails in samevm mode
alanb
parents: 5506
diff changeset
   257
        } finally {
e83d67ad8c96 6962419: TEST_BUG: java_io tests fails in samevm mode
alanb
parents: 5506
diff changeset
   258
            fis.close();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
    private static boolean testDataInputStream(DataInputStream is)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
            throws Exception {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
        is.close();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
        boolean failed = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
        boolean result;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
        System.out.println("Testing :" + is);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
        for (OpsAfterClose op : OpsAfterClose.values()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
            result = op.check(is);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
            if (!result) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
                failed = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
           System.out.println(op + ":" + result);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
        if (failed) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
            System.out.println("Test failed for the failed operation{s}" +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
                        " above for :" + is);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
        return failed;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
}