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

qa.justtestlah.utils.OutputStreamProgress 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.IOException;
import java.io.OutputStream;
import java.util.concurrent.atomic.AtomicLong;

/**
 * Extension of {@link OutputStreamProgress} 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 OutputStreamProgress extends OutputStream { private final OutputStream outstream; private AtomicLong bytesWritten = new AtomicLong(0); /** @param outstream {@link OutputStream} */ public OutputStreamProgress(OutputStream outstream) { this.outstream = outstream; } @Override public void write(int b) throws IOException { outstream.write(b); bytesWritten.incrementAndGet(); } @Override public void write(byte[] b) throws IOException { outstream.write(b); bytesWritten.addAndGet(b.length); } @Override public void write(byte[] b, int off, int len) throws IOException { outstream.write(b, off, len); bytesWritten.addAndGet(len); } @Override public void flush() throws IOException { outstream.flush(); } @Override public void close() throws IOException { outstream.close(); } public long getWrittenLength() { return bytesWritten.get(); } }





© 2015 - 2024 Weber Informatics LLC | Privacy Policy