// Path: measures/src/main/java/io/apisense/network/MeasurementError.java
// public class MeasurementError extends Exception {
//   public final String taskName;
// 
//   public MeasurementError(String taskName, String reason) {
//     super(reason);
//     this.taskName = taskName;
//   }
// 
//   public MeasurementError(String taskName, String reason, Throwable e) {
//     super(reason, e);
//     this.taskName = taskName;
//   }
// 
//   public MeasurementError(String taskName, Exception e) {
//     this(taskName, e.getMessage(), e);
//   }
// }
// 
// Path: measures/src/main/java/io/apisense/network/MeasurementResult.java
// public abstract class MeasurementResult {
//   /**
//    * Name of the task (ie TCP download, Traceroute, etc)
//    */
//   private final String taskName;
// 
//   /**
//    * Time of the beginning of the task in milliseconds
//    */
//   private final long startTime;
// 
//   /**
//    * Time of the end of the task in milliseconds
//    */
//   private final long endTime;
// 
//   /**
//    * Number of milliseconds representing the duration of the task
//    */
//   private final long duration;
// 
//   protected MeasurementResult(String taskName, long startTime, long endTime) {
//     this.taskName = taskName;
//     this.startTime = startTime;
//     this.endTime = endTime;
//     this.duration = endTime - startTime;
//   }
// 
//   public String getTaskName() {
//     return taskName;
//   }
// 
//   public long getStartTime() {
//     return startTime;
//   }
// 
//   public long getEndTime() {
//     return endTime;
//   }
// 
//   public long getDuration() {
//     return duration;
//   }
// 
//   @Override
//   public String toString() {
//     return "MeasurementResult{" +
//         "taskName='" + taskName + '\'' +
//         ", startTime=" + startTime +
//         ", endTime=" + endTime +
//         ", duration=" + duration +
//         '}';
//   }
// }


import android.util.Log;
import java.io.IOException;
import java.net.DatagramSocket;
import io.apisense.network.MeasurementError;
import io.apisense.network.MeasurementResult;
package io.apisense.network.udp;





/**
 * Measurement class used to realise an UDP download burst
 * Measures the jitter, the jitter, the loss, and the number of out of order packets in download
 */
public class UDPDownloadBurstTask extends UDPBurstTask {
  public static final String TAG = "UDPDownloadBurst";

  public UDPDownloadBurstTask(UDPBurstConfig udpBurstConfig) {
    super(TAG, udpBurstConfig);
  }

  /**
   * {@inheritDoc}
   *
   * @return A {@link UDPBurstResult} object containing information on the UDP download burst.
   * @throws MeasurementError {@inheritDoc}
   */
  public MeasurementResult execute() throws MeasurementError {
    MetricCalculator metricCalculator = new MetricCalculator();
    DatagramSocket sock = openSocket();

    startTimeTask = System.currentTimeMillis();
    UDPPacket dataPacket;
    int pktRecv = 0;

    sendDownloadRequest(sock);

    for (int i = 0; i < config.getUdpBurstCount(); i++) {
      dataPacket = retrieveResponseDatagram(sock);

      if (dataPacket.type == UDPPacket.PKT_DATA) {
        Log.v(TAG, "Received packed n°" + dataPacket.packetNum);
// Path: measures/src/main/java/io/apisense/network/MeasurementError.java
// public class MeasurementError extends Exception {
//   public final String taskName;
// 
//   public MeasurementError(String taskName, String reason) {
//     super(reason);
//     this.taskName = taskName;
//   }
// 
//   public MeasurementError(String taskName, String reason, Throwable e) {
//     super(reason, e);
//     this.taskName = taskName;
//   }
// 
//   public MeasurementError(String taskName, Exception e) {
//     this(taskName, e.getMessage(), e);
//   }
// }
// 
// Path: measures/src/main/java/io/apisense/network/MeasurementResult.java
// public abstract class MeasurementResult {
//   /**
//    * Name of the task (ie TCP download, Traceroute, etc)
//    */
//   private final String taskName;
// 
//   /**
//    * Time of the beginning of the task in milliseconds
//    */
//   private final long startTime;
// 
//   /**
//    * Time of the end of the task in milliseconds
//    */
//   private final long endTime;
// 
//   /**
//    * Number of milliseconds representing the duration of the task
//    */
//   private final long duration;
// 
//   protected MeasurementResult(String taskName, long startTime, long endTime) {
//     this.taskName = taskName;
//     this.startTime = startTime;
//     this.endTime = endTime;
//     this.duration = endTime - startTime;
//   }
// 
//   public String getTaskName() {
//     return taskName;
//   }
// 
//   public long getStartTime() {
//     return startTime;
//   }
// 
//   public long getEndTime() {
//     return endTime;
//   }
// 
//   public long getDuration() {
//     return duration;
//   }
// 
//   @Override
//   public String toString() {
//     return "MeasurementResult{" +
//         "taskName='" + taskName + '\'' +
//         ", startTime=" + startTime +
//         ", endTime=" + endTime +
//         ", duration=" + duration +
//         '}';
//   }
// }


// Path: measures/src/main/java/io/apisense/network/udp/UDPDownloadBurstTask.java
import android.util.Log;
import java.io.IOException;
import java.net.DatagramSocket;
import io.apisense.network.MeasurementError;
import io.apisense.network.MeasurementResult;

package io.apisense.network.udp;





/**
 * Measurement class used to realise an UDP download burst
 * Measures the jitter, the jitter, the loss, and the number of out of order packets in download
 */
public class UDPDownloadBurstTask extends UDPBurstTask {
  public static final String TAG = "UDPDownloadBurst";

  public UDPDownloadBurstTask(UDPBurstConfig udpBurstConfig) {
    super(TAG, udpBurstConfig);
  }

  /**
   * {@inheritDoc}
   *
   * @return A {@link UDPBurstResult} object containing information on the UDP download burst.
   * @throws MeasurementError {@inheritDoc}
   */
  public MeasurementResult execute() throws MeasurementError {
    MetricCalculator metricCalculator = new MetricCalculator();
    DatagramSocket sock = openSocket();

    startTimeTask = System.currentTimeMillis();
    UDPPacket dataPacket;
    int pktRecv = 0;

    sendDownloadRequest(sock);

    for (int i = 0; i < config.getUdpBurstCount(); i++) {
      dataPacket = retrieveResponseDatagram(sock);

      if (dataPacket.type == UDPPacket.PKT_DATA) {
        Log.v(TAG, "Received packed n°" + dataPacket.packetNum);
        pktRecv++;