KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > hudson > maven > TransferListenerImpl


1 package hudson.maven;
2
3 import hudson.model.TaskListener;
4 import org.apache.maven.wagon.events.TransferEvent;
5 import org.apache.maven.wagon.events.TransferListener;
6
7 import java.io.PrintStream JavaDoc;
8
9 /**
10  * {@link TransferListener} implementation.
11  *
12  * <p>
13  * This implementation puts the transfer progress indication in a distinctively formatted line,
14  * so that on HTML we can render the progress as a progress bar.
15  *
16  * @author Kohsuke Kawaguchi
17  */

18 final class TransferListenerImpl implements TransferListener {
19     /**
20      * Receives the formatter messages.
21      */

22     private final PrintStream JavaDoc out;
23
24     private long transferedSize;
25
26
27     public TransferListenerImpl(TaskListener listener) {
28         this.out = listener.getLogger();
29     }
30
31     public void transferInitiated( TransferEvent e )
32     {
33         String JavaDoc url = e.getWagon().getRepository().getUrl();
34
35         if(e.getRequestType()==TransferEvent.REQUEST_PUT) {
36             out.println("Uploading to "+url);
37         } else {
38             out.println("Downloading "+url);
39         }
40     }
41
42     public void transferStarted(TransferEvent e) {
43         transferedSize = 0;
44         long total = e.getResource().getContentLength();
45         out.println(HEADER+" start "+total);
46     }
47
48     public void transferProgress(TransferEvent e, byte[] buffer, int length) {
49         transferedSize += length;
50         out.println(HEADER + " progress " + transferedSize);
51     }
52
53     public void transferCompleted(TransferEvent e) {
54         out.println(HEADER + " completed");
55     }
56
57     public void transferError(TransferEvent e) {
58         out.println(HEADER + " error");
59         e.getException().printStackTrace(out);
60     }
61
62     public void debug(String JavaDoc message) {
63     }
64
65     /**
66      * Lines printed by this class will have this header.
67      */

68     public static final String JavaDoc HEADER = "[:TRANSFER:]";
69 }
70
Popular Tags