All Downloads are FREE. Search and download functionalities are using the official Maven repository.

cn.hutool.http.HttpResource Maven / Gradle / Ivy

There is a newer version: 5.8.32
Show newest version
package cn.hutool.http;

import cn.hutool.core.io.resource.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(Resource resource, 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;
	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy