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

com.dg.libs.rest.requests.FileBodyHttpRequestImpl Maven / Gradle / Ivy

There is a newer version: 2.9.0
Show newest version
package com.dg.libs.rest.requests;

import android.content.Context;

import com.araneaapps.android.libs.logger.ALog;
import com.dg.libs.rest.callbacks.HttpCallback;
import com.dg.libs.rest.client.BaseRestClient.RequestMethod;
import com.dg.libs.rest.entities.CountingInputStreamEntity;
import com.dg.libs.rest.entities.CountingInputStreamEntity.UploadListener;
import com.dg.libs.rest.parsers.HttpResponseParser;

import org.apache.http.HttpEntity;

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

public abstract class FileBodyHttpRequestImpl extends EntityHttpRequestImpl {

	public static final String TAG = FileBodyHttpRequestImpl.class.getSimpleName();
	private UploadListener listener;

	public FileBodyHttpRequestImpl(final Context context, RequestMethod requestMethod,
			final HttpResponseParser parser, final HttpCallback callback) {
		super(context, requestMethod, parser, callback);
	}

	public abstract File fileToSend();
	
	public void setListener(UploadListener listener) {
		this.listener = listener;
	}

	@Override
	public HttpEntity getEntity() {
		try {
			File file = fileToSend();
			FileInputStream fileInputStream = new FileInputStream(file);
			CountingInputStreamEntity countingInputStreamEntity = new CountingInputStreamEntity(fileInputStream, file.length());
			countingInputStreamEntity.setUploadListener(listener);
			return countingInputStreamEntity;
		} catch (IOException e) {
			ALog.e(e);
		}
		return null;
	}
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy