1 package org.eclipse.aether.transport.file;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
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 }