* increase read-buffer
This commit is contained in:
parent
611a6bf637
commit
bd45c798d4
|
@ -86,7 +86,7 @@ public final class VerificationUtilities {
|
|||
InputStream in = new FileInputStream(file);
|
||||
|
||||
try {
|
||||
byte[] buffer = new byte[32 * 1024];
|
||||
byte[] buffer = new byte[BUFFER_SIZE];
|
||||
int len = 0;
|
||||
|
||||
while ((len = in.read(buffer)) >= 0) {
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
|
||||
package net.filebot.ui.sfv;
|
||||
|
||||
import static net.filebot.util.FileUtilities.*;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
|
@ -14,21 +14,16 @@ import javax.swing.SwingWorker;
|
|||
import net.filebot.hash.Hash;
|
||||
import net.filebot.hash.HashType;
|
||||
|
||||
|
||||
class ChecksumComputationTask extends SwingWorker<Map<HashType, String>, Void> {
|
||||
|
||||
private static final int BUFFER_SIZE = 32 * 1024;
|
||||
|
||||
private final File file;
|
||||
private final HashType hashType;
|
||||
|
||||
|
||||
public ChecksumComputationTask(File file, HashType hashType) {
|
||||
this.file = file;
|
||||
this.hashType = hashType;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
protected Map<HashType, String> doInBackground() throws Exception {
|
||||
// create hash instance
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
|
||||
package net.filebot.util;
|
||||
|
||||
|
||||
import static net.filebot.util.FileUtilities.*;
|
||||
import static net.filebot.web.WebRequest.*;
|
||||
|
||||
import java.io.IOException;
|
||||
|
@ -19,13 +18,11 @@ import java.util.Map.Entry;
|
|||
|
||||
import javax.swing.SwingWorker;
|
||||
|
||||
|
||||
public class DownloadTask extends SwingWorker<ByteBuffer, Void> {
|
||||
|
||||
public static final String DOWNLOAD_STATE = "download state";
|
||||
public static final String DOWNLOAD_PROGRESS = "download progress";
|
||||
|
||||
|
||||
public static enum DownloadState {
|
||||
PENDING, CONNECTING, DOWNLOADING, DONE
|
||||
}
|
||||
|
@ -39,12 +36,10 @@ public class DownloadTask extends SwingWorker<ByteBuffer, Void> {
|
|||
private Map<String, String> requestHeaders;
|
||||
private Map<String, List<String>> responseHeaders;
|
||||
|
||||
|
||||
public DownloadTask(URL url) {
|
||||
this.url = url;
|
||||
}
|
||||
|
||||
|
||||
protected HttpURLConnection createConnection() throws Exception {
|
||||
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
|
||||
|
||||
|
@ -57,7 +52,6 @@ public class DownloadTask extends SwingWorker<ByteBuffer, Void> {
|
|||
return connection;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
protected ByteBuffer doInBackground() throws Exception {
|
||||
setDownloadState(DownloadState.CONNECTING);
|
||||
|
@ -87,7 +81,7 @@ public class DownloadTask extends SwingWorker<ByteBuffer, Void> {
|
|||
setDownloadState(DownloadState.DOWNLOADING);
|
||||
|
||||
ReadableByteChannel in = Channels.newChannel(connection.getInputStream());
|
||||
ByteBufferOutputStream buffer = new ByteBufferOutputStream((int) (contentLength > 0 ? contentLength : 32 * 1024));
|
||||
ByteBufferOutputStream buffer = new ByteBufferOutputStream((int) (contentLength > 0 ? contentLength : BUFFER_SIZE));
|
||||
|
||||
try {
|
||||
while (!isCancelled() && ((buffer.transferFrom(in)) >= 0)) {
|
||||
|
@ -114,53 +108,43 @@ public class DownloadTask extends SwingWorker<ByteBuffer, Void> {
|
|||
return buffer.getByteBuffer();
|
||||
}
|
||||
|
||||
|
||||
protected void setDownloadState(DownloadState state) {
|
||||
this.state = state;
|
||||
firePropertyChange(DOWNLOAD_STATE, null, state);
|
||||
}
|
||||
|
||||
|
||||
public DownloadState getDownloadState() {
|
||||
return state;
|
||||
}
|
||||
|
||||
|
||||
public URL getUrl() {
|
||||
return url;
|
||||
}
|
||||
|
||||
|
||||
public boolean isContentLengthKnown() {
|
||||
return contentLength >= 0;
|
||||
}
|
||||
|
||||
|
||||
public long getContentLength() {
|
||||
return contentLength;
|
||||
}
|
||||
|
||||
|
||||
public void setRequestHeaders(Map<String, String> requestHeaders) {
|
||||
this.requestHeaders = new HashMap<String, String>(requestHeaders);
|
||||
}
|
||||
|
||||
|
||||
public void setPostParameters(Map<String, String> postParameters) {
|
||||
this.postParameters = new HashMap<String, String>(postParameters);
|
||||
}
|
||||
|
||||
|
||||
public Map<String, List<String>> getResponseHeaders() {
|
||||
return responseHeaders;
|
||||
}
|
||||
|
||||
|
||||
public Map<String, String> getPostParameters() {
|
||||
return postParameters;
|
||||
}
|
||||
|
||||
|
||||
public Map<String, String> getRequestHeaders() {
|
||||
return requestHeaders;
|
||||
}
|
||||
|
|
|
@ -642,6 +642,8 @@ public final class FileUtilities {
|
|||
return buffer.toString();
|
||||
}
|
||||
|
||||
public static final int BUFFER_SIZE = 64 * 1024;
|
||||
|
||||
public static final long KILO = 1024;
|
||||
public static final long MEGA = 1024 * KILO;
|
||||
public static final long GIGA = 1024 * MEGA;
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
package net.filebot.web;
|
||||
|
||||
import static net.filebot.util.FileUtilities.*;
|
||||
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
|
@ -185,7 +187,7 @@ public final class WebRequest {
|
|||
in = new InflaterInputStream(in, new Inflater(true));
|
||||
}
|
||||
|
||||
ByteBufferOutputStream buffer = new ByteBufferOutputStream(contentLength >= 0 ? contentLength : 32 * 1024);
|
||||
ByteBufferOutputStream buffer = new ByteBufferOutputStream(contentLength >= 0 ? contentLength : BUFFER_SIZE);
|
||||
try {
|
||||
// read all
|
||||
buffer.transferFully(in);
|
||||
|
|
Loading…
Reference in New Issue