* increase read-buffer

This commit is contained in:
Reinhard Pointner 2014-08-17 06:56:48 +00:00
parent 611a6bf637
commit bd45c798d4
5 changed files with 57 additions and 74 deletions

View File

@ -86,7 +86,7 @@ public final class VerificationUtilities {
InputStream in = new FileInputStream(file); InputStream in = new FileInputStream(file);
try { try {
byte[] buffer = new byte[32 * 1024]; byte[] buffer = new byte[BUFFER_SIZE];
int len = 0; int len = 0;
while ((len = in.read(buffer)) >= 0) { while ((len = in.read(buffer)) >= 0) {

View File

@ -1,6 +1,6 @@
package net.filebot.ui.sfv; package net.filebot.ui.sfv;
import static net.filebot.util.FileUtilities.*;
import java.io.File; import java.io.File;
import java.io.FileInputStream; import java.io.FileInputStream;
@ -14,21 +14,16 @@ import javax.swing.SwingWorker;
import net.filebot.hash.Hash; import net.filebot.hash.Hash;
import net.filebot.hash.HashType; import net.filebot.hash.HashType;
class ChecksumComputationTask extends SwingWorker<Map<HashType, String>, Void> { class ChecksumComputationTask extends SwingWorker<Map<HashType, String>, Void> {
private static final int BUFFER_SIZE = 32 * 1024;
private final File file; private final File file;
private final HashType hashType; private final HashType hashType;
public ChecksumComputationTask(File file, HashType hashType) { public ChecksumComputationTask(File file, HashType hashType) {
this.file = file; this.file = file;
this.hashType = hashType; this.hashType = hashType;
} }
@Override @Override
protected Map<HashType, String> doInBackground() throws Exception { protected Map<HashType, String> doInBackground() throws Exception {
// create hash instance // create hash instance

View File

@ -1,7 +1,6 @@
package net.filebot.util; package net.filebot.util;
import static net.filebot.util.FileUtilities.*;
import static net.filebot.web.WebRequest.*; import static net.filebot.web.WebRequest.*;
import java.io.IOException; import java.io.IOException;
@ -19,13 +18,11 @@ import java.util.Map.Entry;
import javax.swing.SwingWorker; import javax.swing.SwingWorker;
public class DownloadTask extends SwingWorker<ByteBuffer, Void> { public class DownloadTask extends SwingWorker<ByteBuffer, Void> {
public static final String DOWNLOAD_STATE = "download state"; public static final String DOWNLOAD_STATE = "download state";
public static final String DOWNLOAD_PROGRESS = "download progress"; public static final String DOWNLOAD_PROGRESS = "download progress";
public static enum DownloadState { public static enum DownloadState {
PENDING, CONNECTING, DOWNLOADING, DONE PENDING, CONNECTING, DOWNLOADING, DONE
} }
@ -39,12 +36,10 @@ public class DownloadTask extends SwingWorker<ByteBuffer, Void> {
private Map<String, String> requestHeaders; private Map<String, String> requestHeaders;
private Map<String, List<String>> responseHeaders; private Map<String, List<String>> responseHeaders;
public DownloadTask(URL url) { public DownloadTask(URL url) {
this.url = url; this.url = url;
} }
protected HttpURLConnection createConnection() throws Exception { protected HttpURLConnection createConnection() throws Exception {
HttpURLConnection connection = (HttpURLConnection) url.openConnection(); HttpURLConnection connection = (HttpURLConnection) url.openConnection();
@ -57,7 +52,6 @@ public class DownloadTask extends SwingWorker<ByteBuffer, Void> {
return connection; return connection;
} }
@Override @Override
protected ByteBuffer doInBackground() throws Exception { protected ByteBuffer doInBackground() throws Exception {
setDownloadState(DownloadState.CONNECTING); setDownloadState(DownloadState.CONNECTING);
@ -87,7 +81,7 @@ public class DownloadTask extends SwingWorker<ByteBuffer, Void> {
setDownloadState(DownloadState.DOWNLOADING); setDownloadState(DownloadState.DOWNLOADING);
ReadableByteChannel in = Channels.newChannel(connection.getInputStream()); 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 { try {
while (!isCancelled() && ((buffer.transferFrom(in)) >= 0)) { while (!isCancelled() && ((buffer.transferFrom(in)) >= 0)) {
@ -114,53 +108,43 @@ public class DownloadTask extends SwingWorker<ByteBuffer, Void> {
return buffer.getByteBuffer(); return buffer.getByteBuffer();
} }
protected void setDownloadState(DownloadState state) { protected void setDownloadState(DownloadState state) {
this.state = state; this.state = state;
firePropertyChange(DOWNLOAD_STATE, null, state); firePropertyChange(DOWNLOAD_STATE, null, state);
} }
public DownloadState getDownloadState() { public DownloadState getDownloadState() {
return state; return state;
} }
public URL getUrl() { public URL getUrl() {
return url; return url;
} }
public boolean isContentLengthKnown() { public boolean isContentLengthKnown() {
return contentLength >= 0; return contentLength >= 0;
} }
public long getContentLength() { public long getContentLength() {
return contentLength; return contentLength;
} }
public void setRequestHeaders(Map<String, String> requestHeaders) { public void setRequestHeaders(Map<String, String> requestHeaders) {
this.requestHeaders = new HashMap<String, String>(requestHeaders); this.requestHeaders = new HashMap<String, String>(requestHeaders);
} }
public void setPostParameters(Map<String, String> postParameters) { public void setPostParameters(Map<String, String> postParameters) {
this.postParameters = new HashMap<String, String>(postParameters); this.postParameters = new HashMap<String, String>(postParameters);
} }
public Map<String, List<String>> getResponseHeaders() { public Map<String, List<String>> getResponseHeaders() {
return responseHeaders; return responseHeaders;
} }
public Map<String, String> getPostParameters() { public Map<String, String> getPostParameters() {
return postParameters; return postParameters;
} }
public Map<String, String> getRequestHeaders() { public Map<String, String> getRequestHeaders() {
return requestHeaders; return requestHeaders;
} }

View File

@ -642,6 +642,8 @@ public final class FileUtilities {
return buffer.toString(); return buffer.toString();
} }
public static final int BUFFER_SIZE = 64 * 1024;
public static final long KILO = 1024; public static final long KILO = 1024;
public static final long MEGA = 1024 * KILO; public static final long MEGA = 1024 * KILO;
public static final long GIGA = 1024 * MEGA; public static final long GIGA = 1024 * MEGA;

View File

@ -1,5 +1,7 @@
package net.filebot.web; package net.filebot.web;
import static net.filebot.util.FileUtilities.*;
import java.io.ByteArrayOutputStream; import java.io.ByteArrayOutputStream;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
@ -185,7 +187,7 @@ public final class WebRequest {
in = new InflaterInputStream(in, new Inflater(true)); 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 { try {
// read all // read all
buffer.transferFully(in); buffer.transferFully(in);