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.EventListener;
21
22 /**
23 * The CopyStreamListener class can accept CopyStreamEvents to keep track
24 * of the progress of a stream copying operation. However, it is currently
25 * not used that way within NetComponents for performance reasons. Rather
26 * the bytesTransferred(long, int) method is called directly rather than
27 * passing an event to bytesTransferred(CopyStreamEvent), saving the creation
28 * of a CopyStreamEvent instance. Also, the only place where
29 * CopyStreamListener is currently used within NetComponents is in the
30 * static methods of the uninstantiable org.apache.commons.io.Util class, which
31 * would preclude the use of addCopyStreamListener and
32 * removeCopyStreamListener methods. However, future additions may use the
33 * JavaBean event model, which is why the hooks have been included from the
34 * beginning.
35 * <p>
36 * <p>
37 * @see CopyStreamEvent
38 * @see CopyStreamAdapter
39 * @see Util
40 * @author <a href="mailto:savarese@apache.org">Daniel F. Savarese</a>
41 * @version $Id: CopyStreamListener.java 489397 2006-12-21 16:28:51Z rwinston $
42 */
43 public interface CopyStreamListener extends EventListener
44 {
45 /**
46 * This method is invoked by a CopyStreamEvent source after copying
47 * a block of bytes from a stream. The CopyStreamEvent will contain
48 * the total number of bytes transferred so far and the number of bytes
49 * transferred in the last write.
50 * @param event The CopyStreamEvent fired by the copying of a block of
51 * bytes.
52 */
53 public void bytesTransferred(CopyStreamEvent event);
54
55
56 /**
57 * This method is not part of the JavaBeans model and is used by the
58 * static methods in the org.apache.commons.io.Util class for efficiency.
59 * It is invoked after a block of bytes to inform the listener of the
60 * transfer.
61 * @param totalBytesTransferred The total number of bytes transferred
62 * so far by the copy operation.
63 * @param bytesTransferred The number of bytes copied by the most recent
64 * write.
65 * @param streamSize The number of bytes in the stream being copied.
66 * This may be equal to CopyStreamEvent.UNKNOWN_STREAM_SIZE if
67 * the size is unknown.
68 */
69 public void bytesTransferred(long totalBytesTransferred,
70 int bytesTransferred,
71 long streamSize);
72 }