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

qa.justtestlah.utils.JustTestLahFileEntity Maven / Gradle / Ivy

Go to download

JustTestLah! is a JAVA test framework targeting projects that support multiple platforms, in particular Web, Android and iOS. It follows a BDD approach and allows testing against all platforms using the same feature files. JustTestLah's main aim is to make the configuration and the actual test code as easy as possible.

There is a newer version: 1.9-RC4
Show newest version
package qa.justtestlah.utils;

import java.io.File;
import java.io.IOException;
import java.io.OutputStream;
import org.apache.http.entity.FileEntity;

/**
 * Extension of {@link org.apache.http.entity.FileEntity} to enable a progress report for file
 * uploads.
 *
 * 

taken from * https://stackoverflow.com/questions/7057342/how-to-get-a-progress-bar-for-a-file-upload-with-apache-httpclient-4#8475006 */ public class JustTestLahFileEntity extends FileEntity { private OutputStreamProgress outstream; public JustTestLahFileEntity(File file) { super(file); } @Override public void writeTo(OutputStream outstream) throws IOException { this.outstream = new OutputStreamProgress(outstream); super.writeTo(this.outstream); } /** @return the progress of the upload (0-100) */ public int getProgress() { if (outstream == null) { return 0; } long contentLength = getContentLength(); if (contentLength <= 0) { // Prevent division by zero and negative values return 0; } long writtenLength = outstream.getWrittenLength(); return (int) (100 * writtenLength / contentLength); } }





© 2015 - 2024 Weber Informatics LLC | Privacy Policy