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

com.dounine.clouddisk360.parser.deserializer.passport.PassportResponseHandle Maven / Gradle / Ivy

package com.dounine.clouddisk360.parser.deserializer.passport;

import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;

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.PassportParser;
import com.dounine.clouddisk360.parser.deserializer.BaseResponseHandle;
import com.dounine.clouddisk360.parser.deserializer.login.LoginConst;
import com.dounine.clouddisk360.parser.deserializer.login.LoginUserToken;
import com.dounine.clouddisk360.store.BasePathCommon;

public class PassportResponseHandle extends BaseResponseHandle
		implements ResponseHandler {

	public PassportResponseHandle(PassportParser parse) {
		super(parse);
	}

	@Override
	public Passport handleResponse(HttpResponse response) throws ClientProtocolException, IOException {
		executeBefore(response);
		saveCookie();
		executeAfter(response);
		return null;
	}

	@Override
	public void saveCookie() {
		parse.getCookieStoreUT().writeCookieStoreToDisk(parse.getHttpClientContext().getCookieStore(), new String[] { LoginConst.QUCRYPTCODE_NAME });
	}

	@Override
	public void executeBefore(HttpResponse response) {
		HttpEntity entity = response.getEntity();
		InputStream is = null;
		try {
			is = entity.getContent();
		} catch (UnsupportedOperationException | IOException e2) {
			e2.printStackTrace();
		}
		OutputStream os = null;
		try {
			LoginUserToken loginUser = parse.getHttpClientContext().getUserToken(LoginUserToken.class);
			File file = new File(BasePathCommon.basePath + loginUser.getAccount());
			if (!file.exists()) {
				file.mkdirs();
			}
			os = new FileOutputStream(new File(BasePathCommon.basePath + loginUser.getAccount()
					+ String.format("/captcha.jpg", System.currentTimeMillis())));
		} catch (FileNotFoundException e1) {
			e1.printStackTrace();
		}
		byte[] data = new byte[1024 * 1024];
		int length = 0;
		try {
			while ((length = is.read(data)) != -1) {
				os.write(data, 0, length);
			}
			os.flush();
			os.close();
			is.close();
		} catch (IOException e) {
			e.printStackTrace();
		}
	}

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy