01: /*
02: * Copyright 2001-2005 The Apache Software Foundation
03: *
04: * Licensed under the Apache License, Version 2.0 (the "License");
05: * you may not use this file except in compliance with the License.
06: * You may obtain a copy of the License at
07: *
08: * http://www.apache.org/licenses/LICENSE-2.0
09: *
10: * Unless required by applicable law or agreed to in writing, software
11: * distributed under the License is distributed on an "AS IS" BASIS,
12: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13: * See the License for the specific language governing permissions and
14: * limitations under the License.
15: */
16: package org.apache.commons.net.io;
17:
18: import java.util.EventObject;
19:
20: /**
21: * A CopyStreamEvent is triggered after every write performed by a
22: * stream copying operation. The event stores the number of bytes
23: * transferred by the write triggering the event as well as the total
24: * number of bytes transferred so far by the copy operation.
25: * <p>
26: * <p>
27: * @see CopyStreamListener
28: * @see CopyStreamAdapter
29: * @see Util
30: * @author <a href="mailto:savarese@apache.org">Daniel F. Savarese</a>
31: * @version $Id: CopyStreamEvent.java 165675 2005-05-02 20:09:55Z rwinston $
32: */
33: public class CopyStreamEvent extends EventObject {
34: /**
35: * Constant used to indicate the stream size is unknown.
36: */
37: public static final long UNKNOWN_STREAM_SIZE = -1;
38:
39: private int bytesTransferred;
40: private long totalBytesTransferred;
41: private long streamSize;
42:
43: /**
44: * Creates a new CopyStreamEvent instance.
45: * @param source The source of the event.
46: * @param totalBytesTransferred The total number of bytes transferred so
47: * far during a copy operation.
48: * @param bytesTransferred The number of bytes transferred during the
49: * write that triggered the CopyStreamEvent.
50: * @param streamSize The number of bytes in the stream being copied.
51: * This may be set to <code>UNKNOWN_STREAM_SIZE</code> if the
52: * size is unknown.
53: */
54: public CopyStreamEvent(Object source, long totalBytesTransferred,
55: int bytesTransferred, long streamSize) {
56: super (source);
57: this .bytesTransferred = bytesTransferred;
58: this .totalBytesTransferred = totalBytesTransferred;
59: this .streamSize = streamSize;
60: }
61:
62: /**
63: * Returns the number of bytes transferred by the write that triggered
64: * the event.
65: * @return The number of bytes transferred by the write that triggered
66: * the vent.
67: */
68: public int getBytesTransferred() {
69: return bytesTransferred;
70: }
71:
72: /**
73: * Returns the total number of bytes transferred so far by the copy
74: * operation.
75: * @return The total number of bytes transferred so far by the copy
76: * operation.
77: */
78: public long getTotalBytesTransferred() {
79: return totalBytesTransferred;
80: }
81:
82: /**
83: * Returns the size of the stream being copied.
84: * This may be set to <code>UNKNOWN_STREAM_SIZE</code> if the
85: * size is unknown.
86: * @return The size of the stream being copied.
87: */
88: public long getStreamSize() {
89: return streamSize;
90: }
91: }
|