5503N/A/*
5503N/A * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved.
5503N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5503N/A *
5503N/A * This code is free software; you can redistribute it and/or modify it
5503N/A * under the terms of the GNU General Public License version 2 only, as
5503N/A * published by the Free Software Foundation.
5503N/A *
5503N/A * This code is distributed in the hope that it will be useful, but WITHOUT
5503N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
5503N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
5503N/A * version 2 for more details (a copy is included in the LICENSE file that
5503N/A * accompanied this code).
5503N/A *
5503N/A * You should have received a copy of the GNU General Public License version
5503N/A * 2 along with this work; if not, write to the Free Software Foundation,
5503N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
5503N/A *
5503N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
5503N/A * or visit www.oracle.com if you need additional information or have any
5503N/A * questions.
5503N/A */
5503N/A
5503N/Aimport java.io.File;
5503N/Aimport java.io.FileInputStream;
5503N/Aimport java.io.FileNotFoundException;
5503N/Aimport java.io.FileOutputStream;
5503N/Aimport java.io.IOException;
5503N/Aimport java.io.RandomAccessFile;
5503N/A
5503N/A/*
5503N/A * @test
5503N/A * @bug 8003322
5503N/A * @run shell ioTraceTest.sh IoTraceFileReadWrite
5503N/A */
5503N/Apublic class IoTraceFileReadWrite extends IoTraceBase {
5503N/A
5503N/A private void testWrite(File f) throws IOException, FileNotFoundException,
5503N/A Exception {
5503N/A try (FileOutputStream fos = new FileOutputStream(f)) {
5503N/A fos.write(11);
5503N/A }
5503N/A expectFile(1, 0, f);
5503N/A }
5503N/A
5503N/A
5503N/A private void testRead(File f) throws IOException, FileNotFoundException,
5503N/A Exception {
5503N/A try (FileInputStream fos = new FileInputStream(f)) {
5503N/A fos.read();
5503N/A }
5503N/A expectFile(0, 1, f);
5503N/A }
5503N/A
5503N/A private void testRandomAccessWrite(File f) throws Exception {
5503N/A try (RandomAccessFile raf = new RandomAccessFile(f, "rw")) {
5503N/A raf.write(11);
5503N/A }
5503N/A expectFile(1, 0, f);
5503N/A }
5503N/A
5503N/A private void testRandomAccessRead(File f) throws Exception {
5503N/A try (RandomAccessFile raf = new RandomAccessFile(f, "r")) {
5503N/A raf.read();
5503N/A }
5503N/A expectFile(0, 1, f);
5503N/A }
5503N/A
5503N/A public void test() throws Exception {
5503N/A IoTraceAgent.setListener(this);
5503N/A File f = File.createTempFile("IoTraceFileReadWrite", ".bin");
5503N/A try {
5503N/A clear();
5503N/A testWrite(f);
5503N/A clear();
5503N/A testRead(f);
5503N/A clear();
5503N/A testRandomAccessWrite(f);
5503N/A clear();
5503N/A testRandomAccessRead(f);
5503N/A } finally {
5503N/A f.delete();
5503N/A }
5503N/A }
5503N/A
5503N/A public static void main(String... args) throws Exception {
5503N/A IoTraceFileReadWrite t = new IoTraceFileReadWrite();
5503N/A t.test();
5503N/A }
5503N/A}