mirror of
https://gitee.com/chinabugotech/hutool.git
synced 2025-07-21 15:09:48 +08:00
add http engine
This commit is contained in:
61
hutool-core/src/main/java/cn/hutool/core/io/EmptyInputStream.java
Executable file
61
hutool-core/src/main/java/cn/hutool/core/io/EmptyInputStream.java
Executable file
@@ -0,0 +1,61 @@
|
||||
package cn.hutool.core.io;
|
||||
|
||||
import java.io.InputStream;
|
||||
|
||||
/**
|
||||
* 空的流
|
||||
*
|
||||
* @author looly
|
||||
*/
|
||||
@SuppressWarnings("NullableProblems")
|
||||
public final class EmptyInputStream extends InputStream {
|
||||
/**
|
||||
* 单例实例
|
||||
*/
|
||||
public static final EmptyInputStream INSTANCE = new EmptyInputStream();
|
||||
|
||||
private EmptyInputStream() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public int available() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void close() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void mark(final int readLimit) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean markSupported() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int read() {
|
||||
return -1;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int read(final byte[] buf) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int read(final byte[] buf, final int off, final int len) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void reset() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public long skip(final long n) {
|
||||
return 0L;
|
||||
}
|
||||
}
|
@@ -0,0 +1,55 @@
|
||||
package cn.hutool.core.io.resource;
|
||||
|
||||
import cn.hutool.core.lang.Assert;
|
||||
|
||||
import java.io.InputStream;
|
||||
import java.io.Serializable;
|
||||
import java.net.URL;
|
||||
|
||||
/**
|
||||
* HTTP资源,用于自定义表单数据,可自定义Content-Type
|
||||
*
|
||||
* @author looly
|
||||
* @since 5.7.17
|
||||
*/
|
||||
public class HttpResource implements Resource, Serializable {
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
private final Resource resource;
|
||||
private final String contentType;
|
||||
|
||||
/**
|
||||
* 构造
|
||||
*
|
||||
* @param resource 资源,非空
|
||||
* @param contentType Content-Type类型,{@code null}表示不设置
|
||||
*/
|
||||
public HttpResource(final Resource resource, final String contentType) {
|
||||
this.resource = Assert.notNull(resource, "Resource must be not null !");
|
||||
this.contentType = contentType;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return resource.getName();
|
||||
}
|
||||
|
||||
@Override
|
||||
public URL getUrl() {
|
||||
return resource.getUrl();
|
||||
}
|
||||
|
||||
@Override
|
||||
public InputStream getStream() {
|
||||
return resource.getStream();
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取自定义Content-Type类型
|
||||
*
|
||||
* @return Content-Type类型
|
||||
*/
|
||||
public String getContentType() {
|
||||
return this.contentType;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user