View Javadoc

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