Source code: com/yaftp/ftp/FtpStandardListener.java
1 /**
2 *
3 * CopyRights Jean-Yves MENGANT 1999,2000,2001,2002
4 *
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License
7 * as published by the Free Software Foundation; either version 2
8 * of the License, or any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
18 */
19
20 package com.yaftp.ftp ;
21
22 import java.util.Vector ;
23 import java.io.* ;
24
25 /**
26
27 Define the FtpStandardListener as an abstract top level class and
28 Define the FtpVectorListener as beeing the simplest implementation of the
29 concept inheriting from FtpStandarListener which standardize basic
30 interface behavior
31 this implementation is basically used with the LIST command but may also
32 be used for any other similar usage
33
34 @Author Jean-Yves MENGANT
35 @version : 0.0.1
36
37
38 */
39 public abstract class FtpStandardListener
40 implements FtpClientListener {
41
42 private String _dataMessage ; // Error Message
43
44 protected FtpBufferTransfertListener _listener ;
45 private FtpBufferTransfertEvent _bufferEvent = null ;
46
47 protected void broadcastBufferEvent( int bufferSize )
48 {
49 if ( ( _listener == null ) || ( bufferSize == -1 ) )
50 return ;
51
52 if ( _bufferEvent == null )
53 _bufferEvent = new FtpBufferTransfertEvent( this , bufferSize ) ;
54 else
55 _bufferEvent.set_bytesTransfered(bufferSize) ;
56 _listener.bytesTransfered(_bufferEvent);
57 }
58
59 // Make data thread errors visible
60 public void dataError ( String error , FtpDataNotifier dataEvt )
61 {
62 _dataMessage = error ;
63 dataEvt.makeDataVisible() ;
64 }
65
66 // Standards accessors and actuators
67 public void set_dataMessage( String msg )
68 { _dataMessage = msg ; }
69
70 public String get_dataMessage()
71 { return _dataMessage ; }
72
73 public void addFtpBufferTransfertListener( FtpBufferTransfertListener listener )
74 {
75 if ( _listener == null )
76 _listener = listener ;
77 }
78
79 public void removeFtpBufferTransfertListener( FtpBufferTransfertListener listener )
80 {
81 if ( _listener == listener )
82 _listener = null ;
83 }
84
85 public abstract void readData( InputStream myStream ,
86 FtpDataNotifier dataEvt
87 ) ;
88
89 public abstract void writeData( OutputStream myWriter ,
90 FtpDataNotifier dataEvt
91 ) ;
92
93 public abstract void buildLocalReader( File file )
94 throws ClientFtpError ;
95
96 public abstract void closeLocalReader()
97 throws ClientFtpError ;
98
99 public abstract void buildLocalWriter( File file )
100 throws ClientFtpError ;
101
102 public abstract void closeLocalWriter()
103 throws ClientFtpError ;
104
105 }
106