001/**
002 *
003 * Copyright (c) 2014, the Railo Company Ltd. All rights reserved.
004 *
005 * This library is free software; you can redistribute it and/or
006 * modify it under the terms of the GNU Lesser General Public
007 * License as published by the Free Software Foundation; either 
008 * version 2.1 of the License, or (at your option) any later version.
009 * 
010 * This library is distributed in the hope that it will be useful,
011 * but WITHOUT ANY WARRANTY; without even the implied warranty of
012 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
013 * Lesser General Public License for more details.
014 * 
015 * You should have received a copy of the GNU Lesser General Public 
016 * License along with this library.  If not, see <http://www.gnu.org/licenses/>.
017 * 
018 **/
019package lucee.commons.lang;
020
021import java.io.UnsupportedEncodingException;
022
023/**
024 * Name Value Pair
025 */
026public final class ByteNameValuePair {
027
028    private byte[] name;
029    private byte[] value;
030        private boolean urlEncoded;
031    
032    /**
033     * constructor of the class
034     * @param name
035     * @param value
036     */
037    public ByteNameValuePair(byte[] name, byte[] value,boolean urlEncoded) {
038        this.name = name;
039        this.value = value;
040        this.urlEncoded = urlEncoded;
041    }
042    
043    /**
044     * @return Returns the name.
045     */
046    public byte[] getName() {
047        return name;
048    }
049    
050    /**
051     * @param encoding 
052     * @return Returns the name.
053     * @throws UnsupportedEncodingException 
054     */
055    public String getName(String encoding) throws UnsupportedEncodingException {
056        return new String(name,encoding);
057    }
058    
059    /**
060     * @param encoding 
061     * @param defaultValue 
062     * @return Returns the name.
063     */
064    public String getName(String encoding, String defaultValue) {
065        try {
066            return new String(name,encoding);
067        } catch (UnsupportedEncodingException e) {
068            return defaultValue;
069        }
070    }
071    
072    /**
073     * @param name The name to set.
074     */
075    public void setName(byte[] name) {
076        this.name = name;
077    }
078    /**
079     * @return Returns the value.
080     */
081    public byte[] getValue() {
082        return value;
083    }
084    
085    /**
086     * @param encoding 
087     * @return Returns the name.
088     * @throws UnsupportedEncodingException 
089     */
090    public String getValue(String encoding) throws UnsupportedEncodingException {
091        return new String(value,encoding);
092    }
093    
094    /**
095     * @param encoding 
096     * @param defaultValue 
097     * @return Returns the name.
098     */
099    public String getValue(String encoding, String defaultValue) {
100        try {
101            return new String(value,encoding);
102        } catch (UnsupportedEncodingException e) {
103            return defaultValue;
104        }
105    }
106    
107    /**
108     * @param value The value to set.
109     */
110    public void setValue(byte[] value) {
111        this.value = value;
112    }
113
114        /**
115         * @return the urlEncoded
116         */
117        public boolean isUrlEncoded() {
118                return urlEncoded;
119        }
120
121}