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

com.dounine.clouddisk360.parser.deserializer.file.download.FileDownloadFileResponseHandle Maven / Gradle / Ivy

package com.dounine.clouddisk360.parser.deserializer.file.download;

import java.io.File;
import java.io.IOException;

import org.apache.commons.io.FileUtils;
import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.ResponseHandler;

import com.dounine.clouddisk360.parser.FileDownloadFileParser;
import com.dounine.clouddisk360.parser.deserializer.BaseResponseHandle;
import com.dounine.clouddisk360.store.BasePathCommon;

public class FileDownloadFileResponseHandle extends BaseResponseHandle
		implements ResponseHandler {

	public FileDownloadFileResponseHandle(FileDownloadFileParser parse) {
		super(parse);
	}

	@Override
	public FileDownloadFile handleResponse(HttpResponse response) throws ClientProtocolException, IOException {
		HttpEntity entity = response.getEntity();
		File destination = new File(BasePathCommon.basePath+"downloads/" + parse.getParameter().getFileName());
		FileUtils.copyInputStreamToFile(entity.getContent(), destination);
		return desializer(destination.getAbsolutePath());
	}

	@Override
	public String disassemblyResult(String result) {
		return String.format("{'filePath':'%s'}", result);
	}

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy