View Javadoc

1   package org.apache.maven.index.updater.fixtures;
2   
3   /*
4    * Licensed to the Apache Software Foundation (ASF) under one
5    * or more contributor license agreements.  See the NOTICE file
6    * distributed with this work for additional information
7    * regarding copyright ownership.  The ASF licenses this file
8    * to you under the Apache License, Version 2.0 (the
9    * "License"); you may not use this file except in compliance
10   * with the License.  You may obtain a copy of the License at
11   *
12   *   http://www.apache.org/licenses/LICENSE-2.0    
13   *
14   * Unless required by applicable law or agreed to in writing,
15   * software distributed under the License is distributed on an
16   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17   * KIND, either express or implied.  See the License for the
18   * specific language governing permissions and limitations
19   * under the License.
20   */
21  
22  import org.apache.maven.wagon.events.TransferEvent;
23  import org.apache.maven.wagon.events.TransferListener;
24  
25  public class TransferListenerFixture
26      implements TransferListener
27  {
28      private static final int ONE_CHUNK = 64;
29  
30      private int col = 0;
31  
32      private int count = 0;
33  
34      private int kb = 0;
35  
36      public void transferStarted( final TransferEvent transferEvent )
37      {
38          System.out.println( "Started transfer: " + transferEvent.getResource().getName() );
39      }
40  
41      public void transferProgress( final TransferEvent transferEvent, final byte[] buffer, final int length )
42      {
43          if ( buffer == null )
44          {
45              return;
46          }
47  
48          count += buffer.length;
49  
50          if ( ( count / ONE_CHUNK ) > kb )
51          {
52              if ( col > 80 )
53              {
54                  System.out.println();
55                  col = 0;
56              }
57  
58              System.out.print( '.' );
59              col++;
60              kb++;
61          }
62      }
63  
64      public void transferInitiated( final TransferEvent transferEvent )
65      {
66      }
67  
68      public void transferError( final TransferEvent transferEvent )
69      {
70          System.out.println( "[ERROR]: " + transferEvent.getException().getLocalizedMessage() );
71          transferEvent.getException().printStackTrace();
72      }
73  
74      public void transferCompleted( final TransferEvent transferEvent )
75      {
76          System.out.println( "\nCompleted transfer: " + transferEvent.getResource().getName() + " ("
77              + (double) ( count / ONE_CHUNK ) + " chunks of size: " + ONE_CHUNK + " bytes)" );
78      }
79  
80      public void debug( final String message )
81      {
82          System.out.println( "[DEBUG]: " + message );
83      }
84  }