use of org.sonatype.aether.transfer.TransferResource in project sonatype-aether by sonatype.
the class ConsoleTransferListener method transferProgressed.
@Override
public void transferProgressed(TransferEvent event) {
TransferResource resource = event.getResource();
downloads.put(resource, Long.valueOf(event.getTransferredBytes()));
StringBuilder buffer = new StringBuilder(64);
for (Map.Entry<TransferResource, Long> entry : downloads.entrySet()) {
long total = entry.getKey().getContentLength();
long complete = entry.getValue().longValue();
buffer.append(getStatus(complete, total)).append(" ");
}
int pad = lastLength - buffer.length();
lastLength = buffer.length();
pad(buffer, pad);
buffer.append('\r');
out.print(buffer);
}
use of org.sonatype.aether.transfer.TransferResource in project sonatype-aether by sonatype.
the class TransferEventTester method checkEvents.
private static void checkEvents(Queue<TransferEvent> events, long expectedBytes) {
TransferEvent currentEvent = events.poll();
String msg = "initiate event is missing";
assertNotNull(msg, currentEvent);
assertEquals(msg, INITIATED, currentEvent.getType());
checkProperties(currentEvent);
TransferResource expectedResource = currentEvent.getResource();
currentEvent = events.poll();
msg = "start event is missing";
assertNotNull(msg, currentEvent);
assertEquals(msg, TransferEvent.EventType.STARTED, currentEvent.getType());
assertEquals("bad content length", expectedBytes, currentEvent.getResource().getContentLength());
checkProperties(currentEvent);
assertResourceEquals(expectedResource, currentEvent.getResource());
EventType progressed = TransferEvent.EventType.PROGRESSED;
EventType succeeded = TransferEvent.EventType.SUCCEEDED;
TransferEvent succeedEvent = null;
int dataLength = 0;
long transferredBytes = 0;
while ((currentEvent = events.poll()) != null) {
EventType currentType = currentEvent.getType();
assertResourceEquals(expectedResource, currentEvent.getResource());
if (succeeded.equals(currentType)) {
succeedEvent = currentEvent;
checkProperties(currentEvent);
break;
} else {
assertTrue("event is not 'succeeded' and not 'progressed'", progressed.equals(currentType));
assertTrue("wrong order of progressed events, transferredSize got smaller, last = " + transferredBytes + ", current = " + currentEvent.getTransferredBytes(), currentEvent.getTransferredBytes() >= transferredBytes);
assertEquals("bad content length", expectedBytes, currentEvent.getResource().getContentLength());
transferredBytes = currentEvent.getTransferredBytes();
dataLength += currentEvent.getDataBuffer().remaining();
checkProperties(currentEvent);
}
}
// all events consumed
assertEquals("too many events left: " + events.toString(), 0, events.size());
// test transferred size
assertEquals("progress events transferred bytes don't match: data length does not add up", expectedBytes, dataLength);
assertEquals("succeed event transferred bytes don't match", expectedBytes, succeedEvent.getTransferredBytes());
}
Aggregations