001 /*
002 * Copyright 2001-2005 The Apache Software Foundation
003 *
004 * Licensed under the Apache License, Version 2.0 (the "License");
005 * you may not use this file except in compliance with the License.
006 * You may obtain a copy of the License at
007 *
008 * http://www.apache.org/licenses/LICENSE-2.0
009 *
010 * Unless required by applicable law or agreed to in writing, software
011 * distributed under the License is distributed on an "AS IS" BASIS,
012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 * See the License for the specific language governing permissions and
014 * limitations under the License.
015 */
016 package org.apache.commons.net.io;
017
018 import java.util.EventObject;
019
020 /**
021 * A CopyStreamEvent is triggered after every write performed by a
022 * stream copying operation. The event stores the number of bytes
023 * transferred by the write triggering the event as well as the total
024 * number of bytes transferred so far by the copy operation.
025 * <p>
026 * <p>
027 * @see CopyStreamListener
028 * @see CopyStreamAdapter
029 * @see Util
030 * @author <a href="mailto:savarese@apache.org">Daniel F. Savarese</a>
031 * @version $Id: CopyStreamEvent.java 165675 2005-05-02 20:09:55Z rwinston $
032 */
033 public class CopyStreamEvent extends EventObject
034 {
035 /**
036 * Constant used to indicate the stream size is unknown.
037 */
038 public static final long UNKNOWN_STREAM_SIZE = -1;
039
040 private int bytesTransferred;
041 private long totalBytesTransferred;
042 private long streamSize;
043
044 /**
045 * Creates a new CopyStreamEvent instance.
046 * @param source The source of the event.
047 * @param totalBytesTransferred The total number of bytes transferred so
048 * far during a copy operation.
049 * @param bytesTransferred The number of bytes transferred during the
050 * write that triggered the CopyStreamEvent.
051 * @param streamSize The number of bytes in the stream being copied.
052 * This may be set to <code>UNKNOWN_STREAM_SIZE</code> if the
053 * size is unknown.
054 */
055 public CopyStreamEvent(Object source, long totalBytesTransferred,
056 int bytesTransferred, long streamSize)
057 {
058 super(source);
059 this.bytesTransferred = bytesTransferred;
060 this.totalBytesTransferred = totalBytesTransferred;
061 this.streamSize = streamSize;
062 }
063
064 /**
065 * Returns the number of bytes transferred by the write that triggered
066 * the event.
067 * @return The number of bytes transferred by the write that triggered
068 * the vent.
069 */
070 public int getBytesTransferred()
071 {
072 return bytesTransferred;
073 }
074
075 /**
076 * Returns the total number of bytes transferred so far by the copy
077 * operation.
078 * @return The total number of bytes transferred so far by the copy
079 * operation.
080 */
081 public long getTotalBytesTransferred()
082 {
083 return totalBytesTransferred;
084 }
085
086 /**
087 * Returns the size of the stream being copied.
088 * This may be set to <code>UNKNOWN_STREAM_SIZE</code> if the
089 * size is unknown.
090 * @return The size of the stream being copied.
091 */
092 public long getStreamSize()
093 {
094 return streamSize;
095 }
096 }