diff --git a/pom.xml b/pom.xml
index ec03b0826..0e4c77ad2 100644
--- a/pom.xml
+++ b/pom.xml
@@ -3,7 +3,7 @@
4.0.0
com.tonikelope
MegaBasterd
- 7.86
+ 7.87
jar
diff --git a/src/main/java/com/tonikelope/megabasterd/ChunkDownloader.java b/src/main/java/com/tonikelope/megabasterd/ChunkDownloader.java
index f15bf324c..e3caf19d3 100644
--- a/src/main/java/com/tonikelope/megabasterd/ChunkDownloader.java
+++ b/src/main/java/com/tonikelope/megabasterd/ChunkDownloader.java
@@ -41,11 +41,24 @@ public class ChunkDownloader implements Runnable, SecureSingleThreadNotifiable {
private boolean _notified;
private final ArrayList _excluded_proxy_list;
private volatile boolean _reset_current_chunk;
+ private volatile InputStream _chunk_inputstream = null;
private String _current_smart_proxy;
- public void setReset_current_chunk(boolean _reset_current_chunk) {
- this._reset_current_chunk = _reset_current_chunk;
+ public void RESET_CURRENT_CHUNK() {
+
+ if (_chunk_inputstream != null) {
+
+ this._reset_current_chunk = true;
+
+ try {
+ _chunk_inputstream.close();
+ } catch (IOException ex) {
+ Logger.getLogger(ChunkDownloader.class.getName()).log(Level.SEVERE, null, ex);
+ }
+
+ _chunk_inputstream = null;
+ }
}
public ChunkDownloader(int id, Download download) {
@@ -299,7 +312,9 @@ public class ChunkDownloader implements Runnable, SecureSingleThreadNotifiable {
tmp_chunk_file = new File(_download.getChunkmanager().getChunks_dir() + "/" + new File(_download.getFile_name()).getName() + ".chunk" + chunk_id + ".tmp");
- try (InputStream is = new ThrottledInputStream(con.getInputStream(), _download.getMain_panel().getStream_supervisor()); OutputStream tmp_chunk_file_os = new BufferedOutputStream(new FileOutputStream(tmp_chunk_file))) {
+ _chunk_inputstream = new ThrottledInputStream(con.getInputStream(), _download.getMain_panel().getStream_supervisor());
+
+ try (OutputStream tmp_chunk_file_os = new BufferedOutputStream(new FileOutputStream(tmp_chunk_file))) {
init_chunk_time = System.currentTimeMillis();
@@ -309,7 +324,7 @@ public class ChunkDownloader implements Runnable, SecureSingleThreadNotifiable {
if (!_exit && !_download.isStopped() && !_download.getChunkmanager().isExit()) {
- while (!_reset_current_chunk && !_exit && !_download.isStopped() && !_download.getChunkmanager().isExit() && chunk_reads < chunk_size && (reads = is.read(buffer, 0, Math.min((int) (chunk_size - chunk_reads), buffer.length))) != -1) {
+ while (!_reset_current_chunk && !_exit && !_download.isStopped() && !_download.getChunkmanager().isExit() && chunk_reads < chunk_size && (reads = _chunk_inputstream.read(buffer, 0, Math.min((int) (chunk_size - chunk_reads), buffer.length))) != -1) {
tmp_chunk_file_os.write(buffer, 0, reads);
chunk_reads += reads;
@@ -331,12 +346,6 @@ public class ChunkDownloader implements Runnable, SecureSingleThreadNotifiable {
}
}
- if (this._reset_current_chunk) {
- LOG.log(Level.WARNING, "{0} Worker [{1}] FORCE RESET CHUNK [{2}]! {3}", new Object[]{Thread.currentThread().getName(), _id, chunk_id, _download.getFile_name()});
- _current_smart_proxy = null;
- this._reset_current_chunk = false;
- }
-
}
finish_chunk_time = System.currentTimeMillis();
@@ -376,25 +385,6 @@ public class ChunkDownloader implements Runnable, SecureSingleThreadNotifiable {
http_error = 0;
- /*
-
- //Proxy speed benchmark (TO DO: change of strategy. Perform a MEGA speed test without proxies and compare the download speed of the chunks with SmartProxy with respect to this speed (with an adjustment coefficient) in order to know if the proxy is slow.).
- if (_current_smart_proxy != null && finish_chunk_time != -1) {
-
- long chunk_speed = Math.round(chunk_size / (((double) (finish_chunk_time - init_chunk_time - paused)) / 1000));
-
- long expected_chunk_speed = ( MEGA_DOWNLOAD_SPEED / CURRENT_MEGABASTERD_CHUNK_DOWNLOADERS_COUNT ) * SLOW_PROXY_PERC;
-
- if (chunk_speed < expected_chunk_speed) {
-
- LOG.log(Level.INFO, "{0} Worker [{1}] WARNING -> PROXY {2} CHUNK DOWNLOAD SPEED: {3}/s SEEMS TO BE SLOW (expected is {4}/s) {4}", new Object[]{Thread.currentThread().getName(), _id, _current_smart_proxy, formatBytes(chunk_speed), formatBytes(expected_chunk_speed), _download.getFile_name()});
-
- slow_proxy = true;
- }
-
-
- }
- */
_excluded_proxy_list.clear();
_download.getChunkmanager().secureNotify();
@@ -413,6 +403,22 @@ public class ChunkDownloader implements Runnable, SecureSingleThreadNotifiable {
} finally {
+ if (_chunk_inputstream != null) {
+
+ try {
+ _chunk_inputstream.close();
+ } catch (IOException ex) {
+ Logger.getLogger(ChunkDownloader.class.getName()).log(Level.SEVERE, null, ex);
+ }
+ _chunk_inputstream = null;
+ }
+
+ if (_reset_current_chunk) {
+ LOG.log(Level.WARNING, "Worker [{0}] FORCE RESET CHUNK [{1}]! {2}", new Object[]{_id, chunk_id, _download.getFile_name()});
+ _current_smart_proxy = null;
+ _reset_current_chunk = false;
+ }
+
if (chunk_error) {
LOG.log(Level.INFO, "{0} Worker [{1}] has FAILED downloading chunk [{2}]! {3}", new Object[]{Thread.currentThread().getName(), _id, chunk_id, _download.getFile_name()});
@@ -447,7 +453,7 @@ public class ChunkDownloader implements Runnable, SecureSingleThreadNotifiable {
setExit(true);
}
- } else if (!FORCE_SMART_PROXY) {
+ } else {
_current_smart_proxy = null;
}
diff --git a/src/main/java/com/tonikelope/megabasterd/DownloadManager.java b/src/main/java/com/tonikelope/megabasterd/DownloadManager.java
index c9d105964..582cac13f 100644
--- a/src/main/java/com/tonikelope/megabasterd/DownloadManager.java
+++ b/src/main/java/com/tonikelope/megabasterd/DownloadManager.java
@@ -42,7 +42,7 @@ public class DownloadManager extends TransferenceManager {
ArrayList chunkworkers = ((Download) transference).getChunkworkers();
chunkworkers.forEach((worker) -> {
- worker.setReset_current_chunk(true);
+ worker.RESET_CURRENT_CHUNK();
});
});
diff --git a/src/main/java/com/tonikelope/megabasterd/FileGrabberDialog.java b/src/main/java/com/tonikelope/megabasterd/FileGrabberDialog.java
index ebb473092..0722b6331 100644
--- a/src/main/java/com/tonikelope/megabasterd/FileGrabberDialog.java
+++ b/src/main/java/com/tonikelope/megabasterd/FileGrabberDialog.java
@@ -522,7 +522,7 @@ public class FileGrabberDialog extends javax.swing.JDialog {
_base_path = files_selected[0].getParentFile().getAbsolutePath();
- dir_name_textfield.setText(files_selected[0].getParentFile().getName() + "_" + String.valueOf(System.currentTimeMillis()/1000));
+ dir_name_textfield.setText(files_selected[0].getParentFile().getName() + "_" + String.valueOf(System.currentTimeMillis() / 1000));
dir_name_textfield.setEnabled(true);
@@ -624,7 +624,7 @@ public class FileGrabberDialog extends javax.swing.JDialog {
_base_path = filechooser.getSelectedFile().getAbsolutePath();
- dir_name_textfield.setText(filechooser.getSelectedFile().getName() + "_" + String.valueOf(System.currentTimeMillis()/1000));
+ dir_name_textfield.setText(filechooser.getSelectedFile().getName() + "_" + String.valueOf(System.currentTimeMillis() / 1000));
dir_name_textfield.setEnabled(true);
@@ -988,7 +988,7 @@ public class FileGrabberDialog extends javax.swing.JDialog {
_base_path = (files.size() == 1 && files.get(0).isDirectory()) ? files.get(0).getAbsolutePath() : files.get(0).getParentFile().getAbsolutePath();
MiscTools.GUIRunAndWait(() -> {
- dir_name_textfield.setText(((files.size() == 1 && files.get(0).isDirectory()) ? files.get(0).getName() : files.get(0).getParentFile().getName()) + "_" + String.valueOf(System.currentTimeMillis()/1000));
+ dir_name_textfield.setText(((files.size() == 1 && files.get(0).isDirectory()) ? files.get(0).getName() : files.get(0).getParentFile().getName()) + "_" + String.valueOf(System.currentTimeMillis() / 1000));
dir_name_textfield.setEnabled(true);
diff --git a/src/main/java/com/tonikelope/megabasterd/MainPanel.java b/src/main/java/com/tonikelope/megabasterd/MainPanel.java
index 43c6a6c9c..b60c5d6d2 100644
--- a/src/main/java/com/tonikelope/megabasterd/MainPanel.java
+++ b/src/main/java/com/tonikelope/megabasterd/MainPanel.java
@@ -69,7 +69,7 @@ import javax.swing.UIManager;
*/
public final class MainPanel {
- public static final String VERSION = "7.86";
+ public static final String VERSION = "7.87";
public static final boolean FORCE_SMART_PROXY = false; //TRUE FOR DEBUGING SMART PROXY
public static final int THROTTLE_SLICE_SIZE = 16 * 1024;
public static final int DEFAULT_BYTE_BUFFER_SIZE = 16 * 1024;