// Path: Android/Blink/library/src/main/java/net/qiujuer/blink/core/ReceiveDelivery.java
// public interface ReceiveDelivery {
//     /**
//      * Parses a start response from the receiver.
//      *
//      * @param entity ReceivePacket
//      */
//     void postReceiveStart(ReceivePacket entity);
// 
//     /**
//      * Parses a end response from the receiver.
//      *
//      * @param entity    ReceivePacket
//      * @param isSuccess isSuccess
//      */
//     void postReceiveEnd(ReceivePacket entity, boolean isSuccess);
// 
//     /**
//      * Parses a progress response from the receiver.
//      *
//      * @param entity   ReceivePacket
//      * @param progress Receive progress
//      */
//     void postReceiveProgress(ReceivePacket entity, float progress);
// }
// 
// Path: Java/Blink/library/src/net/qiujuer/blink/core/ReceivePacket.java
// public abstract class ReceivePacket extends Packet {
//     private final long mId;
//     private String mHash;
// 
//     public ReceivePacket(long id, byte type, long len) {
//         super(type);
//         mId = id;
//         mLength = len;
//     }
// 
//     public long getId() {
//         return mId;
//     }
// 
//     /**
//      * Set Packet Hash Code
//      *
//      * @param hashCode HashCode
//      */
//     public void setHash(String hashCode) {
//         mHash = hashCode;
//     }
// 
//     /**
//      * Get Packet Hash Code
//      *
//      * @return HashCode
//      */
//     public String getHash() {
//         return mHash;
//     }
// 
//     /**
//      * On Receiver receive same info buffer call this
//      *
//      * @param bytes Info data
//      */
//     public void setInfo(byte[] bytes) {
//     }
// 
//     /**
//      * Receiver write buffer
//      *
//      * @param buffer Buffer
//      * @param offset Buffer offset
//      * @param count  Buffer Count
//      */
//     public abstract void write(byte[] buffer, int offset, int count);
// }
// 
// Path: Android/Blink/library/src/main/java/net/qiujuer/blink/core/SendDelivery.java
// public interface SendDelivery extends Disposable {
// 
//     /**
//      * Parses a progress response from the sender.
//      *
//      * @param entity   SendPacket
//      * @param progress Send progress
//      */
//     void postSendProgress(SendPacket entity, float progress);
// }
// 
// Path: Android/Blink/library/src/main/java/net/qiujuer/blink/core/SendPacket.java
// public abstract class SendPacket extends BlinkPacket {
//     private final SendListener mListener;
//     private boolean mCanceled;
//     private BlinkConn mBlinkConn;
// 
// 
//     public SendPacket(byte type, SendListener listener) {
//         super(type);
//         mListener = listener;
//     }
// 
//     public SendListener getListener() {
//         return mListener;
//     }
// 
//     /**
//      * Cancel the packet to send
//      * If the packet on sending you can't cancel it
//      * But you can cancel sending notify callback
//      */
//     public void cancel() {
//         mCanceled = true;
//         if (mBlinkConn != null) {
//             mBlinkConn.cancel(this);
//             mBlinkConn = null;
//         }
//     }
// 
//     /**
//      * Get the packet iscanceled
//      *
//      * @return Is Canceled
//      */
//     public boolean isCanceled() {
//         return mCanceled;
//     }
// 
//     /**
//      * Set The BlinkConn to Cancel from queue
//      *
//      * @param blinkConn BlinkConn
//      * @return SendPacket
//      */
//     SendPacket setBlinkConn(BlinkConn blinkConn) {
//         mBlinkConn = blinkConn;
//         return this;
//     }
// 
//     /**
//      * On Sender send the packet call this to send packet info
//      * The bytes in 0~32767 size
//      *
//      * @param buffer Send buffer
//      * @param index  Buffer start index
//      * @return Read to buffer count
//      */
//     public short readInfo(byte[] buffer, int index) {
//         return 0;
//     }
// 
//     /**
//      * Sender read same data to send
//      *
//      * @param buffer Buffer
//      * @param offset Buffer offset
//      * @param count  Buffer count
//      * @return Read to buffer count
//      */
//     public abstract int read(byte[] buffer, int offset, int count);
// }
// 
// Path: Android/Blink/library/src/main/java/net/qiujuer/blink/listener/ReceiveListener.java
// public interface ReceiveListener {
//     /**
//      * On Receiver receive new packet call this
//      *
//      * @param type Packet Type
//      * @param id   Packet Id
//      */
//     void onReceiveStart(byte type, long id);
// 
//     /**
//      * Receiver receive packet progress
//      *
//      * @param packet   ReceivePacket
//      * @param progress Receive Progress
//      */
//     void onReceiveProgress(ReceivePacket packet, float progress);
// 
//     /**
//      * On Receiver end receive packet call this
//      *
//      * @param packet ReceivePacket
//      */
//     void onReceiveEnd(ReceivePacket packet);
// }


import android.os.Handler;
import net.qiujuer.blink.core.ReceiveDelivery;
import net.qiujuer.blink.core.ReceivePacket;
import net.qiujuer.blink.core.SendDelivery;
import net.qiujuer.blink.core.SendPacket;
import net.qiujuer.blink.listener.ReceiveListener;
import java.util.concurrent.Executor;
            @Override
            public void execute(Runnable command) {
                handler.post(command);
            }
        };
    }

    public ExecutorDelivery(Executor executor, ReceiveListener listener) {
        super(listener);
        mPoster = executor;
    }

    @Override
    public void postSendStart(SendPacket entity) {
        mPoster.execute(new SendDeliveryRunnable(entity, null, false));
    }

    @Override
    public void postSendEnd(SendPacket entity, boolean isSuccess) {
        entity.setSuccess(isSuccess);
        mPoster.execute(new SendDeliveryRunnable(entity, null, true));
    }

    @Override
    public void postSendProgress(SendPacket entity, int total, int cur) {
        ProgressStatus status = new ProgressStatus(total, cur);
        mPoster.execute(new SendDeliveryRunnable(entity, status, false));
    }

    @Override
// Path: Android/Blink/library/src/main/java/net/qiujuer/blink/core/ReceiveDelivery.java
// public interface ReceiveDelivery {
//     /**
//      * Parses a start response from the receiver.
//      *
//      * @param entity ReceivePacket
//      */
//     void postReceiveStart(ReceivePacket entity);
// 
//     /**
//      * Parses a end response from the receiver.
//      *
//      * @param entity    ReceivePacket
//      * @param isSuccess isSuccess
//      */
//     void postReceiveEnd(ReceivePacket entity, boolean isSuccess);
// 
//     /**
//      * Parses a progress response from the receiver.
//      *
//      * @param entity   ReceivePacket
//      * @param progress Receive progress
//      */
//     void postReceiveProgress(ReceivePacket entity, float progress);
// }
// 
// Path: Java/Blink/library/src/net/qiujuer/blink/core/ReceivePacket.java
// public abstract class ReceivePacket extends Packet {
//     private final long mId;
//     private String mHash;
// 
//     public ReceivePacket(long id, byte type, long len) {
//         super(type);
//         mId = id;
//         mLength = len;
//     }
// 
//     public long getId() {
//         return mId;
//     }
// 
//     /**
//      * Set Packet Hash Code
//      *
//      * @param hashCode HashCode
//      */
//     public void setHash(String hashCode) {
//         mHash = hashCode;
//     }
// 
//     /**
//      * Get Packet Hash Code
//      *
//      * @return HashCode
//      */
//     public String getHash() {
//         return mHash;
//     }
// 
//     /**
//      * On Receiver receive same info buffer call this
//      *
//      * @param bytes Info data
//      */
//     public void setInfo(byte[] bytes) {
//     }
// 
//     /**
//      * Receiver write buffer
//      *
//      * @param buffer Buffer
//      * @param offset Buffer offset
//      * @param count  Buffer Count
//      */
//     public abstract void write(byte[] buffer, int offset, int count);
// }
// 
// Path: Android/Blink/library/src/main/java/net/qiujuer/blink/core/SendDelivery.java
// public interface SendDelivery extends Disposable {
// 
//     /**
//      * Parses a progress response from the sender.
//      *
//      * @param entity   SendPacket
//      * @param progress Send progress
//      */
//     void postSendProgress(SendPacket entity, float progress);
// }
// 
// Path: Android/Blink/library/src/main/java/net/qiujuer/blink/core/SendPacket.java
// public abstract class SendPacket extends BlinkPacket {
//     private final SendListener mListener;
//     private boolean mCanceled;
//     private BlinkConn mBlinkConn;
// 
// 
//     public SendPacket(byte type, SendListener listener) {
//         super(type);
//         mListener = listener;
//     }
// 
//     public SendListener getListener() {
//         return mListener;
//     }
// 
//     /**
//      * Cancel the packet to send
//      * If the packet on sending you can't cancel it
//      * But you can cancel sending notify callback
//      */
//     public void cancel() {
//         mCanceled = true;
//         if (mBlinkConn != null) {
//             mBlinkConn.cancel(this);
//             mBlinkConn = null;
//         }
//     }
// 
//     /**
//      * Get the packet iscanceled
//      *
//      * @return Is Canceled
//      */
//     public boolean isCanceled() {
//         return mCanceled;
//     }
// 
//     /**
//      * Set The BlinkConn to Cancel from queue
//      *
//      * @param blinkConn BlinkConn
//      * @return SendPacket
//      */
//     SendPacket setBlinkConn(BlinkConn blinkConn) {
//         mBlinkConn = blinkConn;
//         return this;
//     }
// 
//     /**
//      * On Sender send the packet call this to send packet info
//      * The bytes in 0~32767 size
//      *
//      * @param buffer Send buffer
//      * @param index  Buffer start index
//      * @return Read to buffer count
//      */
//     public short readInfo(byte[] buffer, int index) {
//         return 0;
//     }
// 
//     /**
//      * Sender read same data to send
//      *
//      * @param buffer Buffer
//      * @param offset Buffer offset
//      * @param count  Buffer count
//      * @return Read to buffer count
//      */
//     public abstract int read(byte[] buffer, int offset, int count);
// }
// 
// Path: Android/Blink/library/src/main/java/net/qiujuer/blink/listener/ReceiveListener.java
// public interface ReceiveListener {
//     /**
//      * On Receiver receive new packet call this
//      *
//      * @param type Packet Type
//      * @param id   Packet Id
//      */
//     void onReceiveStart(byte type, long id);
// 
//     /**
//      * Receiver receive packet progress
//      *
//      * @param packet   ReceivePacket
//      * @param progress Receive Progress
//      */
//     void onReceiveProgress(ReceivePacket packet, float progress);
// 
//     /**
//      * On Receiver end receive packet call this
//      *
//      * @param packet ReceivePacket
//      */
//     void onReceiveEnd(ReceivePacket packet);
// }


// Path: Android/Blink/old/src/main/java/net/qiujuer/blink/ExecutorDelivery.java
import android.os.Handler;
import net.qiujuer.blink.core.ReceiveDelivery;
import net.qiujuer.blink.core.ReceivePacket;
import net.qiujuer.blink.core.SendDelivery;
import net.qiujuer.blink.core.SendPacket;
import net.qiujuer.blink.listener.ReceiveListener;
import java.util.concurrent.Executor;

            @Override
            public void execute(Runnable command) {
                handler.post(command);
            }
        };
    }

    public ExecutorDelivery(Executor executor, ReceiveListener listener) {
        super(listener);
        mPoster = executor;
    }

    @Override
    public void postSendStart(SendPacket entity) {
        mPoster.execute(new SendDeliveryRunnable(entity, null, false));
    }

    @Override
    public void postSendEnd(SendPacket entity, boolean isSuccess) {
        entity.setSuccess(isSuccess);
        mPoster.execute(new SendDeliveryRunnable(entity, null, true));
    }

    @Override
    public void postSendProgress(SendPacket entity, int total, int cur) {
        ProgressStatus status = new ProgressStatus(total, cur);
        mPoster.execute(new SendDeliveryRunnable(entity, status, false));
    }

    @Override
    public void postReceiveStart(ReceivePacket entity) {