com.jianggujin.http.util.JKeyVal Maven / Gradle / Ivy
The newest version!
/**
* Copyright 2018 jianggujin (www.jianggujin.com).
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
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