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

ars.invoke.channel.http.HttpFileInvoker Maven / Gradle / Ivy

The newest version!
package ars.invoke.channel.http;

import java.io.File;
import java.util.UUID;

import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.util.EntityUtils;

import ars.util.Streams;
import ars.invoke.remote.Remotes;
import ars.invoke.remote.Endpoint;
import ars.invoke.request.Requester;

/**
 * 基于文件流的Http远程调用实现
 *
 * @author wuyongqiang
 */
public class HttpFileInvoker extends AbstractHttpInvoker {

    @Override
    protected Object accept(Requester requester, Endpoint endpoint, HttpResponse response) throws Exception {
        HttpEntity entity = response.getEntity();
        File file = new File(Remotes.getDirectory(),
            new StringBuilder("download-").append(UUID.randomUUID()).append(".temp").toString());
        try {
            Streams.write(entity.getContent(), file);
            return file;
        } finally {
            EntityUtils.consumeQuietly(entity);
        }
    }

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy