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.EventListener; 019 020 /** 021 * The CopyStreamListener class can accept CopyStreamEvents to keep track 022 * of the progress of a stream copying operation. However, it is currently 023 * not used that way within NetComponents for performance reasons. Rather 024 * the bytesTransferred(long, int) method is called directly rather than 025 * passing an event to bytesTransferred(CopyStreamEvent), saving the creation 026 * of a CopyStreamEvent instance. Also, the only place where 027 * CopyStreamListener is currently used within NetComponents is in the 028 * static methods of the uninstantiable org.apache.commons.io.Util class, which 029 * would preclude the use of addCopyStreamListener and 030 * removeCopyStreamListener methods. However, future additions may use the 031 * JavaBean event model, which is why the hooks have been included from the 032 * beginning. 033 * <p> 034 * <p> 035 * @see CopyStreamEvent 036 * @see CopyStreamAdapter 037 * @see Util 038 * @author <a href="mailto:savarese@apache.org">Daniel F. Savarese</a> 039 * @version $Id: CopyStreamListener.java 165675 2005-05-02 20:09:55Z rwinston $ 040 */ 041 public interface CopyStreamListener extends EventListener 042 { 043 /** 044 * This method is invoked by a CopyStreamEvent source after copying 045 * a block of bytes from a stream. The CopyStreamEvent will contain 046 * the total number of bytes transferred so far and the number of bytes 047 * transferred in the last write. 048 * @param event The CopyStreamEvent fired by the copying of a block of 049 * bytes. 050 */ 051 public void bytesTransferred(CopyStreamEvent event); 052 053 054 /** 055 * This method is not part of the JavaBeans model and is used by the 056 * static methods in the org.apache.commons.io.Util class for efficiency. 057 * It is invoked after a block of bytes to inform the listener of the 058 * transfer. 059 * @param totalBytesTransferred The total number of bytes transferred 060 * so far by the copy operation. 061 * @param bytesTransferred The number of bytes copied by the most recent 062 * write. 063 * @param streamSize The number of bytes in the stream being copied. 064 * This may be equal to CopyStreamEvent.UNKNOWN_STREAM_SIZE if 065 * the size is unknown. 066 */ 067 public void bytesTransferred(long totalBytesTransferred, 068 int bytesTransferred, 069 long streamSize); 070 }