com.jianggujin.http.util.JKeyVal Maven / Gradle / Ivy
package com.jianggujin.http.util;
import java.io.InputStream;
/**
* 键值对
*
* @author jianggujin
*
*/
public class JKeyVal {
/**
* 键
*/
private String key;
/**
* 值
*/
private String value;
/**
* 输入流
*/
private InputStream stream;
/**
* 创建键值对
*
* @param key
* 健
* @param value
* 值
* @return keyvalue
*/
public static JKeyVal create(String key, String value) {
return new JKeyVal().key(key).value(value);
}
/**
* 创建键值对
*
* @param key
* 健
* @param filename
* 文件名
* @param stream
* 文件输入流
* @return keyvalue
*/
public static JKeyVal create(String key, String filename, InputStream stream) {
return new JKeyVal().key(key).value(filename).inputStream(stream);
}
private JKeyVal() {
}
/**
* 设置键
*
* @param key
* 健
* @return keyvalue
*/
public JKeyVal key(String key) {
if (JDataUtils.isEmpty(key)) {
throw new IllegalArgumentException("Data key must not be empty");
}
this.key = key;
return this;
}
/**
* 获得键
*
* @return key
*/
public String key() {
return key;
}
/**
* 设置值
*
* @param value
* 值
* @return keyvalue
*/
public JKeyVal value(String value) {
if (value == null) {
throw new IllegalArgumentException("Data value must not be null");
}
this.value = value;
return this;
}
/**
* 获得值
*
* @return value
*/
public String value() {
return value;
}
/**
* 设置输入流
*
* @param in
* @return
*/
public JKeyVal inputStream(InputStream in) {
if (in == null) {
throw new IllegalArgumentException("Data input stream must not be null");
}
this.stream = in;
return this;
}
/**
* 获得输入流
*
* @return
*/
public InputStream inputStream() {
return stream;
}
/**
* 判断是否有输入流
*
* @return
*/
public boolean hasInputStream() {
return stream != null;
}
@Override
public String toString() {
return key + "=" + value;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy