package kieker.common.record.misc;

import java.nio.BufferOverflowException;
import kieker.common.exception.RecordInstantiationException;
import kieker.common.record.AbstractMonitoringRecord;
import kieker.common.record.io.IValueDeserializer;
import kieker.common.record.io.IValueSerializer;

/**
 * @author Christian Wulf
 *         API compatibility: Kieker 1.15.0
 *
 * @since 1.13
 */
public class HostApplicationMetaData extends AbstractMonitoringRecord {

    /**
     * Descriptive definition of the serialization size of the record.
     */
    public static final int SIZE = // HostApplicationMetaData.systemName
    TYPE_SIZE_STRING + // HostApplicationMetaData.ipAddress
    TYPE_SIZE_STRING + // HostApplicationMetaData.hostname
    TYPE_SIZE_STRING + // HostApplicationMetaData.applicationName
    TYPE_SIZE_STRING;

    public static final Class<?>[] TYPES = { // HostApplicationMetaData.systemName
    String.class, // HostApplicationMetaData.ipAddress
    String.class, // HostApplicationMetaData.hostname
    String.class, // HostApplicationMetaData.applicationName
    String.class };

    /**
     * property name array.
     */
    public static final String[] VALUE_NAMES = { "systemName", "ipAddress", "hostname", "applicationName" };

    public static final String SYSTEM_NAME = "";

    public static final String IP_ADDRESS = "";

    public static final String HOSTNAME = "";

    public static final String APPLICATION_NAME = "";

    private static final long serialVersionUID = 5425789809172379297L;

    /**
     * property declarations.
     */
    private final String systemName;

    private final String ipAddress;

    private final String hostname;

    private final String applicationName;

    /**
     * Creates a new instance of this class using the given parameters.
     *
     * @param systemName
     *            systemName
     * @param ipAddress
     *            ipAddress
     * @param hostname
     *            hostname
     * @param applicationName
     *            applicationName
     */
    public HostApplicationMetaData(final String systemName, final String ipAddress, final String hostname, final String applicationName) {
        this.systemName = systemName == null ? "" : systemName;
        this.ipAddress = ipAddress == null ? "" : ipAddress;
        this.hostname = hostname == null ? "" : hostname;
        this.applicationName = applicationName == null ? "" : applicationName;
    }

    /**
     * @param deserializer
     *            The deserializer to use
     * @throws RecordInstantiationException
     *             when the record could not be deserialized
     */
    public HostApplicationMetaData(final IValueDeserializer deserializer) throws RecordInstantiationException {
        this.systemName = deserializer.getString();
        this.ipAddress = deserializer.getString();
        this.hostname = deserializer.getString();
        this.applicationName = deserializer.getString();
    }

    @Override
    public void serialize(final IValueSerializer serializer) throws BufferOverflowException {
        serializer.putString(this.getSystemName());
        serializer.putString(this.getIpAddress());
        serializer.putString(this.getHostname());
        serializer.putString(this.getApplicationName());
    }

    @Override
    public Class<?>[] getValueTypes() {
        // NOPMD
        return TYPES;
    }

    @Override
    public String[] getValueNames() {
        // NOPMD
        return VALUE_NAMES;
    }

    @Override
    public int getSize() {
        return SIZE;
    }

    @Override
    public boolean equals(final Object obj) {
        if (obj == null) {
            return false;
        }
        if (obj == this) {
            return true;
        }
        if (obj.getClass() != this.getClass()) {
            return false;
        }
        final HostApplicationMetaData castedRecord = (HostApplicationMetaData) obj;
        if (this.getLoggingTimestamp() != castedRecord.getLoggingTimestamp()) {
            return false;
        }
        if (!this.getSystemName().equals(castedRecord.getSystemName())) {
            return false;
        }
        if (!this.getIpAddress().equals(castedRecord.getIpAddress())) {
            return false;
        }
        if (!this.getHostname().equals(castedRecord.getHostname())) {
            return false;
        }
        if (!this.getApplicationName().equals(castedRecord.getApplicationName())) {
            return false;
        }
        return true;
    }

    @Override
    public int hashCode() {
        int code = 0;
        code += this.getSystemName().hashCode();
        code += this.getIpAddress().hashCode();
        code += this.getHostname().hashCode();
        code += this.getApplicationName().hashCode();
        return code;
    }

    public final String getSystemName() {
        return this.systemName;
    }

    public final String getIpAddress() {
        return this.ipAddress;
    }

    public final String getHostname() {
        return this.hostname;
    }

    public final String getApplicationName() {
        return this.applicationName;
    }

    @Override
    public String toString() {
        String result = "HostApplicationMetaData: ";
        res

        result += this.getSystemName() + ", ";
        result += "ipAddress = ";
        result += this.getIpAddress() + ", ";
        result += "hostname = ";
        result += this.getHostname() + ", ";
        result += "applicationName = ";
        result += this.getApplicationName() + ", ";
        return result;
    }
}


if (obj.getClass() != this.getClass()) {
            return false;
        }

package kieker.common.record.misc;

import java.nio.BufferOverflowException;
import kieker.common.exception.RecordInstantiationException;
import kieker.common.record.AbstractMonitoringRecord;
import kieker.common.record.io.IValueDeserializer;
import kieker.common.record.io.IValueSerializer;

/**
 * @author Christian Wulf
 *         API compatibility: Kieker 1.15.0
 *
 * @since 1.13
 */
public class HostApplicationMetaData extends AbstractMonitoringRecord {

    /**
     * Descriptive definition of the serialization size of the record.
     */
    public static final int SIZE = // HostApplicationMetaData.systemName
    TYPE_SIZE_STRING + // HostApplicationMetaData.ipAddress
    TYPE_SIZE_STRING + // HostApplicationMetaData.hostname
    TYPE_SIZE_STRING + // HostApplicationMetaData.applicationName
    TYPE_SIZE_STRING;

    public static final Class<?>[] TYPES = { // HostApplicationMetaData.systemName
    String.class, // HostApplicationMetaData.ipAddress
    String.class, // HostApplicationMetaData.hostname
    String.class, // HostApplicationMetaData.applicationName
    String.class };

    /**
     * property name array.
     */
    public static final String[] VALUE_NAMES = { "systemName", "ipAddress", "hostname", "applicationName" };

    public static final String SYSTEM_NAME = "";

    public static final String IP_ADDRESS = "";

    public static final String HOSTNAME = "";

    public static final String APPLICATION_NAME = "";

    private static final long serialVersionUID = 5425789809172379297L;

    /**
     * property declarations.
     */
    private final String systemName;

    private final String ipAddress;

    private final String hostname;

    private final String applicationName;

    /**
     * Creates a new instance of this class using the given parameters.
     *
     * @param systemName
     *            systemName
     * @param ipAddress
     *            ipAddress
     * @param hostname
     *            hostname
     * @param applicationName
     *            applicationName
     */
    public HostApplicationMetaData(final String systemName, final String ipAddress, final String hostname, final String applicationName) {
        this.systemName = systemName == null ? "" : systemName;
        this.ipAddress = ipAddress == null ? "" : ipAddress;
        this.hostname = hostname == null ? "" : hostname;
        this.applicationName = applicationName == null ? "" : applicationName;
    }

    /**
     * @param deserializer
     *            The deserializer to use
     * @throws RecordInstantiationException
     *             when the record could not be deserialized
     */
    public HostApplicationMetaData(final IValueDeserializer deserializer) throws RecordInstantiationException {
        this.systemName = deserializer.getString();
        this.ipAddress = deserializer.getString();
        this.hostname = deserializer.getString();
        this.applicationName = deserializer.getString();
    }

    @Override
    public void serialize(final IValueSerializer serializer) throws BufferOverflowException {
        serializer.putString(this.getSystemName());
        serializer.putString(this.getIpAddress());
        serializer.putString(this.getHostname());
        serializer.putString(this.getApplicationName());
    }

    @Override
    public Class<?>[] getValueTypes() {
        // NOPMD
        return TYPES;
    }

    @Override
    public String[] getValueNames() {
        // NOPMD
        return VALUE_NAMES;
    }

    @Override
    public int getSize() {
        return SIZE;
    }

    @Override
    public boolean equals(final Object obj) {
        if (obj == null) {
            return false;
        }
        if (obj == this) {
            return true;
        }

        final HostApplicationMetaData castedRecord = (HostApplicationMetaData) obj;
        if (this.getLoggingTimestamp() != castedRecord.getLoggingTimestamp()) {
            return false;
        }
        if (!this.getSystemName().equals(castedRecord.getSystemName())) {
            return false;
        }
        if (!this.getIpAddress().equals(castedRecord.getIpAddress())) {
            return false;
        }
        if (!this.getHostname().equals(castedRecord.getHostname())) {
            return false;
        }
        if (!this.getApplicationName().equals(castedRecord.getApplicationName())) {
            return false;
        }
        return true;
    }

    @Override
    public int hashCode() {
        int code = 0;
        code += this.getSystemName().hashCode();
        code += this.getIpAddress().hashCode();
        code += this.getHostname().hashCode();
        code += this.getApplicationName().hashCode();
        return code;
    }

    public final String getSystemName() {
        return this.systemName;
    }

    public final String getIpAddress() {
        return this.ipAddress;
    }

    public final String getHostname() {
        return this.hostname;
    }

    public final String getApplicationName() {
        return this.applicationName;
    }

    @Override
    public String toString() {
        String result = "HostApplicationMetaData: ";
        result += "systemName = ";
        result += this.getSystemName() + ", ";
        result += "ipAddress = ";
        result += this.getIpAddress() + ", ";
        result += "hostname = ";
        result += this.getHostname() + ", ";
        result += "applicationName = ";
        result += this.getApplicationName() + ", ";
        return result;
    }
}


@Override
    public void actionPerformed(final ActionEvent event)

package com.google.security.zynamics.binnavi.Gui.CriteriaDialog;

import java.awt.event.ActionEvent;
import javax.swing.AbstractAction;
import com.google.security.zynamics.binnavi.Gui.CriteriaDialog.ExpressionModel.CCriteriumTree;
import com.google.security.zynamics.binnavi.Gui.CriteriaDialog.ExpressionTree.JCriteriumTree;
import com.google.security.zynamics.binnavi.Gui.CriteriaDialog.Implementations.CCriteriumFunctions;

/**
 * Listener class that handles clicks on the Add Condition button.
 */
public final class CAddConditionButtonListener extends AbstractAction {

    private static final long serialVersionUID = 502859633998619670L;

    /**
     * Visible criteria tree.
     */
    private final JCriteriumTree m_jtree;

    /**
     * Backs the visible criteria tree.
     */
    private final CCriteriumTree m_ctree;

    /**
     * Provides the criterium to add.
     */
    private final CConditionBox m_selectionBox;

    /**
     * Creates a new action object.
     *
     * @param jtree Visible criteria tree.
     * @param ctree Backs the visible criteria tree.
     * @param conditionBox Provides the criterium to add.
     */
    public CAddConditionButtonListener(final JCriteriumTree jtree, final CCriteriumTree ctree, final CConditionBox conditionBox) {
        m_jtree = jtree;
        m_ctree = ctree;
        m_selectionBox = conditionBox;
    }

{
        CCriteriumFunctions.appendCriterium(m_jtree, m_ctree, m_selectionBox);
    }
}


{
        CCriteriumFunctions.appendCriterium(m_jtree, m_ctree, m_selectionBox);
    }

package com.google.security.zynamics.binnavi.Gui.CriteriaDialog;

import java.awt.event.ActionEvent;
import javax.swing.AbstractAction;
import com.google.security.zynamics.binnavi.Gui.CriteriaDialog.ExpressionModel.CCriteriumTree;
import com.google.security.zynamics.binnavi.Gui.CriteriaDialog.ExpressionTree.JCriteriumTree;
import com.google.security.zynamics.binnavi.Gui.CriteriaDialog.Implementations.CCriteriumFunctions;

/**
 * Listener class that handles clicks on the Add Condition button.
 */
public final class CAddConditionButtonListener extends AbstractAction {

    private static final long serialVersionUID = 502859633998619670L;

    /**
     * Visible criteria tree.
     */
    private final JCriteriumTree m_jtree;

    /**
     * Backs the visible criteria tree.
     */
    private final CCriteriumTree m_ctree;

    /**
     * Provides the criterium to add.
     */
    private final CConditionBox m_selectionBox;

    /**
     * Creates a new action object.
     *
     * @param jtree Visible criteria tree.
     * @param ctree Backs the visible criteria tree.
     * @param conditionBox Provides the criterium to add.
     */
    public CAddConditionButtonListener(final JCriteriumTree jtree, final CCriteriumTree ctree, final CConditionBox conditionBox) {
        m_jtree = jtree;
        m_ctree = ctree;
        m_selectionBox = conditionBox;
    }

    @Override
    public void actionPerformed(final ActionEvent event)


package com.google.security.zynamics.binnavi.Gui.CriteriaDialog;

import java.awt.event.ActionEvent;
import javax.swing.AbstractAction;
import com.google.security.zynamics.binnavi.Gui.CriteriaDialog.ExpressionModel.CCriteriumTree;
import com.google.security.zynamics.binnavi.Gui.CriteriaDialog.ExpressionTree.JCriteriumTree;
import com.google.security.zynamics.binnavi.Gui.CriteriaDialog.Implementations.CCriteriumFunctions;

/**
 * Listener class that handles clicks on the Add Condition button.
 */
public final class CAddConditionButtonListener extends AbstractAction {

    private static final long serialVersionUID = 502859633998619670L;

    /**
     * Visible criteria tree.
     */
    private final JCriteriumTree m_jtree;

    /**
     * Backs the visible criteria tree.
     */
    private final CCriteriumTree m_ctree;

    /**
     * Provides the criterium to add.
     */
    private final CConditionBox m_selectionBox;

    /**
     * Creates a new action object.
     *
     * @param jtree Visible criteria tree.
     * @param ctree Backs the visible criteria tree.
     * @param conditionBox Provides the criterium to add.
     */
    public CAddConditionButtonListener(final JCriteriumTree jtree, final CCriteriumTree ctree, final CConditionBox conditionBox) {
        m_jtree = jtree;
        m_ctree = ctree;
        m_selectionBox = conditionBox;
    }

    @Override
    public void actionPerformed(final ActionEvent event) {
        CCriteriumFunctions.app


package org.voovan.http.message.packet;

import org.voovan.http.message.Request;
import org.voovan.http.server.context.WebContext;
import org.voovan.tools.log.Logger;
import java.io.UnsupportedEncodingException;
import java.net.URLDecoder;
import java.net.URLEncoder;
import java.util.Map;
import java.util.Map.Entry;

/**
 *  HTTP 的 cookie 对象
 * @author helyho
 *
 * Voovan Framework.
 * WebSite: http://example.com
 */
public class Cookie {

    private String domain;

    private String path;

    private int maxAge = -999999;

    private String expires;

    private boolean secure;

    private boolean httpOnly;

    private String name;

    private String value;

    private Cookie() {
    }

    public String getDomain() {
        return domain;
    }

    public void setDomain(String domain) {
        this.domain = domain;
    }

    public String getPath() {
        return path;
    }

    public void setPath(String path) {
        this.path = path;
    }

    public int getMaxAge() {
        return maxAge;
    }

    public void setMaxAge(int maxAge) {
        this.maxAge = maxAge;
    }

    public String getExpires() {
        return expires;
    }

    public void setExpires(String expires) {
        this.expires = expires;
    }

    public boolean isSecure() {
        return secure;
    }

    public void setSecure(boolean secure) {
        this.secure = secure;
    }

    public boolean isHttpOnly() {
        return httpOnly;
    }

    public void setHttpOnly(boolean httpOnly) {
        this.httpOnly = httpOnly;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

{
        try {
            return URLDecoder.decode(this.value, "UTF-8");
        } catch (UnsupportedEncodingException e) {
            Logger.error(e);
        }
        return this.value;
    }

    public void setValue(String value) {
        try {
            this.value = URLEncoder.encode(value, "UTF-8");
        } catch (UnsupportedEncodingException e) {
            Logger.error(e);
        }
    }

    @Override
    public String toString() {
        return (this.name != null || this.value != null ? (this.name + "=" + this.value) : "") + (this.domain != null ? ("; domain=" + this.domain) : "") + (this.maxAge != -999999 ? ("; max-age=" + this.maxAge) : "") + (this.path != null ? ("; path=" + this.path) : "") + (this.httpOnly ? "; httponly; " : "") + (this.secure ? "; secure" : "");
    }

    /**
     * 通过 Map 构建一个 Cookie 对象
     * @param cookieMap Cookie 属性 Map
     * @return Cookie 对象
     */
    public static Cookie buildCookie(Map<String, String> cookieMap) {
        Cookie cookie = new Cookie();
        for (Entry<String, String> cookieMapItem : cookieMap.entrySet()) {
            switch(cookieMapItem.getKey().toLowerCase()) {
                case "domain":
                    cookie.setDomain(cookieMapItem.getValue());
                    break;
                case "path":
                    cookie.setPath(cookieMapItem.getValue());
                    break;
                case "max-age":
                    cookie.setMaxAge(Integer.parseInt(cookieMapItem.getValue()));
                    break;
                case "secure":
                    cookie.setSecure(true);
                    break;
                case "httponly":
                    cookie.setHttpOnly(true);
                    break;
                case "expires":
                    cookie.setExpires(cookieMapItem.getValue());
                    break;
                default:
                    cookie.setName(cookieMapItem.getKey());
                    cookie.setValue(cookieMapItem.getValue());
                    break;
            }
        }
        return cookie;
    }

    /**
     * 创建一个 Cookie
     * @param domain	cookie的受控域
     * @param path      cookie路径
     * @param name		名称
     * @param value		值
     * @param maxAge	失效时间,单位秒
     * @param isHttpOnly httpOnly属性
     * @return Cookie 对象
     */
    public static Cookie newInstance(String domain, String path, String name, String value, int maxAge, boolean isHttpOnly) {
        Cookie cookie = new Cookie();
        cookie.setName(name);
        cookie.setValue(value);
        cookie.setPath(path);
        cookie.setDomain(domain);
        cookie.setMaxAge(maxAge);
        cookie.setHttpOnly(isHttpOnly);
        return cookie;
    }

    /**
     * 创建一个 Cookie
     * @param request	请求对象
     * @param path      cookie路径
     * @param name		名称
     * @param value		值
     * @param maxAge	失效时间,单位秒
     * @param isHttpOnly httpOnly属性
     * @return Cookie 对象
     */
    public static Cookie newInstance(Request request, String path, String name, String value, int maxAge, boolean isHttpOnly) {
        String Host = request.header().get("Host");
        String domain = Host.split(":")[0];
        return newInstance(domain, path, name, value, maxAge, isHttpOnly);
    }

    /**
     * 创建一个 Cookie
     * @param request	请求对象
     * @param path      cookie路径
     * @param name		名称
     * @param value		值
     * @return Cookie 对象
     */
    public static Cookie newInstance(Request request, String path, String name, String value) {
        return newInstance(request, path, name, value, WebContext.getWebServerConfig().getSessionTimeout() * 60, false);
    }

    /**
     * 创建一个 Cookie
     * @param request	请求对象
     * @param name		名称
     * @param value		值
     * @return Cookie 对象
     */
    public static Cookie newInstance(Request request, String name, String value) {
        return newInstance(request, "/", name, value, WebContext.getWebServerConfig().getSessionTimeout() * 60, false);
    }
}


package org.voovan.http.message.packet;

import org.voovan.http.message.Request;
import org.voovan.http.server.context.WebContext;
import org.voovan.tools.log.Logger;
import java.io.UnsupportedEncodingException;
import java.net.URLDecoder;
import java.net.URLEncoder;
import java.util.Map;
import java.util.Map.Entry;

/**
 *  HTTP 的 cookie 对象
 * @author helyho
 *
 * Voovan Framework.
 * WebSite: http://example.com
 */
public class Cookie {

    private String domain;

    private String path;

    private int maxAge = -999999;

    private String expires;

    private boolean secure;

    private boolean httpOnly;

    private String name;

    private String value;

    private Cookie() {
    }

    public String getDomain() {
        return domain;
    }

    public void setDomain(String domain) {
        this.domain = domain;
    }

    public String getPath() {
        return path;
    }

    public void setPath(String path) {
        this.path = path;
    }

    public int getMaxAge() {
        return maxAge;
    }

    public void setMaxAge(int maxAge) {
        this.maxAge = maxAge;
    }

    public String getExpires() {
        return expires;
    }

    public void setExpires(String expires) {
        this.expires = expires;
    }

    public boolean isSecure() {
        return secure;
    }

    public void setSecure(boolean secure) {
        this.secure = secure;
    }

    public boolean isHttpOnly() {
        return httpOnly;
    }

    public void setHttpOnly(boolean httpOnly) {
        this.httpOnly = httpOnly;
    }

    public String getName() {
        return name;
    }

    public void setName(String name)

    public String getValue() {
        try {
            return URLDecoder.decode(this.value, "UTF-8");
        } catch (UnsupportedEncodingException e) {
            Logger.error(e);
        }
        return this.value;
    }

    public void setValue(String value) {
        try {
            this.value = URLEncoder.encode(value, "UTF-8");
        } catch (UnsupportedEncodingException e) {
            Logger.error(e);
        }
    }

    @Override
    public String toString() {
        return (this.name != null || this.value != null ? (this.name + "=" + this.value) : "") + (this.domain != null ? ("; domain=" + this.domain) : "") + (this.maxAge != -999999 ? ("; max-age=" + this.maxAge) : "") + (this.path != null ? ("; path=" + this.path) : "") + (this.httpOnly ? "; httponly; " : "") + (this.secure ? "; secure" : "");
    }

    /**
     * 通过 Map 构建一个 Cookie 对象
     * @param cookieMap Cookie 属性 Map
     * @return Cookie 对象
     */
    public static Cookie buildCookie(Map<String, String> cookieMap) {
        Cookie cookie = new Cookie();
        for (Entry<String, String> cookieMapItem : cookieMap.entrySet()) {
            switch(cookieMapItem.getKey().toLowerCase()) {
                case "domain":
                    cookie.setDomain(cookieMapItem.getValue());
                    break;
                case "path":
                    cookie.setPath(cookieMapItem.getValue());
                    break;
                case "max-age":
                    cookie.setMaxAge(Integer.parseInt(cookieMapItem.getValue()));
                    break;
                case "secure":
                    cookie.setSecure(true);
                    break;
                case "httponly":
                    cookie.setHttpOnly(true);
                    break;
                case "expires":
                    cookie.setExpires(cookieMapItem.getValue());
                    break;
                default:
                    cookie.setName(cookieMapItem.getKey());
                    cookie.setValue(cookieMapItem.getValue());
                    break;
            }
        }
        return cookie;
    }

    /**
     * 创建一个 Cookie
     * @param domain	cookie的受控域
     * @param path      cookie路径
     * @param name		名称
     * @param value		值
     * @param maxAge	失效时间,单位秒
     * @param isHttpOnly httpOnly属性
     * @return Cookie 对象
     */
    public static Cookie newInstance(String domain, String path, String name, String value, int maxAge, boolean isHttpOnly) {
        Cookie cookie = new Cookie();
        cookie.setName(name);
        cookie.setValue(value);
        cookie.setPath(path);
        cookie.setDomain(domain);
        cookie.setMaxAge(maxAge);
        cookie.setHttpOnly(isHttpOnly);
        return cookie;
    }

    /**
     * 创建一个 Cookie
     * @param request	请求对象
     * @param path      cookie路径
     * @param name		名称
     * @param value		值
     * @param maxAge	失效时间,单位秒
     * @param isHttpOnly httpOnly属性
     * @return Cookie 对象
     */
    public static Cookie newInstance(Request request, String path, String name, String value, int maxAge, boolean isHttpOnly) {
        String Host = request.header().get("Host");
        String domain = Host.split(":")[0];
        return newInstance(domain, path, name, value, maxAge, isHttpOnly);
    }

    /**
     * 创建一个 Cookie
     * @param request	请求对象
     * @param path      cookie路径
     * @param name		名称
     * @param value		值
     * @return Cookie 对象
     */
    public static Cookie newInstance(Request request, String path, String name, String value) {
        return newInstance(request, path, name, value, WebContext.getWebServerConfig().getSessionTimeout() * 60, false);
    }

    /**
     * 创建一个 Cookie
     * @param request	请求对象
     * @param name		名称
     * @param value		值
     * @return Cookie 对象
     */
    public static Cookie newInstance(Request request, String name, String value) {
        return newInstance(request, "/", name, value, WebContext.getWebServerConfig().getSessionTimeout() * 60, false);
    }
}


        try {
            return URLDecoder.decode(this.value, "UTF-8");
        } catch (UnsupportedEncodingException e) {
            Logger.error(e);
        }

package org.voovan.http.message.packet;

import org.voovan.http.message.Request;
import org.voovan.http.server.context.WebContext;
import org.voovan.tools.log.Logger;
import java.io.UnsupportedEncodingException;
import java.net.URLDecoder;
import java.net.URLEncoder;
import java.util.Map;
import java.util.Map.Entry;

/**
 *  HTTP 的 cookie 对象
 * @author helyho
 *
 * Voovan Framework.
 * WebSite: http://example.com
 */
public class Cookie {

    private String domain;

    private String path;

    private int maxAge = -999999;

    private String expires;

    private boolean secure;

    private boolean httpOnly;

    private String name;

    private String value;

    private Cookie() {
    }

    public String getDomain() {
        return domain;
    }

    public void setDomain(String domain) {
        this.domain = domain;
    }

    public String getPath() {
        return path;
    }

    public void setPath(String path) {
        this.path = path;
    }

    public int getMaxAge() {
        return maxAge;
    }

    public void setMaxAge(int maxAge) {
        this.maxAge = maxAge;
    }

    public String getExpires() {
        return expires;
    }

    public void setExpires(String expires) {
        this.expires = expires;
    }

    public boolean isSecure() {
        return secure;
    }

    public void setSecure(boolean secure) {
        this.secure = secure;
    }

    public boolean isHttpOnly() {
        return httpOnly;
    }

    public void setHttpOnly(boolean httpOnly) {
        this.httpOnly = httpOnly;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getValue() {

        return this.value;
    }

    public void setValue(String value) {
        try {
            this.value = URLEncoder.encode(value, "UTF-8");
        } catch (UnsupportedEncodingException e) {
            Logger.error(e);
        }
    }

    @Override
    public String toString() {
        return (this.name != null || this.value != null ? (this.name + "=" + this.value) : "") + (this.domain != null ? ("; domain=" + this.domain) : "") + (this.maxAge != -999999 ? ("; max-age=" + this.maxAge) : "") + (this.path != null ? ("; path=" + this.path) : "") + (this.httpOnly ? "; httponly; " : "") + (this.secure ? "; secure" : "");
    }

    /**
     * 通过 Map 构建一个 Cookie 对象
     * @param cookieMap Cookie 属性 Map
     * @return Cookie 对象
     */
    public static Cookie buildCookie(Map<String, String> cookieMap) {
        Cookie cookie = new Cookie();
        for (Entry<String, String> cookieMapItem : cookieMap.entrySet()) {
            switch(cookieMapItem.getKey().toLowerCase()) {
                case "domain":
                    cookie.setDomain(cookieMapItem.getValue());
                    break;
                case "path":
                    cookie.setPath(cookieMapItem.getValue());
                    break;
                case "max-age":
                    cookie.setMaxAge(Integer.parseInt(cookieMapItem.getValue()));
                    break;
                case "secure":
                    cookie.setSecure(true);
                    break;
                case "httponly":
                    cookie.setHttpOnly(true);
                    break;
                case "expires":
                    cookie.setExpires(cookieMapItem.getValue());
                    break;
                default:
                    cookie.setName(cookieMapItem.getKey());
                    cookie.setValue(cookieMapItem.getValue());
                    break;
            }
        }
        return cookie;
    }

    /**
     * 创建一个 Cookie
     * @param domain	cookie的受控域
     * @param path      cookie路径
     * @param name		名称
     * @param value		值
     * @param maxAge	失效时间,单位秒
     * @param isHttpOnly httpOnly属性
     * @return Cookie 对象
     */
    public static Cookie newInstance(String domain, String path, String name, String value, int maxAge, boolean isHttpOnly) {
        Cookie cookie = new Cookie();
        cookie.setName(name);
        cookie.setValue(value);
        cookie.setPath(path);
        cookie.setDomain(domain);
        cookie.setMaxAge(maxAge);
        cookie.setHttpOnly(isHttpOnly);
        return cookie;
    }

    /**
     * 创建一个 Cookie
     * @param request	请求对象
     * @param path      cookie路径
     * @param name		名称
     * @param value		值
     * @param maxAge	失效时间,单位秒
     * @param isHttpOnly httpOnly属性
     * @return Cookie 对象
     */
    public static Cookie newInstance(Request request, String path, String name, String value, int maxAge, boolean isHttpOnly) {
        String Host = request.header().get("Host");
        String domain = Host.split(":")[0];
        return newInstance(domain, path, name, value, maxAge, isHttpOnly);
    }

    /**
     * 创建一个 Cookie
     * @param request	请求对象
     * @param path      cookie路径
     * @param name		名称
     * @param value		值
     * @return Cookie 对象
     */
    public static Cookie newInstance(Request request, String path, String name, String value) {
        return newInstance(request, path, name, value, WebContext.getWebServerConfig().getSessionTimeout() * 60, false);
    }

    /**
     * 创建一个 Cookie
     * @param request	请求对象
     * @param name		名称
     * @param value		值
     * @return Cookie 对象
     */
    public static Cookie newInstance(Request request, String name, String value) {
        return newInstance(request, "/", name, value, WebContext.getWebServerConfig().getSessionTimeout() * 60, false);
    }
}


package org.voovan.http.message.packet;

import org.voovan.http.message.Request;
import org.voovan.http.server.context.WebContext;
import org.voovan.tools.log.Logger;
import java.io.UnsupportedEncodingException;
import java.net.URLDecoder;
import java.net.URLEncoder;
import java.util.Map;
import java.util.Map.Entry;

/**
 *  HTTP 的 cookie 对象
 * @author helyho
 *
 * Voovan Framework.
 * WebSite: http://example.com
 */
public class Cookie {

    private String domain;

    private String path;

    private int maxAge = -999999;

    private String expires;

    private boolean secure;

    private boolean httpOnly;

    private String name;

    private String value;

    private Cookie() {
    }

    public String getDomain() {
        return domain;
    }

    public void setDomain(String domain) {
        this.domain = domain;
    }

    public String getPath() {
        return path;
    }

    public void setPath(String path) {
        this.path = path;
    }

    public int getMaxAge() {
        return maxAge;
    }

    public void setMaxAge(int maxAge) {
        this.maxAge = maxAge;
    }

    public String getExpires() {
        return expires;
    }

    public void setExpires(String expires) {
        this.expires = expires;
    }

    public boolean isSecure() {
        return secure;
    }

    public void setSecure(boolean secure) {
        this.secure = secure;
    }

    public boolean isHttpOnly() {
        return httpOnly;
    }

    public void setHttpOnly(boolean httpOnly) {
        this.httpOnly = httpOnly;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getValue() {
        try {
            return URLDecoder.decode(this.value, "UTF-8");
        } catch (UnsupportedEncodingException e) {
            Logger.error(e);
        }

    }

    public void setValue(String value) {
        try {
            this.value = URLEncoder.encode(value, "UTF-8");
        } catch (UnsupportedEncodingException e) {
            Logger.error(e);
        }
    }

    @Override
    public String toString() {
        return (this.name != null || this.value != null ? (this.name + "=" + this.value) : "") + (this.domain != null ? ("; domain=" + this.domain) : "") + (this.maxAge != -999999 ? ("; max-age=" + this.maxAge) : "") + (this.path != null ? ("; path=" + this.path) : "") + (this.httpOnly ? "; httponly; " : "") + (this.secure ? "; secure" : "");
    }

    /**
     * 通过 Map 构建一个 Cookie 对象
     * @param cookieMap Cookie 属性 Map
     * @return Cookie 对象
     */
    public static Cookie buildCookie(Map<String, String> cookieMap) {
        Cookie cookie = new Cookie();
        for (Entry<String, String> cookieMapItem : cookieMap.entrySet()) {
            switch(cookieMapItem.getKey().toLowerCase()) {
                case "domain":
                    cookie.setDomain(cookieMapItem.getValue());
                    break;
                case "path":
                    cookie.setPath(cookieMapItem.getValue());
                    break;
                case "max-age":
                    cookie.setMaxAge(Integer.parseInt(cookieMapItem.getValue()));
                    break;
                case "secure":
                    cookie.setSecure(true);
                    break;
                case "httponly":
                    cookie.setHttpOnly(true);
                    break;
                case "expires":
                    cookie.setExpires(cookieMapItem.getValue());
                    break;
                default:
                    cookie.setName(cookieMapItem.getKey());
                    cookie.setValue(cookieMapItem.getValue());
                    break;
            }
        }
        return cookie;
    }

    /**
     * 创建一个 Cookie
     * @param domain	cookie的受控域
     * @param path      cookie路径
     * @param name		名称
     * @param value		值
     * @param maxAge	失效时间,单位秒
     * @param isHttpOnly httpOnly属性
     * @return Cookie 对象
     */
    public static Cookie newInstance(String domain, String path, String name, String value, int maxAge, boolean isHttpOnly) {
        Cookie cookie = new Cookie();
        cookie.setName(name);
        cookie.setValue(value);
        cookie.setPath(path);
        cookie.setDomain(domain);
        cookie.setMaxAge(maxAge);
        cookie.setHttpOnly(isHttpOnly);
        return cookie;
    }

    /**
     * 创建一个 Cookie
     * @param request	请求对象
     * @param path      cookie路径
     * @param name		名称
     * @param value		值
     * @param maxAge	失效时间,单位秒
     * @param isHttpOnly httpOnly属性
     * @return Cookie 对象
     */
    public static Cookie newInstance(Request request, String path, String name, String value, int maxAge, boolean isHttpOnly) {
        String Host = request.header().get("Host");
        String domain = Host.split(":")[0];
        return newInstance(domain, path, name, value, maxAge, isHttpOnly);
    }

    /**
     * 创建一个 Cookie
     * @param request	请求对象
     * @param path      cookie路径
     * @param name		名称
     * @param value		值
     * @return Cookie 对象
     */
    public static Cookie newInstance(Request request, String path, String name, String value) {
        return newInstance(request, path, name, value, WebContext.getWebServerConfig().getSessionTimeout() * 60, false);
    }

    /**
     * 创建一个 Cookie
     * @param request	请求对象
     * @param name		名称
     * @param value		值
     * @return Cookie 对象
     */
    public static Cookie newInstance(Request request, String name, String value) {
        return newInstance(request, "/", name, value, WebContext.getWebServerConfig().getSessionTimeout() * 60, false);
    }
}


package org.voovan.http.message.packet;

import org.voovan.http.message.Request;
import org.voovan.http.server.context.WebContext;
import org.voovan.tools.log.Logger;
import java.io.UnsupportedEncodingException;
import java.net.URLDecoder;
import java.net.URLEncoder;
import java.util.Map;
import java.util.Map.Entry;

/**
 *  HTTP 的 cookie 对象
 * @author helyho
 *
 * Voovan Framework.
 * WebSite: http://example.com
 */
public class Cookie {

    private String domain;

    private String path;

    private int maxAge = -999999;

    private String expires;

    private boolean secure;

    private boolean httpOnly;

    private String name;

    private String value;

    private Cookie() {
    }

    public String getDomain() {
        return domain;
    }

    public void setDomain(String domain) {
        this.domain = domain;
    }

    public String getPath() {
        return path;
    }

    public void setPath(String path) {
        this.path = path;
    }

    public int getMaxAge() {
        return maxAge;
    }

    public void setMaxAge(int maxAge) {
        this.maxAge = maxAge;
    }

    public String getExpires() {
        return expires;
    }

    public void setExpires(String expires) {
        this.expires = expires;
    }

    public boolean isSecure() {
        return secure;
    }

    public void setSecure(boolean secure) {
        this.secure = secure;
    }

    public boolean isHttpOnly() {
        return httpOnly;
    }

    public void setHttpOnly(boolean httpOnly) {
        this.httpOnly = httpOnly;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getValue() {
        try {
            return URLDecoder.decode(this.value, "UTF-8");
        } catch (UnsupportedEncodingException e) {
            Logger.error(e);
        }
        return this.value;

    public void setValue(String value) {
        try {
            this.value = URLEncoder.encode(value, "UTF-8");
        } catch (UnsupportedEncodingException e) {
            Logger.error(e);
        }
    }

    @Override
    public String toString() {
        return (this.name != null || this.value != null ? (this.name + "=" + this.value) : "") + (this.domain != null ? ("; domain=" + this.domain) : "") + (this.maxAge != -999999 ? ("; max-age=" + this.maxAge) : "") + (this.path != null ? ("; path=" + this.path) : "") + (this.httpOnly ? "; httponly; " : "") + (this.secure ? "; secure" : "");
    }

    /**
     * 通过 Map 构建一个 Cookie 对象
     * @param cookieMap Cookie 属性 Map
     * @return Cookie 对象
     */
    public static Cookie buildCookie(Map<String, String> cookieMap) {
        Cookie cookie = new Cookie();
        for (Entry<String, String> cookieMapItem : cookieMap.entrySet()) {
            switch(cookieMapItem.getKey().toLowerCase()) {
                case "domain":
                    cookie.setDomain(cookieMapItem.getValue());
                    break;
                case "path":
                    cookie.setPath(cookieMapItem.getValue());
                    break;
                case "max-age":
                    cookie.setMaxAge(Integer.parseInt(cookieMapItem.getValue()));
                    break;
                case "secure":
                    cookie.setSecure(true);
                    break;
                case "httponly":
                    cookie.setHttpOnly(true);
                    break;
                case "expires":
                    cookie.setExpires(cookieMapItem.getValue());
                    break;
                default:
                    cookie.setName(cookieMapItem.getKey());
                    cookie.setValue(cookieMapItem.getValue());
                    break;
            }
        }
        return cookie;
    }

    /**
     * 创建一个 Cookie
     * @param domain	cookie的受控域
     * @param path      cookie路径
     * @param name		名称
     * @param value		值
     * @param maxAge	失效时间,单位秒
     * @param isHttpOnly httpOnly属性
     * @return Cookie 对象
     */
    public static Cookie newInstance(String domain, String path, String name, String value, int maxAge, boolean isHttpOnly) {
        Cookie cookie = new Cookie();
        cookie.setName(name);
        cookie.setValue(value);
        cookie.setPath(path);
        cookie.setDomain(domain);
        cookie.setMaxAge(maxAge);
        cookie.setHttpOnly(isHttpOnly);
        return cookie;
    }

    /**
     * 创建一个 Cookie
     * @param request	请求对象
     * @param path      cookie路径
     * @param name		名称
     * @param value		值
     * @param maxAge	失效时间,单位秒
     * @param isHttpOnly httpOnly属性
     * @return Cookie 对象
     */
    public static Cookie newInstance(Request request, String path, String name, String value, int maxAge, boolean isHttpOnly) {
        String Host = request.header().get("Host");
        String domain = Host.split(":")[0];
        return newInstance(domain, path, name, value, maxAge, isHttpOnly);
    }

    /**
     * 创建一个 Cookie
     * @param request	请求对象
     * @param path      cookie路径
     * @param name		名称
     * @param value		值
     * @return Cookie 对象
     */
    public static Cookie newInstance(Request request, String path, String name, String value) {
        return newInstance(request, path, name, value, WebContext.getWebServerConfig().getSessionTimeout() * 60, false);
    }

    /**
     * 创建一个 Cookie
     * @param request	请求对象
     * @param name		名称
     * @param value		值
     * @return Cookie 对象
     */
    public static Cookie newInstance(Request request, String name, String value) {
        return newInstance(request, "/", name, value, WebContext.getWebServerConfig().getSessionTimeout() * 60, false);
    }
}


package org.voovan.http.message.packet;

import org.voovan.http.message.Request;
import org.voovan.http.server.context.WebContext;
import org.voovan.tools.log.Logger;
import java.io.UnsupportedEncodingException;
import java.net.URLDecoder;
import java.net.URLEncoder;
import java.util.Map;
import java.util.Map.Entry;

/**
 *  HTTP 的 cookie 对象
 * @author helyho
 *
 * Voovan Framework.
 * WebSite: http://example.com
 */
public class Cookie {

    private String domain;

    private String path;

    private int maxAge = -999999;

    private String expires;

    private boolean secure;

    private boolean httpOnly;

    private String name;

    private String value;

    private Cookie() {
    }

    public String getDomain() {
        return domain;
    }

    public void setDomain(String domain) {
        this.domain = domain;
    }

    public String getPath() {
        return path;
    }

    public void setPath(String path) {
        this.path = path;
    }

    public int getMaxAge() {
        return maxAge;
    }

    public void setMaxAge(int maxAge) {
        this.maxAge = maxAge;
    }

    public String getExpires() {
        return expires;
    }

    public void setExpires(String expires) {
        this.expires = expires;
    }

    public boolean isSecure() {
        return secure;
    }

    public void setSecure(boolean secure) {
        this.secure = secure;
    }

    public boolean isHttpOnly() {
        return httpOnly;
    }

    public void setHttpOnly(boolean httpOnly) {
        this.httpOnly = httpOnly;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getValue() {
        try {
            return URLDecoder.decode(this.value, "UTF-8");
        } catch (UnsupportedEncodingException e) {
            Logger.error(e);
        }
        return this.value;
    }

    public void setValue(String value) {
        try {
            this.value = URLEncoder.encode(value, "UTF-8");
        } catch (UnsupportedEncodingException e) {
            Logger.error(e);
        }
    }

    @Override
    public String toString() {
        return (this.name != null || this.value != null ? (this.name + "=" + this.value) : "") + (this.domain != null ? ("; domain=" + this.domain) : "") + (this.maxAge != -999999 ? ("; max-age=" + this.maxAge) : "") + (this.path != null ? ("; path=" + this.path) : "") + (this.httpOnly ? "; httponly; " : "") + (this.secure ? "; secure" : "");
    }

    /**
     * 通过 Map 构建一个 Cookie 对象
     * @param cookieMap Cookie 属性 Map
     * @return Cookie 对象
     */
    public static Cookie buildCookie(Map<String, String> cookieMap) {
        Cookie cookie = new Cookie();
        for (Entry<String, String> cookieMapItem : cookieMap.entrySet()) {
            switch(cookieMapItem.getKey().toLowerCase()) {
                case "domain":
                    cookie.setDomain(cookieMapItem.getValue());
                    break;
                case "path":
                    cookie.setPath(cookieMapItem.getValue());
                    break;
                case "max-age":
                    cookie.setMaxAge(Integer.parseInt(cookieMapItem.getValue()));
                    break;
                case "secure":
                    cookie.setSecure(true);
                    break;
                case "httponly":
                    cookie.setHttpOnly(true);
                    break;
                case "expires":
                    cookie.setExpires(cookieMapItem.getValue());
                    break;
                default:
                    cookie.setName(cookieMapItem.getKey());
                    cookie.setValue(cookieMapItem.getValue());
                    break;
            }
        }
        return cookie;
    }

    /**
     * 创建一个 Cookie
     * @param domain	cookie的受控域
     * @param path      cookie路径
     * @param name		名称
     * @param value		值
     * @param maxAge	失效时间,单位秒
     * @param isHttpOnly httpOnly属性
     * @return Cookie 对象
     */
    public static Cookie newInstance(String domain, String path, String name, String value, int maxAge, boolean isHttpOnly) {
        Cookie cookie = new Cookie();

        cookie.setValue(value);
        cookie.setPath(path);
        cookie.setDomain(domain);
        cookie.setMaxAge(maxAge);
        cookie.setHttpOnly(isHttpOnly);
        return cookie;
    }

    /**
     * 创建一个 Cookie
     * @param request	请求对象
     * @param path      cookie路径
     * @param name		名称
     * @param value		值
     * @param maxAge	失效时间,单位秒
     * @param isHttpOnly httpOnly属性
     * @return Cookie 对象
     */
    public static Cookie newInstance(Request request, String path, String name, String value, int maxAge, boolean isHttpOnly) {
        String Host = request.header().get("Host");
        String domain = Host.split(":")[0];
        return newInstance(domain, path, name, value, maxAge, isHttpOnly);
    }

    /**
     * 创建一个 Cookie
     * @param request	请求对象
     * @param path      cookie路径
     * @param name		名称
     * @param value		值
     * @return Cookie 对象
     */
    public static Cookie newInstance(Request request, String path, String name, String value) {
        return newInstance(request, path, name, value, WebContext.getWebServerConfig().getSessionTimeout() * 60, false);
    }

    /**
     * 创建一个 Cookie
     * @param request	请求对象
     * @param name		名称
     * @param value		值
     * @return Cookie 对象
     */
    public static Cookie newInstance(Request request, String name, String value) {
        return newInstance(request, "/", name, value, WebContext.getWebServerConfig().getSessionTimeout() * 60, false);
    }
}


public static Cookie newInstance(Request request, String name, String value) {
        return newInstance(request, "/", name, value, WebContext.getWebServerConfig().getSessionTimeout() * 60, false);
    }

package org.voovan.http.message.packet;

import org.voovan.http.message.Request;
import org.voovan.http.server.context.WebContext;
import org.voovan.tools.log.Logger;
import java.io.UnsupportedEncodingException;
import java.net.URLDecoder;
import java.net.URLEncoder;
import java.util.Map;
import java.util.Map.Entry;

/**
 *  HTTP 的 cookie 对象
 * @author helyho
 *
 * Voovan Framework.
 * WebSite: http://example.com
 */
public class Cookie {

    private String domain;

    private String path;

    private int maxAge = -999999;

    private String expires;

    private boolean secure;

    private boolean httpOnly;

    private String name;

    private String value;

    private Cookie() {
    }

    public String getDomain() {
        return domain;
    }

    public void setDomain(String domain) {
        this.domain = domain;
    }

    public String getPath() {
        return path;
    }

    public void setPath(String path) {
        this.path = path;
    }

    public int getMaxAge() {
        return maxAge;
    }

    public void setMaxAge(int maxAge) {
        this.maxAge = maxAge;
    }

    public String getExpires() {
        return expires;
    }

    public void setExpires(String expires) {
        this.expires = expires;
    }

    public boolean isSecure() {
        return secure;
    }

    public void setSecure(boolean secure) {
        this.secure = secure;
    }

    public boolean isHttpOnly() {
        return httpOnly;
    }

    public void setHttpOnly(boolean httpOnly) {
        this.httpOnly = httpOnly;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getValue() {
        try {
            return URLDecoder.decode(this.value, "UTF-8");
        } catch (UnsupportedEncodingException e) {
            Logger.error(e);
        }
        return this.value;
    }

    public void setValue(String value) {
        try {
            this.value = URLEncoder.encode(value, "UTF-8");
        } catch (UnsupportedEncodingException e) {
            Logger.error(e);
        }
    }

    @Override
    public String toString() {
        return (this.name != null || this.value != null ? (this.name + "=" + this.value) : "") + (this.domain != null ? ("; domain=" + this.domain) : "") + (this.maxAge != -999999 ? ("; max-age=" + this.maxAge) : "") + (this.path != null ? ("; path=" + this.path) : "") + (this.httpOnly ? "; httponly; " : "") + (this.secure ? "; secure" : "");
    }

    /**
     * 通过 Map 构建一个 Cookie 对象
     * @param cookieMap Cookie 属性 Map
     * @return Cookie 对象
     */
    public static Cookie buildCookie(Map<String, String> cookieMap) {
        Cookie cookie = new Cookie();
        for (Entry<String, String> cookieMapItem : cookieMap.entrySet()) {
            switch(cookieMapItem.getKey().toLowerCase()) {
                case "domain":
                    cookie.setDomain(cookieMapItem.getValue());
                    break;
                case "path":
                    cookie.setPath(cookieMapItem.getValue());
                    break;
                case "max-age":
                    cookie.setMaxAge(Integer.parseInt(cookieMapItem.getValue()));
                    break;
                case "secure":
                    cookie.setSecure(true);
                    break;
                case "httponly":
                    cookie.setHttpOnly(true);
                    break;
                case "expires":
                    cookie.setExpires(cookieMapItem.getValue());
                    break;
                default:
                    cookie.setName(cookieMapItem.getKey());
                    cookie.setValue(cookieMapItem.getValue());
                    break;
            }
        }
        return cookie;
    }

    /**
     * 创建一个 Cookie
     * @param domain	cookie的受控域
     * @param path      cookie路径
     * @param name		名称
     * @param value		值
     * @param maxAge	失效时间,单位秒
     * @param isHttpOnly httpOnly属性
     * @return Cookie 对象
     */
    public static Cookie newInstance(String domain, String path, String name, String value, int maxAge, boolean isHttpOnly) {
        Cookie cookie = new Cookie();
        cookie.setName(name);
        cookie.setValue(value);
        cookie.setPath(path);
        cookie.setDomain(domain);
        cookie.setMaxAge(maxAge);
        cookie.setHttpOnly(isHttpOnly);
        return cookie;
    }

    /**
     * 创建一个 Cookie
     * @param request	请求对象
     * @param path      cookie路径
     * @param name		名称
     * @param value		值
     * @param maxAge	失效时间,单位秒
     * @param isHttpOnly httpOnly属性
     * @return Cookie 对象
     */
    public static Cookie newInstance(Request request, String path, String name, String value, int maxAge, boolean isHttpOnly) {
        String Host = request.header().get("Host");
        String domain = Host.split(":")[0];
        return newInstance(domain, path, name, value, maxAge, isHttpOnly);
    }

    /**
     * 创建一个 Cookie
     * @param request	请求对象
     * @param path      cookie路径
     * @param name		名称
     * @param value		值
     * @return Cookie 对象
     */
    public static Cookie newInstance(Request request, String path, String name, String value) {
        return newInstance(request, path, name, value, WebContext.getWebServerConfig().getSessionTimeout() * 60, false);
    }

    /**
     * 创建一个 Cookie
     * @param request	请求对象
     * @param name		名称
     * @param value		值
     * @return Cookie 对象
     */


try {
            this.value = URLEncoder.encode(value, "UTF-8");
        } catch (UnsupportedEncodingException e) {
            Logger.error(e);
        }

package org.voovan.http.message.packet;

import org.voovan.http.message.Request;
import org.voovan.http.server.context.WebContext;
import org.voovan.tools.log.Logger;
import java.io.UnsupportedEncodingException;
import java.net.URLDecoder;
import java.net.URLEncoder;
import java.util.Map;
import java.util.Map.Entry;

/**
 *  HTTP 的 cookie 对象
 * @author helyho
 *
 * Voovan Framework.
 * WebSite: http://example.com
 */
public class Cookie {

    private String domain;

    private String path;

    private int maxAge = -999999;

    private String expires;

    private boolean secure;

    private boolean httpOnly;

    private String name;

    private String value;

    private Cookie() {
    }

    public String getDomain() {
        return domain;
    }

    public void setDomain(String domain) {
        this.domain = domain;
    }

    public String getPath() {
        return path;
    }

    public void setPath(String path) {
        this.path = path;
    }

    public int getMaxAge() {
        return maxAge;
    }

    public void setMaxAge(int maxAge) {
        this.maxAge = maxAge;
    }

    public String getExpires() {
        return expires;
    }

    public void setExpires(String expires) {
        this.expires = expires;
    }

    public boolean isSecure() {
        return secure;
    }

    public void setSecure(boolean secure) {
        this.secure = secure;
    }

    public boolean isHttpOnly() {
        return httpOnly;
    }

    public void setHttpOnly(boolean httpOnly) {
        this.httpOnly = httpOnly;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getValue() {
        try {
            return URLDecoder.decode(this.value, "UTF-8");
        } catch (UnsupportedEncodingException e) {
            Logger.error(e);
        }
        return this.value;
    }

    public void setValue(String value) {

    }

    @Override
    public String toString() {
        return (this.name != null || this.value != null ? (this.name + "=" + this.value) : "") + (this.domain != null ? ("; domain=" + this.domain) : "") + (this.maxAge != -999999 ? ("; max-age=" + this.maxAge) : "") + (this.path != null ? ("; path=" + this.path) : "") + (this.httpOnly ? "; httponly; " : "") + (this.secure ? "; secure" : "");
    }

    /**
     * 通过 Map 构建一个 Cookie 对象
     * @param cookieMap Cookie 属性 Map
     * @return Cookie 对象
     */
    public static Cookie buildCookie(Map<String, String> cookieMap) {
        Cookie cookie = new Cookie();
        for (Entry<String, String> cookieMapItem : cookieMap.entrySet()) {
            switch(cookieMapItem.getKey().toLowerCase()) {
                case "domain":
                    cookie.setDomain(cookieMapItem.getValue());
                    break;
                case "path":
                    cookie.setPath(cookieMapItem.getValue());
                    break;
                case "max-age":
                    cookie.setMaxAge(Integer.parseInt(cookieMapItem.getValue()));
                    break;
                case "secure":
                    cookie.setSecure(true);
                    break;
                case "httponly":
                    cookie.setHttpOnly(true);
                    break;
                case "expires":
                    cookie.setExpires(cookieMapItem.getValue());
                    break;
                default:
                    cookie.setName(cookieMapItem.getKey());
                    cookie.setValue(cookieMapItem.getValue());
                    break;
            }
        }
        return cookie;
    }

    /**
     * 创建一个 Cookie
     * @param domain	cookie的受控域
     * @param path      cookie路径
     * @param name		名称
     * @param value		值
     * @param maxAge	失效时间,单位秒
     * @param isHttpOnly httpOnly属性
     * @return Cookie 对象
     */
    public static Cookie newInstance(String domain, String path, String name, String value, int maxAge, boolean isHttpOnly) {
        Cookie cookie = new Cookie();
        cookie.setName(name);
        cookie.setValue(value);
        cookie.setPath(path);
        cookie.setDomain(domain);
        cookie.setMaxAge(maxAge);
        cookie.setHttpOnly(isHttpOnly);
        return cookie;
    }

    /**
     * 创建一个 Cookie
     * @param request	请求对象
     * @param path      cookie路径
     * @param name		名称
     * @param value		值
     * @param maxAge	失效时间,单位秒
     * @param isHttpOnly httpOnly属性
     * @return Cookie 对象
     */
    public static Cookie newInstance(Request request, String path, String name, String value, int maxAge, boolean isHttpOnly) {
        String Host = request.header().get("Host");
        String domain = Host.split(":")[0];
        return newInstance(domain, path, name, value, maxAge, isHttpOnly);
    }

    /**
     * 创建一个 Cookie
     * @param request	请求对象
     * @param path      cookie路径
     * @param name		名称
     * @param value		值
     * @return Cookie 对象
     */
    public static Cookie newInstance(Request request, String path, String name, String value) {
        return newInstance(request, path, name, value, WebContext.getWebServerConfig().getSessionTimeout() * 60, false);
    }

    /**
     * 创建一个 Cookie
     * @param request	请求对象
     * @param name		名称
     * @param value		值
     * @return Cookie 对象
     */
    public static Cookie newInstance(Request request, String name, String value) {
        return newInstance(request, "/", name, value, WebContext.getWebServerConfig().getSessionTimeout() * 60, false);
    }
}


@Override
    public ArrayList<Article> parse(String jString, ResponseObject<ArrayList<Article>> responseObject) throws Exception

package net.nashlegend.sourcewall.request.parsers;

import net.nashlegend.sourcewall.model.Article;
import net.nashlegend.sourcewall.request.JsonHandler;
import net.nashlegend.sourcewall.request.ResponseObject;
import org.json.JSONArray;
import org.json.JSONObject;
import java.util.ArrayList;

/**
 * Created by NashLegend on 16/5/2.
 */
public class ArticleListParser implements Parser<ArrayList<Article>> {

{
        ArrayList<Article> articleList = new ArrayList<>();
        JSONArray articles = JsonHandler.getUniversalJsonArray(jString, responseObject);
        assert articles != null;
        for (int i = 0; i < articles.length(); i++) {
            JSONObject jo = articles.getJSONObject(i);
            articleList.add(Article.fromJsonSimple(jo));
        }
        return articleList;
    }
}


{
        ArrayList<Article> articleList = new ArrayList<>();
        JSONArray articles = JsonHandler.getUniversalJsonArray(jString, responseObject);
        assert articles != null;
        for (int i = 0; i < articles.length(); i++) {
            JSONObject jo = articles.getJSONObject(i);
            articleList.add(Article.fromJsonSimple(jo));
        }
        return articleList;
    }

package net.nashlegend.sourcewall.request.parsers;

import net.nashlegend.sourcewall.model.Article;
import net.nashlegend.sourcewall.request.JsonHandler;
import net.nashlegend.sourcewall.request.ResponseObject;
import org.json.JSONArray;
import org.json.JSONObject;
import java.util.ArrayList;

/**
 * Created by NashLegend on 16/5/2.
 */
public class ArticleListParser implements Parser<ArrayList<Article>> {

    @Override
    public ArrayList<Article> parse(String jString, ResponseObject<ArrayList<Article>> responseObject) throws Exception


        ArrayList<Article> articleList = new ArrayList<>();
        JSONArray articles = JsonHandler.getUniversalJsonArray(jString, responseObject);

package net.nashlegend.sourcewall.request.parsers;

import net.nashlegend.sourcewall.model.Article;
import net.nashlegend.sourcewall.request.JsonHandler;
import net.nashlegend.sourcewall.request.ResponseObject;
import org.json.JSONArray;
import org.json.JSONObject;
import java.util.ArrayList;

/**
 * Created by NashLegend on 16/5/2.
 */
public class ArticleListParser implements Parser<ArrayList<Article>> {

    @Override
    public ArrayList<Article> parse(String jString, ResponseObject<ArrayList<Article>> responseObject) throws Exception {

        assert articles != null;
        for (int i = 0; i < articles.length(); i++) {
            JSONObject jo = articles.getJSONObject(i);
            articleList.add(Article.fromJsonSimple(jo));
        }
        return articleList;
    }
}


assert articles != null;
        for (int i = 0; i < articles.length(); i++) {
            JSONObject jo = articles.getJSONObject(i);
            articleList.add(Article.fromJsonSimple(jo));
        }

package net.nashlegend.sourcewall.request.parsers;

import net.nashlegend.sourcewall.model.Article;
import net.nashlegend.sourcewall.request.JsonHandler;
import net.nashlegend.sourcewall.request.ResponseObject;
import org.json.JSONArray;
import org.json.JSONObject;
import java.util.ArrayList;

/**
 * Created by NashLegend on 16/5/2.
 */
public class ArticleListParser implements Parser<ArrayList<Article>> {

    @Override
    public ArrayList<Article> parse(String jString, ResponseObject<ArrayList<Article>> responseObject) throws Exception {
        ArrayList<Article> articleList = new ArrayList<>();
        JSONArray articles = JsonHandler.getUniversalJsonArray(jString, responseObject);


package net.nashlegend.sourcewall.request.parsers;

import net.nashlegend.sourcewall.model.Article;
import net.nashlegend.sourcewall.request.JsonHandler;
import net.nashlegend.sourcewall.request.ResponseObject;
import org.json.JSONArray;
import org.json.JSONObject;
import java.util.ArrayList;

/**
 * Created by NashLegend on 16/5/2.
 */
public class ArticleListParser implements Parser<ArrayList<Article>> {

    @Override
    public ArrayList<Article> parse(String jString, ResponseObject<ArrayList<Article>> responseObject) throws Exception {
        ArrayList<Article> articleList = new ArrayList<>();
        JSONArray articles = JsonHandler.getUniversalJsonArray(jString, responseObject);
        assert articles != null;
        for (int i = 0; i < articles.length(); i++) {
            JSONObject jo = articles.getJSONObject(i);
            articleList.add(Article.fromJsonSimple(jo));
        }


package net.nashlegend.sourcewall.request.parsers;

import net.nashlegend.sourcewall.model.Article;
import net.nashlegend.sourcewall.request.JsonHandler;
import net.nashlegend.sourcewall.request.ResponseObject;
import org.json.JSONArray;
import org.json.JSONObject;
import java.util.ArrayList;

/**
 * Created by NashLegend on 16/5/2.
 */
public class ArticleListParser implements Parser<ArrayList<Article>> {

    @Override
    public ArrayList<Article> parse(String jString, ResponseObject<ArrayList<Article>> responseObject) throws Exception {
        ArrayList<Article> articleList = new ArrayList<>();
        JSONArray articles = JsonHandle


for (int i = 0; i < articles.length(); i++) {
            JSONObject jo = articles.getJSONObject(i);
            articleList.add(Article.fromJsonSimple(jo));
        }

package net.nashlegend.sourcewall.request.parsers;

import net.nashlegend.sourcewall.model.Article;
import net.nashlegend.sourcewall.request.JsonHandler;
import net.nashlegend.sourcewall.request.ResponseObject;
import org.json.JSONArray;
import org.json.JSONObject;
import java.util.ArrayList;

/**
 * Created by NashLegend on 16/5/2.
 */
public class ArticleListParser implements Parser<ArrayList<Article>> {

    @Override
    public ArrayList<Article> parse(String jString, ResponseObject<ArrayList<Article>> responseObject) throws Exception {
        ArrayList<Article> articleList = new ArrayList<>();
        JSONArray articles = JsonHandler.getUniversalJsonArray(jString, responseObject);
        assert articles != null;


public static SpatialRDD<Geometry> readToGeometryRDD(JavaSparkContext sc, String inputPath, int wkbColumn, boolean allowInvalidGeometries, boolean skipSyntacticallyInvalidGeometries)

package org.apache.sedona.core.formatMapper;

import org.apache.sedona.core.enums.FileDataSplitter;
import org.apache.sedona.core.spatialRDD.SpatialRDD;
import org.apache.spark.api.java.JavaRDD;
import org.apache.spark.api.java.JavaSparkContext;
import org.locationtech.jts.geom.Geometry;

public class WkbReader extends RddReader {

    /**
     * Read a SpatialRDD from a file.
     *
     * @param sc
     * @param inputPath
     * @param wkbColumn The column which contains the wkt string. Start from 0.
     * @param allowInvalidGeometries whether allows topology-invalid geometries exist in the generated RDD
     * @param skipSyntacticallyInvalidGeometries whether allows Sedona to automatically skip syntax-invalid geometries, rather than throw errors
     * @return
     */

{
        JavaRDD rawTextRDD = sc.textFile(inputPath);
        FormatMapper<Geometry> formatMapper = new FormatMapper<Geometry>(wkbColumn, -1, FileDataSplitter.WKB, true, null);
        formatMapper.allowTopologicallyInvalidGeometries = allowInvalidGeometries;
        formatMapper.skipSyntacticallyInvalidGeometries = skipSyntacticallyInvalidGeometries;
        return createSpatialRDD(rawTextRDD, formatMapper);
    }

    /**
     * Read a SpatialRDD from a string type rdd.
     *
     * @param rawTextRDD a string type RDD
     * @param wkbColumn The column which contains the wkt string. Start from 0.
     * @param allowInvalidGeometries whether allows topology-invalid geometries exist in the generated RDD
     * @param skipSyntacticallyInvalidGeometries whether allows Sedona to automatically skip syntax-invalid geometries, rather than throw errors
     * @return
     */
    public static SpatialRDD<Geometry> readToGeometryRDD(JavaRDD rawTextRDD, int wkbColumn, boolean allowInvalidGeometries, boolean skipSyntacticallyInvalidGeometries) {
        FormatMapper<Geometry> formatMapper = new FormatMapper<Geometry>(wkbColumn, -1, FileDataSplitter.WKB, true, null);
        formatMapper.allowTopologicallyInvalidGeometries = allowInvalidGeometries;
        formatMapper.skipSyntacticallyInvalidGeometries = skipSyntacticallyInvalidGeometries;
        return createSpatialRDD(rawTextRDD, formatMapper);
    }
}


{
        FormatMapper<Geometry> formatMapper = new FormatMapper<Geometry>(wkbColumn, -1, FileDataSplitter.WKB, true, null);
        formatMapper.allowTopologicallyInvalidGeometries = allowInvalidGeometries;
        formatMapper.skipSyntacticallyInvalidGeometries = skipSyntacticallyInvalidGeometries;
        return createSpatialRDD(rawTextRDD, formatMapper);
    }

package org.apache.sedona.core.formatMapper;

import org.apache.sedona.core.enums.FileDataSplitter;
import org.apache.sedona.core.spatialRDD.SpatialRDD;
import org.apache.spark.api.java.JavaRDD;
import org.apache.spark.api.java.JavaSparkContext;
import org.locationtech.jts.geom.Geometry;

public class WkbReader extends RddReader {

    /**
     * Read a SpatialRDD from a file.
     *
     * @param sc
     * @param inputPath
     * @param wkbColumn The column which contains the wkt string. Start from 0.
     * @param allowInvalidGeometries whether allows topology-invalid geometries exist in the generated RDD
     * @param skipSyntacticallyInvalidGeometries whether allows Sedona to automatically skip syntax-invalid geometries, rather than throw errors
     * @return
     */
    public static SpatialRDD<Geometry> readToGeometryRDD(JavaSparkContext sc, String inputPath, int wkbColumn, boolean allowInvalidGeometries, boolean skipSyntacticallyInvalidGeometries) {
        JavaRDD rawTextRDD = sc.textFile(inputPath);
        FormatMapper<Geometry> formatMapper = new FormatMapper<Geometry>(wkbColumn, -1, FileDataSplitter.WKB, true, null);
        formatMapper.allowTopologicallyInvalidGeometries = allowInvalidGeometries;
        formatMapper.skipSyntacticallyInvalidGeometries = skipSyntacticallyInvalidGeometries;
        return createSpatialRDD(rawTextRDD, formatMapper);
    }

    /**
     * Read a SpatialRDD from a string type rdd.
     *
     * @param rawTextRDD a string type RDD
     * @param wkbColumn The column which contains the wkt string. Start from 0.
     * @param allowInvalidGeometries whether allows topology-invalid geometries exist in the generated RDD
     * @param skipSyntacticallyInvalidGeometries whether allows Sedona to automatically skip syntax-invalid geometries, rather than throw errors
     * @return
     */
    public static SpatialRDD<Geometry> readToGeometryRDD(JavaRDD rawTextRDD, int wkbColumn, boolean allowInvalidGeometries, boolean skipSyntacticallyInvalidGeometries)


        JavaRDD rawTextRDD = sc.textFile(inputPath);
        FormatMapper<Geometry> formatMapper = new FormatMapper<Geometry>(wkbColumn, -1, FileDataSplitter.WKB, true, null);

package org.apache.sedona.core.formatMapper;

import org.apache.sedona.core.enums.FileDataSplitter;
import org.apache.sedona.core.spatialRDD.SpatialRDD;
import org.apache.spark.api.java.JavaRDD;
import org.apache.spark.api.java.JavaSparkContext;
import org.locationtech.jts.geom.Geometry;

public class WkbReader extends RddReader {

    /**
     * Read a SpatialRDD from a file.
     *
     * @param sc
     * @param inputPath
     * @param wkbColumn The column which contains the wkt string. Start from 0.
     * @param allowInvalidGeometries whether allows topology-invalid geometries exist in the generated RDD
     * @param skipSyntacticallyInvalidGeometries whether allows Sedona to automatically skip syntax-invalid geometries, rather than throw errors
     * @return
     */
    public static SpatialRDD<Geometry> readToGeometryRDD(JavaSparkContext sc, String inputPath, int wkbColumn, boolean allowInvalidGeometries, boolean skipSyntacticallyInvalidGeometries) {

        formatMapper.allowTopologicallyInvalidGeometries = allowInvalidGeometries;
        formatMapper.skipSyntacticallyInvalidGeometries = skipSyntacticallyInvalidGeometries;
        return createSpatialRDD(rawTextRDD, formatMapper);
    }

    /**
     * Read a SpatialRDD from a string type rdd.
     *
     * @param rawTextRDD a string type RDD
     * @param wkbColumn The column which contains the wkt string. Start from 0.
     * @param allowInvalidGeometries whether allows topology-invalid geometries exist in the generated RDD
     * @param skipSyntacticallyInvalidGeometries whether allows Sedona to automatically skip syntax-invalid geometries, rather than throw errors
     * @return
     */
    public static SpatialRDD<Geometry> readToGeometryRDD(JavaRDD rawTextRDD, int wkbColumn, boolean allowInvalidGeometries, boolean skipSyntacticallyInvalidGeometries) {
        FormatMapper<Geometry> formatMapper = new FormatMapper<Geometry>(wkbColumn, -1, FileDataSplitter.WKB, true, null);
        formatMapper.allowTopologicallyInvalidGeometries = allowInvalidGeometries;
        formatMapper.skipSyntacticallyInvalidGeometries = skipSyntacticallyInvalidGeometries;
        return createSpatialRDD(rawTextRDD, formatMapper);
    }
}


package org.apache.sedona.core.formatMapper;

import org.apache.sedona.core.enums.FileDataSplitter;
import org.apache.sedona.core.spatialRDD.SpatialRDD;
import org.apache.spark.api.java.JavaRDD;
import org.apache.spark.api.java.JavaSparkContext;
import org.locationtech.jts.geom.Geometry;

public class WkbReader extends RddReader {

    /**
     * Read a SpatialRDD from a file.
     *
     * @param sc
     * @param inputPath
     * @param wkbColumn The column which contains the wkt string. Start from 0.
     * @param allowInvalidGeometries whether allows topology-invalid geometries exist in the generated RDD
     * @param skipSyntacticallyInvalidGeometries whether allows Sedona to automatically skip syntax-invalid geometries, rather than throw errors
     * @return
     */
    public static SpatialRDD<Geometry> readToGeometryRDD(JavaSparkContext sc, String inputPath, int wkbColumn, boolean allowInvalidGeometries, boolean skipSyntacticallyInvalidGeometries) {
        JavaRDD rawTextRDD = sc.textFile(inputPath);
        FormatMapper<Geometry> formatMapper = new FormatMapper<Geometry>(wkbColumn, -1, FileDataSplitter.WKB, true, null);

        return createSpatialRDD(rawTextRDD, formatMapper);
    }

    /**
     * Read a SpatialRDD from a string type rdd.
     *
     * @param rawTextRDD a string type RDD
     * @param wkbColumn The column which contains the wkt string. Start from 0.
     * @param allowInvalidGeometries whether allows topology-invalid geometries exist in the generated RDD
     * @param skipSyntacticallyInvalidGeometries whether allows Sedona to automatically skip syntax-invalid geometries, rather than throw errors
     * @return
     */
    public static SpatialRDD<Geometry> readToGeometryRDD(JavaRDD rawTextRDD, int wkbColumn, boolean allowInvalidGeometries, boolean skipSyntacticallyInvalidGeometries) {
        FormatMapper<Geometry> formatMapper = new FormatMapper<Geometry>(wkbColumn, -1, FileDataSplitter.WKB, true, null);
        formatMapper.allowTopologicallyInvalidGeometries = allowInvalidGeometries;
        formatMapper.skipSyntacticallyInvalidGeometries = skipSyntacticallyInvalidGeometries;
        return createSpatialRDD(rawTextRDD, formatMapper);
    }
}


package org.apache.sedona.core.formatMapper;

import org.apache.sedona.core.enums.FileDataSplitter;
import org.apache.sedona.core.spatialRDD.SpatialRDD;
import org.apache.spark.api.java.JavaRDD;
import org.apache.spark.api.java.JavaSparkContext;
import org.locationtech.jts.geom.Geometry;

public class WkbReader extends RddReader {

    /**
     * Read a SpatialRDD from a file.
     *
     * @param sc
     * @param inputPath
     * @param wkbColumn The column which contains the wkt string. Start from 0.
     * @param allowInvalidGeometries whether allows topology-invalid geometries exist in the generated RDD
     * @param skipSyntacticallyInvalidGeometries whether allows Sedona to automatically skip syntax-invalid geometries, rather than throw errors
     * @return
     */
    public static SpatialRDD<Geometry> readToGeometryRDD(JavaSparkContext sc, String inputPath, int wkbColumn, boolean allowInvalidGeometries, boolean skipSyntacticallyInvalidGeometries) {
        JavaRDD rawTextRDD = sc.textFile(inputPath);
        FormatMapper<Geometry> formatMapper = new FormatMapper<Geometry>(wkbColumn, -1, FileDataSplitter.WKB, true, null);
        formatMapper.allowTopologicallyInvalidGeometries = allowInvalidGeometries;
        formatMapper.skipSyntacticallyInvalidGeometries = skipSyntacticallyInvalidGeometries;

    /**
     * Read a SpatialRDD from a string type rdd.
     *
     * @param rawTextRDD a string type RDD
     * @param wkbColumn The column which contains the wkt string. Start from 0.
     * @param allowInvalidGeometries whether allows topology-invalid geometries exist in the generated RDD
     * @param skipSyntacticallyInvalidGeometries whether allows Sedona to automatically skip syntax-invalid geometries, rather than throw errors
     * @return
     */
    public static SpatialRDD<Geometry> readToGeometryRDD(JavaRDD rawTextRDD, int wkbColumn, boolean allowInvalidGeometries, boolean skipSyntacticallyInvalidGeometries) {
        FormatMapper<Geometry> formatMapper = new FormatMapper<Geometry>(wkbColumn, -1, FileDataSplitter.WKB, true, null);
        formatMapper.allowTopologicallyInvalidGeometries = allowInvalidGeometries;
        formatMapper.skipSyntacticallyInvalidGeometries = skipSyntacticallyInvalidGeometries;
        return createSpatialRDD(rawTextRDD, formatMapper);
    }
}


package org.apache.sedona.core.formatMapper;

import org.apache.sedona.core.enums.FileDataSplitter;
import org.apache.sedona.core.spatialRDD.SpatialRDD;
import org.apache.spark.api.java.JavaRDD;
import org.apache.spark.api.java.JavaSparkContext;
import org.locationtech.jts.geom.Geometry;

public class WkbReader extends RddReader {

    /**
     * Read a SpatialRDD from a file.
     *
     * @param sc
     * @param inputPath
     * @param wkbColumn The column which contains the wkt string. Start from 0.
     * @param allowInvalidGeometries whether allows topology-invalid geometries exist in the generated RDD
     * @param skipSyntacticallyInvalidGeometries whether allows Sedona to automatically skip syntax-invalid geometries, rather than throw errors
     * @return
     */
    public static SpatialRDD<Geometry> readToGeometryRDD(JavaSparkContext sc, String inputPath, int wkbColumn, boolean allowInvalidGeometries, boolean skipSyntacticallyInvalidGeometries) {
        JavaRDD rawTextRDD = sc.textFile(inputPath);
        FormatMapper<Geometry> formatMapper = new FormatMapper<Geometry>(wkbColumn, -1, FileDataSplitter.WKB, true, null);
        formatMapper.allowTopologicallyInvalidGeometries = allowInvalidGeometries;
        formatMapper.skipSyntacticallyInvalidGeometries = skipSyntacticallyInvalidGeometries;
        return createSpatialRDD(rawTextRDD, formatMapper);
    }

    /**
     * Read a SpatialRDD from a string type rdd.
     *
     * @param rawTextRDD a string type RDD
     * @param wkbColumn The column which contains the wkt string. Start from 0.
     * @param allowInvalidGeometries whether allows topology-invalid geometries exist in the generated RDD
     * @param skipSyntacticallyInvalidGeometries whether allows Sedona to automatically skip syntax-invalid geometries, rather than throw errors
     * @return
     */
    public static SpatialRDD<Geometry> readToGeometryRDD(JavaRDD rawTextRDD, int wkbColumn, boolean allowInvalidGeometries, boolean skipSyntacticallyInvalidGeometries) {
        FormatMapper<Geometry> form

        formatMapper.allowTopologicallyInvalidGeometries = allowInvalidGeometries;
        formatMapper.skipSyntacticallyInvalidGeometries = skipSyntacticallyInvalidGeometries;
        return createSpatialRDD(rawTextRDD, formatMapper);
    }
}