// Path: src/main/java/org/cleverframe/fastdfs/constant/OtherConstants.java
// public final class OtherConstants {
//     /**
//      * for overwrite all old metadata
//      */
//     public static final byte STORAGE_SET_METADATA_FLAG_OVERWRITE = 'O';
// 
//     /**
//      * for replace, insert when the meta item not exist, otherwise update it
//      */
//     public static final byte STORAGE_SET_METADATA_FLAG_MERGE = 'M';
//     public static final int FDFS_PROTO_PKG_LEN_SIZE = 8;
//     public static final int FDFS_PROTO_CMD_SIZE = 1;
//     public static final int FDFS_PROTO_CONNECTION_LEN = 4;
//     public static final int FDFS_GROUP_NAME_MAX_LEN = 16;
//     public static final int FDFS_IPADDR_SIZE = 16;
//     public static final int FDFS_DOMAIN_NAME_MAX_SIZE = 128;
//     public static final int FDFS_VERSION_SIZE = 6;
//     public static final int FDFS_STORAGE_ID_MAX_SIZE = 16;
// 
//     public static final String FDFS_RECORD_SEPERATOR = "\u0001";
//     public static final String FDFS_FIELD_SEPERATOR = "\u0002";
// 
//     public static final int TRACKER_QUERY_STORAGE_FETCH_BODY_LEN = FDFS_GROUP_NAME_MAX_LEN + FDFS_IPADDR_SIZE - 1 + FDFS_PROTO_PKG_LEN_SIZE;
//     public static final int TRACKER_QUERY_STORAGE_STORE_BODY_LEN = FDFS_GROUP_NAME_MAX_LEN + FDFS_IPADDR_SIZE + FDFS_PROTO_PKG_LEN_SIZE;
// 
//     /**
//      * 报文头中命令位置
//      */
//     public static final int PROTO_HEADER_CMD_INDEX = FDFS_PROTO_PKG_LEN_SIZE;
// 
//     /**
//      * 报文头中状态码位置
//      */
//     public static final int PROTO_HEADER_STATUS_INDEX = FDFS_PROTO_PKG_LEN_SIZE + 1;
// 
//     public static final byte FDFS_FILE_EXT_NAME_MAX_LEN = 6;
//     public static final byte FDFS_FILE_PREFIX_MAX_LEN = 16;
//     public static final byte FDFS_FILE_PATH_LEN = 10;
//     public static final byte FDFS_FILENAME_BASE64_LENGTH = 27;
//     public static final byte FDFS_TRUNK_FILE_INFO_LEN = 16;
// 
//     public static final long INFINITE_FILE_SIZE = 256 * 1024L * 1024 * 1024 * 1024 * 1024L;
//     public static final long APPENDER_FILE_SIZE = INFINITE_FILE_SIZE;
//     public static final long TRUNK_FILE_MARK_SIZE = 512 * 1024L * 1024 * 1024 * 1024 * 1024L;
//     public static final long NORMAL_LOGIC_FILENAME_LENGTH = FDFS_FILE_PATH_LEN + FDFS_FILENAME_BASE64_LENGTH + FDFS_FILE_EXT_NAME_MAX_LEN + 1;
//     public static final long TRUNK_LOGIC_FILENAME_LENGTH = NORMAL_LOGIC_FILENAME_LENGTH + FDFS_TRUNK_FILE_INFO_LEN;
// }
// 
// Path: src/main/java/org/cleverframe/fastdfs/model/MateData.java
// public class MateData implements Serializable {
// 
//     private String name;
// 
//     private String value;
// 
//     public MateData() {
//     }
// 
//     public MateData(String name) {
//         this.name = name;
//     }
// 
//     public MateData(String name, String value) {
//         this.name = name;
//         this.value = value;
//     }
// 
//     public String getName() {
//         return this.name;
//     }
// 
//     public String getValue() {
//         return this.value;
//     }
// 
//     public void setName(String name) {
//         this.name = name;
//     }
// 
//     public void setValue(String value) {
//         this.value = value;
//     }
// 
//     @Override
//     public int hashCode() {
//         final int prime = 31;
//         int result = 1;
//         result = prime * result + ((name == null) ? 0 : name.hashCode());
//         result = prime * result + ((value == null) ? 0 : value.hashCode());
//         return result;
//     }
// 
//     @Override
//     public boolean equals(Object obj) {
//         if (this == obj)
//             return true;
//         if (obj == null)
//             return false;
//         if (getClass() != obj.getClass())
//             return false;
//         MateData other = (MateData) obj;
//         if (name == null) {
//             if (other.name != null)
//                 return false;
//         } else if (!name.equals(other.name))
//             return false;
//         if (value == null) {
//             if (other.value != null)
//                 return false;
//         } else if (!value.equals(other.value))
//             return false;
//         return true;
//     }
// 
//     @Override
//     public String toString() {
//         return "NameValuePair [name=" + name + ", value=" + value + "]";
//     }
// }


import org.cleverframe.fastdfs.constant.OtherConstants;
import org.cleverframe.fastdfs.model.MateData;
import java.nio.charset.Charset;
import java.util.HashSet;
import java.util.Set;
package org.cleverframe.fastdfs.utils;



/**
 * 文件标签（元数据）映射对象
 * 作者：LiZW <br/>
 * 创建时间：2016/11/20 1:52 <br/>
 */
public class MetadataMapperUtils {

    private MetadataMapperUtils() {
    }

    /**
     * 将元数据映射为byte
     */
// Path: src/main/java/org/cleverframe/fastdfs/constant/OtherConstants.java
// public final class OtherConstants {
//     /**
//      * for overwrite all old metadata
//      */
//     public static final byte STORAGE_SET_METADATA_FLAG_OVERWRITE = 'O';
// 
//     /**
//      * for replace, insert when the meta item not exist, otherwise update it
//      */
//     public static final byte STORAGE_SET_METADATA_FLAG_MERGE = 'M';
//     public static final int FDFS_PROTO_PKG_LEN_SIZE = 8;
//     public static final int FDFS_PROTO_CMD_SIZE = 1;
//     public static final int FDFS_PROTO_CONNECTION_LEN = 4;
//     public static final int FDFS_GROUP_NAME_MAX_LEN = 16;
//     public static final int FDFS_IPADDR_SIZE = 16;
//     public static final int FDFS_DOMAIN_NAME_MAX_SIZE = 128;
//     public static final int FDFS_VERSION_SIZE = 6;
//     public static final int FDFS_STORAGE_ID_MAX_SIZE = 16;
// 
//     public static final String FDFS_RECORD_SEPERATOR = "\u0001";
//     public static final String FDFS_FIELD_SEPERATOR = "\u0002";
// 
//     public static final int TRACKER_QUERY_STORAGE_FETCH_BODY_LEN = FDFS_GROUP_NAME_MAX_LEN + FDFS_IPADDR_SIZE - 1 + FDFS_PROTO_PKG_LEN_SIZE;
//     public static final int TRACKER_QUERY_STORAGE_STORE_BODY_LEN = FDFS_GROUP_NAME_MAX_LEN + FDFS_IPADDR_SIZE + FDFS_PROTO_PKG_LEN_SIZE;
// 
//     /**
//      * 报文头中命令位置
//      */
//     public static final int PROTO_HEADER_CMD_INDEX = FDFS_PROTO_PKG_LEN_SIZE;
// 
//     /**
//      * 报文头中状态码位置
//      */
//     public static final int PROTO_HEADER_STATUS_INDEX = FDFS_PROTO_PKG_LEN_SIZE + 1;
// 
//     public static final byte FDFS_FILE_EXT_NAME_MAX_LEN = 6;
//     public static final byte FDFS_FILE_PREFIX_MAX_LEN = 16;
//     public static final byte FDFS_FILE_PATH_LEN = 10;
//     public static final byte FDFS_FILENAME_BASE64_LENGTH = 27;
//     public static final byte FDFS_TRUNK_FILE_INFO_LEN = 16;
// 
//     public static final long INFINITE_FILE_SIZE = 256 * 1024L * 1024 * 1024 * 1024 * 1024L;
//     public static final long APPENDER_FILE_SIZE = INFINITE_FILE_SIZE;
//     public static final long TRUNK_FILE_MARK_SIZE = 512 * 1024L * 1024 * 1024 * 1024 * 1024L;
//     public static final long NORMAL_LOGIC_FILENAME_LENGTH = FDFS_FILE_PATH_LEN + FDFS_FILENAME_BASE64_LENGTH + FDFS_FILE_EXT_NAME_MAX_LEN + 1;
//     public static final long TRUNK_LOGIC_FILENAME_LENGTH = NORMAL_LOGIC_FILENAME_LENGTH + FDFS_TRUNK_FILE_INFO_LEN;
// }
// 
// Path: src/main/java/org/cleverframe/fastdfs/model/MateData.java
// public class MateData implements Serializable {
// 
//     private String name;
// 
//     private String value;
// 
//     public MateData() {
//     }
// 
//     public MateData(String name) {
//         this.name = name;
//     }
// 
//     public MateData(String name, String value) {
//         this.name = name;
//         this.value = value;
//     }
// 
//     public String getName() {
//         return this.name;
//     }
// 
//     public String getValue() {
//         return this.value;
//     }
// 
//     public void setName(String name) {
//         this.name = name;
//     }
// 
//     public void setValue(String value) {
//         this.value = value;
//     }
// 
//     @Override
//     public int hashCode() {
//         final int prime = 31;
//         int result = 1;
//         result = prime * result + ((name == null) ? 0 : name.hashCode());
//         result = prime * result + ((value == null) ? 0 : value.hashCode());
//         return result;
//     }
// 
//     @Override
//     public boolean equals(Object obj) {
//         if (this == obj)
//             return true;
//         if (obj == null)
//             return false;
//         if (getClass() != obj.getClass())
//             return false;
//         MateData other = (MateData) obj;
//         if (name == null) {
//             if (other.name != null)
//                 return false;
//         } else if (!name.equals(other.name))
//             return false;
//         if (value == null) {
//             if (other.value != null)
//                 return false;
//         } else if (!value.equals(other.value))
//             return false;
//         return true;
//     }
// 
//     @Override
//     public String toString() {
//         return "NameValuePair [name=" + name + ", value=" + value + "]";
//     }
// }


// Path: src/main/java/org/cleverframe/fastdfs/utils/MetadataMapperUtils.java
import org.cleverframe.fastdfs.constant.OtherConstants;
import org.cleverframe.fastdfs.model.MateData;
import java.nio.charset.Charset;
import java.util.HashSet;
import java.util.Set;

package org.cleverframe.fastdfs.utils;



/**
 * 文件标签（元数据）映射对象
 * 作者：LiZW <br/>
 * 创建时间：2016/11/20 1:52 <br/>
 */
public class MetadataMapperUtils {

    private MetadataMapperUtils() {
    }

    /**
     * 将元数据映射为byte
     */
    public static byte[] toByte(Set<MateData> metadataSet, Charset charset) {