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.net.InetAddress;
5503N/A
5503N/A
5503N/Apublic class IoTraceBase implements IoTraceListener {
5503N/A
5503N/A protected static final Object my_context = new Object() {
5503N/A };
5503N/A
5503N/A private String path;
5503N/A private long bytesRead;
5503N/A private long bytesWritten;
5503N/A private Object context;
5503N/A private InetAddress address;
5503N/A private int port;
5503N/A private int timeout;
5503N/A
5503N/A protected void clear() {
5503N/A context = null;
5503N/A bytesRead = 0;
5503N/A bytesWritten = 0;
5503N/A address = null;
5503N/A port = 0;
5503N/A timeout = 0;
5503N/A path = null;
5503N/A }
5503N/A
5503N/A @Override
5503N/A public Object fileWriteBegin(String p) {
5503N/A path = p;
5503N/A return my_context;
5503N/A }
5503N/A
5503N/A @Override
5503N/A public void fileWriteEnd(Object ctx, long bw) {
5503N/A context = ctx;
5503N/A bytesWritten = bw;
5503N/A }
5503N/A
5503N/A @Override
5503N/A public Object fileReadBegin(String p) {
5503N/A path = p;
5503N/A return my_context;
5503N/A }
5503N/A
5503N/A @Override
5503N/A public void fileReadEnd(Object ctx, long br) {
5503N/A context = ctx;
5503N/A bytesRead = br;
5503N/A }
5503N/A
5503N/A @Override
5766N/A public Object socketReadBegin() {
5503N/A return my_context;
5503N/A }
5503N/A
5503N/A @Override
5766N/A public void socketReadEnd(Object context, InetAddress address, int port,
5766N/A int timeout, long bytesRead) {
5503N/A this.context = context;
5766N/A this.address = address;
5766N/A this.port = port;
5766N/A this.timeout = timeout;
5503N/A this.bytesRead = bytesRead;
5503N/A }
5503N/A
5503N/A @Override
5766N/A public Object socketWriteBegin() {
5503N/A return my_context;
5503N/A }
5503N/A
5503N/A @Override
5766N/A public void socketWriteEnd(Object context, InetAddress address, int port,
5766N/A long bytesWritten) {
5503N/A this.context = context;
5766N/A this.address = address;
5766N/A this.port = port;
5503N/A this.bytesWritten = bytesWritten;
5503N/A }
5503N/A
5503N/A protected void expectFileRead(long br, File f) throws Exception {
5503N/A expectFile(0, br, f);
5503N/A }
5503N/A
5503N/A protected void expectFileWrite(long bw, File f) throws Exception {
5503N/A expectFile(bw, 0, f);
5503N/A }
5503N/A
5503N/A protected void expectFile(long bw, long br, File f) throws Exception {
5503N/A if (context != my_context) {
5503N/A throw new Exception("Wrong context: " + context);
5503N/A }
5503N/A if (bytesWritten != bw) {
5503N/A throw new Exception("Expected " + bw + " byte to be read, got: "
5503N/A + bytesWritten);
5503N/A }
5503N/A if (bytesRead != br) {
5503N/A throw new Exception("Expected " + br + " byte to be read, got: "
5503N/A + bytesWritten);
5503N/A }
5503N/A if (!path.equals(f.getPath())) {
5503N/A throw new Exception("Incorrect path: " + path + ". Expected: "
5503N/A + f.getPath());
5503N/A }
5503N/A }
5503N/A
5503N/A protected void expectSocket(int br, int bw, InetAddress ia, int p, int t)
5503N/A throws Exception {
5503N/A if (context != my_context) {
5503N/A throw new Exception("Wrong context: " + context);
5503N/A }
5503N/A if (bytesWritten != bw) {
5503N/A throw new Exception("Expected " + bw + " byte to be written, got: "
5503N/A + bytesWritten);
5503N/A }
5503N/A if (bytesRead != br) {
5503N/A throw new Exception("Expected " + br + " byte to be read, got: "
5503N/A + bytesWritten);
5503N/A }
5503N/A if (!address.equals(ia)) {
5503N/A throw new Exception("Incorrect address: " + address
5503N/A + ". Expected: " + ia);
5503N/A }
5503N/A if (port != p) {
5503N/A throw new Exception("Expected " + p + " port, got: " + port);
5503N/A }
5503N/A if (timeout != t) {
5503N/A throw new Exception("Expected " + t + " timeout, got: " + timeout);
5503N/A }
5503N/A }
5766N/A}