Slowing the download speed is quite simple. Just read from the InputStream more slowly:
public byte[] rateLimitedDownload(InputStream in, int bytesPerSecond) throws IOException {
ByteArrayOutputStream out = new ByteArrayOutputStream();
byte[] buffer = new byte[bytesPerSecond];
int read;
while ((read = in.read(buffer)) != -1) {
out.write(buffer, 0, read);
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
// nothing
}
}
return out.toByteArray();
}
This code isn't perfect - any time spent actually reading from in is not considered, and reads may be less than expected. It should give you an idea though.