* better error messages when anti-leech limits are reached

This commit is contained in:
Reinhard Pointner 2012-07-13 05:00:27 +00:00
parent 9effd7cc6d
commit 8fd4576ff4
1 changed files with 25 additions and 16 deletions

View File

@ -2,6 +2,7 @@
package net.sourceforge.filebot.web;
import java.io.IOException;
import java.io.InputStream;
import java.net.URL;
import java.nio.ByteBuffer;
@ -9,6 +10,7 @@ import java.util.EnumMap;
import java.util.Map;
import java.util.Map.Entry;
import java.util.zip.GZIPInputStream;
import java.util.zip.ZipException;
import net.sourceforge.tuned.ByteBufferOutputStream;
import net.sourceforge.tuned.FileUtilities;
@ -130,12 +132,19 @@ public class OpenSubtitlesSubtitleDescriptor implements SubtitleDescriptor {
@Override
public ByteBuffer fetch() throws Exception {
URL resource = new URL(getProperty(Property.SubDownloadLink));
InputStream stream = new GZIPInputStream(resource.openStream());
InputStream stream = resource.openStream();
try {
ByteBufferOutputStream buffer = new ByteBufferOutputStream(getLength());
// read all
// extract gzipped subtitle on-the-fly
try {
stream = new GZIPInputStream(stream);
} catch (ZipException e) {
throw new IOException(String.format("%s: anti-leech limit may have been reached", e.getMessage()));
}
// fully download
buffer.transferFully(stream);
return buffer.getByteBuffer();