View Javadoc
1   package org.eclipse.aether.transport.http;
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 java.io.ByteArrayOutputStream;
23  import java.nio.ByteBuffer;
24  
25  import org.eclipse.aether.spi.connector.transport.TransportListener;
26  import org.eclipse.aether.transfer.TransferCancelledException;
27  
28  class RecordingTransportListener
29      extends TransportListener
30  {
31  
32      public final ByteArrayOutputStream baos = new ByteArrayOutputStream( 1024 );
33  
34      public long dataOffset;
35  
36      public long dataLength;
37  
38      public int startedCount;
39  
40      public int progressedCount;
41  
42      public boolean cancelStart;
43  
44      public boolean cancelProgress;
45  
46      @Override
47      public void transportStarted( long dataOffset, long dataLength )
48          throws TransferCancelledException
49      {
50          startedCount++;
51          progressedCount = 0;
52          this.dataLength = dataLength;
53          this.dataOffset = dataOffset;
54          baos.reset();
55          if ( cancelStart )
56          {
57              throw new TransferCancelledException();
58          }
59      }
60  
61      @Override
62      public void transportProgressed( ByteBuffer data )
63          throws TransferCancelledException
64      {
65          progressedCount++;
66          baos.write( data.array(), data.arrayOffset() + data.position(), data.remaining() );
67          if ( cancelProgress )
68          {
69              throw new TransferCancelledException();
70          }
71      }
72  
73  }