// Path: library/src/main/java/com/vincan/medialoader/tinyhttpd/HttpConstants.java
// public final class HttpConstants {
// 
//     public final static String CRLF = "\r\n";
// 
//     public final static String SP = " ";
// 
//     public final static String COLON = ":";
// 
//     public static final String CHARSET_DEFAULT = "UTF-8";
// 
//     public static final String PARAM_SIGN = "sign";
// 
//     public static final String PARAM_TIMESTAMP = "timestamp";
// 
//     private HttpConstants() {
//         // Unused
//     }
// }
// 
// Path: library/src/main/java/com/vincan/medialoader/tinyhttpd/response/HttpResponse.java
// public final class HttpResponse implements Response {
// 
//     private HttpHeaders mHeaders = new HttpHeaders();
// 
//     private final HttpVersion mHttpVersion = HttpVersion.HTTP_1_1;
// 
//     private HttpStatus mStatus = HttpStatus.OK;
// 
//     private final SocketChannel mChannel;
// 
//     private ByteBuffer mResponseByteBuffer = ByteBuffer.allocate(Util.DEFAULT_BUFFER_SIZE);
// 
//     public HttpResponse(SocketChannel channel) {
//         mChannel = channel;
//     }
// 
//     @Override
//     public void setStatus(HttpStatus status) {
//         mStatus = status;
//     }
// 
//     @Override
//     public void addHeader(String key, String value) {
//         mHeaders.put(key, value);
//     }
// 
//     @Override
//     public void write(byte[] bytes) throws IOException {
//         write(bytes, 0, bytes.length);
//     }
// 
//     @Override
//     public void write(byte[] bytes, int offset, int length) throws IOException {
//         mResponseByteBuffer.put(bytes, offset, length);
//         mResponseByteBuffer.flip();
//         while (mResponseByteBuffer.hasRemaining()) {//XXX 巨坑：ByteBuffer会缓存，可能不会全部写入channel
//             mChannel.write(mResponseByteBuffer);
//         }
//         mResponseByteBuffer.clear();
//     }
// 
//     @Override
//     public HttpStatus status() {
//         return mStatus;
//     }
// 
//     @Override
//     public HttpVersion protocol() {
//         return mHttpVersion;
//     }
// 
//     @Override
//     public HttpHeaders headers() {
//         return mHeaders;
//     }
// 
//     @Override
//     public String toString() {
//         return "HttpResponse{" +
//                 "httpVersion=" + mHttpVersion +
//                 ", status=" + mStatus +
//                 '}';
//     }
// }


import com.vincan.medialoader.tinyhttpd.HttpConstants;
import com.vincan.medialoader.tinyhttpd.response.HttpResponse;
import java.io.IOException;
import java.util.Map;

package com.vincan.medialoader.tinyhttpd.codec;



/**
 * {@link HttpResponse}的编码器
 *
 * @author vincanyang
 */
public class HttpResponseEncoder implements ResponseEncoder<HttpResponse> {

    @Override

// Path: library/src/main/java/com/vincan/medialoader/tinyhttpd/HttpConstants.java
// public final class HttpConstants {
// 
//     public final static String CRLF = "\r\n";
// 
//     public final static String SP = " ";
// 
//     public final static String COLON = ":";
// 
//     public static final String CHARSET_DEFAULT = "UTF-8";
// 
//     public static final String PARAM_SIGN = "sign";
// 
//     public static final String PARAM_TIMESTAMP = "timestamp";
// 
//     private HttpConstants() {
//         // Unused
//     }
// }
// 
// Path: library/src/main/java/com/vincan/medialoader/tinyhttpd/response/HttpResponse.java
// public final class HttpResponse implements Response {
// 
//     private HttpHeaders mHeaders = new HttpHeaders();
// 
//     private final HttpVersion mHttpVersion = HttpVersion.HTTP_1_1;
// 
//     private HttpStatus mStatus = HttpStatus.OK;
// 
//     private final SocketChannel mChannel;
// 
//     private ByteBuffer mResponseByteBuffer = ByteBuffer.allocate(Util.DEFAULT_BUFFER_SIZE);
// 
//     public HttpResponse(SocketChannel channel) {
//         mChannel = channel;
//     }
// 
//     @Override
//     public void setStatus(HttpStatus status) {
//         mStatus = status;
//     }
// 
//     @Override
//     public void addHeader(String key, String value) {
//         mHeaders.put(key, value);
//     }
// 
//     @Override
//     public void write(byte[] bytes) throws IOException {
//         write(bytes, 0, bytes.length);
//     }
// 
//     @Override
//     public void write(byte[] bytes, int offset, int length) throws IOException {
//         mResponseByteBuffer.put(bytes, offset, length);
//         mResponseByteBuffer.flip();
//         while (mResponseByteBuffer.hasRemaining()) {//XXX 巨坑：ByteBuffer会缓存，可能不会全部写入channel
//             mChannel.write(mResponseByteBuffer);
//         }
//         mResponseByteBuffer.clear();
//     }
// 
//     @Override
//     public HttpStatus status() {
//         return mStatus;
//     }
// 
//     @Override
//     public HttpVersion protocol() {
//         return mHttpVersion;
//     }
// 
//     @Override
//     public HttpHeaders headers() {
//         return mHeaders;
//     }
// 
//     @Override
//     public String toString() {
//         return "HttpResponse{" +
//                 "httpVersion=" + mHttpVersion +
//                 ", status=" + mStatus +
//                 '}';
//     }
// }


// Path: library/src/main/java/com/vincan/medialoader/tinyhttpd/codec/HttpResponseEncoder.java
import com.vincan.medialoader.tinyhttpd.HttpConstants;
import com.vincan.medialoader.tinyhttpd.response.HttpResponse;
import java.io.IOException;
import java.util.Map;

package com.vincan.medialoader.tinyhttpd.codec;



/**
 * {@link HttpResponse}的编码器
 *
 * @author vincanyang
 */
public class HttpResponseEncoder implements ResponseEncoder<HttpResponse> {

    @Override

    public byte[] encode(HttpResponse response) throws IOException {
