mirror of
https://github.com/tonikelope/megabasterd.git
synced 2025-05-22 19:09:05 +02:00
6.56
-BufferedInputStream ChunkWriterManager
This commit is contained in:
parent
392098d6fa
commit
5fd982bc6c
2
pom.xml
2
pom.xml
@ -3,7 +3,7 @@
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<groupId>com.tonikelope</groupId>
|
||||
<artifactId>MegaBasterd</artifactId>
|
||||
<version>6.55</version>
|
||||
<version>6.56</version>
|
||||
<packaging>jar</packaging>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
|
@ -2,10 +2,12 @@ package com.tonikelope.megabasterd;
|
||||
|
||||
import static com.tonikelope.megabasterd.MainPanel.*;
|
||||
import static com.tonikelope.megabasterd.MiscTools.*;
|
||||
import java.io.BufferedOutputStream;
|
||||
import java.io.File;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.OutputStream;
|
||||
import java.net.HttpURLConnection;
|
||||
import java.net.InetSocketAddress;
|
||||
import java.net.Proxy;
|
||||
@ -146,13 +148,13 @@ public class ChunkDownloader implements Runnable, SecureSingleThreadNotifiable {
|
||||
|
||||
long chunk_id = _download.nextChunkId();
|
||||
|
||||
long chunk_offset = ChunkWriteManager.calculateChunkOffset(chunk_id, Download.CHUNK_SIZE_MULTI);
|
||||
long chunk_offset = ChunkWriterManager.calculateChunkOffset(chunk_id, Download.CHUNK_SIZE_MULTI);
|
||||
|
||||
long chunk_size = ChunkWriteManager.calculateChunkSize(chunk_id, _download.getFile_size(), chunk_offset, Download.CHUNK_SIZE_MULTI);
|
||||
long chunk_size = ChunkWriterManager.calculateChunkSize(chunk_id, _download.getFile_size(), chunk_offset, Download.CHUNK_SIZE_MULTI);
|
||||
|
||||
ChunkWriteManager.checkChunkID(chunk_id, _download.getFile_size(), chunk_offset);
|
||||
ChunkWriterManager.checkChunkID(chunk_id, _download.getFile_size(), chunk_offset);
|
||||
|
||||
String chunk_url = ChunkWriteManager.genChunkUrl(worker_url, _download.getFile_size(), chunk_offset, chunk_size);
|
||||
String chunk_url = ChunkWriterManager.genChunkUrl(worker_url, _download.getFile_size(), chunk_offset, chunk_size);
|
||||
|
||||
if ((_current_smart_proxy != null || http_error == 509) && MainPanel.isUse_smart_proxy() && !MainPanel.isUse_proxy()) {
|
||||
|
||||
@ -260,7 +262,7 @@ 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()); FileOutputStream tmp_chunk_file_os = new FileOutputStream(tmp_chunk_file)) {
|
||||
try (InputStream is = new ThrottledInputStream(con.getInputStream(), _download.getMain_panel().getStream_supervisor()); OutputStream tmp_chunk_file_os = new BufferedOutputStream(new FileOutputStream(tmp_chunk_file))) {
|
||||
|
||||
init_chunk_time = System.currentTimeMillis();
|
||||
|
||||
|
@ -54,11 +54,11 @@ public class ChunkDownloaderMono extends ChunkDownloader {
|
||||
|
||||
chunk_id = getDownload().nextChunkId();
|
||||
|
||||
long chunk_offset = ChunkWriteManager.calculateChunkOffset(chunk_id, 1);
|
||||
long chunk_offset = ChunkWriterManager.calculateChunkOffset(chunk_id, 1);
|
||||
|
||||
long chunk_size = ChunkWriteManager.calculateChunkSize(chunk_id, getDownload().getFile_size(), chunk_offset, 1);
|
||||
long chunk_size = ChunkWriterManager.calculateChunkSize(chunk_id, getDownload().getFile_size(), chunk_offset, 1);
|
||||
|
||||
ChunkWriteManager.checkChunkID(chunk_id, getDownload().getFile_size(), chunk_offset);
|
||||
ChunkWriterManager.checkChunkID(chunk_id, getDownload().getFile_size(), chunk_offset);
|
||||
|
||||
long chunk_reads = 0;
|
||||
|
||||
|
@ -125,13 +125,13 @@ public class ChunkUploader implements Runnable, SecureSingleThreadNotifiable {
|
||||
|
||||
chunk_id = _upload.nextChunkId();
|
||||
|
||||
long chunk_offset = ChunkWriteManager.calculateChunkOffset(chunk_id, Upload.CHUNK_SIZE_MULTI);
|
||||
long chunk_offset = ChunkWriterManager.calculateChunkOffset(chunk_id, Upload.CHUNK_SIZE_MULTI);
|
||||
|
||||
long chunk_size = ChunkWriteManager.calculateChunkSize(chunk_id, _upload.getFile_size(), chunk_offset, Upload.CHUNK_SIZE_MULTI);
|
||||
long chunk_size = ChunkWriterManager.calculateChunkSize(chunk_id, _upload.getFile_size(), chunk_offset, Upload.CHUNK_SIZE_MULTI);
|
||||
|
||||
ChunkWriteManager.checkChunkID(chunk_id, _upload.getFile_size(), chunk_offset);
|
||||
ChunkWriterManager.checkChunkID(chunk_id, _upload.getFile_size(), chunk_offset);
|
||||
|
||||
String chunk_url = ChunkWriteManager.genChunkUrl(worker_url, _upload.getFile_size(), chunk_offset, chunk_size);
|
||||
String chunk_url = ChunkWriterManager.genChunkUrl(worker_url, _upload.getFile_size(), chunk_offset, chunk_size);
|
||||
|
||||
URL url = new URL(chunk_url);
|
||||
|
||||
|
@ -1,6 +1,7 @@
|
||||
package com.tonikelope.megabasterd;
|
||||
|
||||
import static com.tonikelope.megabasterd.CryptTools.*;
|
||||
import java.io.BufferedInputStream;
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.IOException;
|
||||
@ -18,9 +19,42 @@ import javax.crypto.NoSuchPaddingException;
|
||||
*
|
||||
* @author tonikelope
|
||||
*/
|
||||
public class ChunkWriteManager implements Runnable, SecureSingleThreadNotifiable {
|
||||
public class ChunkWriterManager implements Runnable, SecureSingleThreadNotifiable {
|
||||
|
||||
private static final Logger LOG = Logger.getLogger(ChunkWriteManager.class.getName());
|
||||
private static final Logger LOG = Logger.getLogger(ChunkWriterManager.class.getName());
|
||||
private volatile long _last_chunk_id_written;
|
||||
private volatile long _bytes_written;
|
||||
private final long _file_size;
|
||||
private final Download _download;
|
||||
private final byte[] _byte_file_key;
|
||||
private final byte[] _byte_iv;
|
||||
private volatile boolean _exit;
|
||||
private final Object _secure_notify_lock;
|
||||
private boolean _notified;
|
||||
private final String _chunks_dir;
|
||||
|
||||
public ChunkWriterManager(Download downloader) throws Exception {
|
||||
_notified = false;
|
||||
_exit = false;
|
||||
_download = downloader;
|
||||
_chunks_dir = _create_chunks_temp_dir();
|
||||
_secure_notify_lock = new Object();
|
||||
_file_size = _download.getFile_size();
|
||||
_byte_file_key = initMEGALinkKey(_download.getFile_key());
|
||||
_byte_iv = initMEGALinkKeyIV(_download.getFile_key());
|
||||
|
||||
if (_download.getProgress() == 0) {
|
||||
|
||||
_last_chunk_id_written = 0;
|
||||
|
||||
_bytes_written = 0;
|
||||
|
||||
} else {
|
||||
_last_chunk_id_written = _download.getLast_chunk_id_dispatched();
|
||||
|
||||
_bytes_written = _download.getProgress();
|
||||
}
|
||||
}
|
||||
|
||||
public static long calculateChunkOffset(long chunk_id, int size_multi) {
|
||||
long[] offs = {0, 128, 384, 768, 1280, 1920, 2688};
|
||||
@ -58,43 +92,6 @@ public class ChunkWriteManager implements Runnable, SecureSingleThreadNotifiable
|
||||
return chunk_size;
|
||||
}
|
||||
|
||||
private volatile long _last_chunk_id_written;
|
||||
private volatile long _bytes_written;
|
||||
private final long _file_size;
|
||||
private final Download _download;
|
||||
private final byte[] _byte_file_key;
|
||||
private final byte[] _byte_iv;
|
||||
private volatile boolean _exit;
|
||||
private final Object _secure_notify_lock;
|
||||
private boolean _notified;
|
||||
private final String _chunks_dir;
|
||||
|
||||
public ChunkWriteManager(Download downloader) throws Exception {
|
||||
_notified = false;
|
||||
_exit = false;
|
||||
_download = downloader;
|
||||
_chunks_dir = _create_chunks_temp_dir();
|
||||
_secure_notify_lock = new Object();
|
||||
_file_size = _download.getFile_size();
|
||||
_byte_file_key = initMEGALinkKey(_download.getFile_key());
|
||||
_byte_iv = initMEGALinkKeyIV(_download.getFile_key());
|
||||
|
||||
if (_download.getProgress() == 0) {
|
||||
|
||||
_last_chunk_id_written = 0;
|
||||
|
||||
_bytes_written = 0;
|
||||
|
||||
} else {
|
||||
_last_chunk_id_written = _download.getLast_chunk_id_dispatched();
|
||||
|
||||
_bytes_written = _download.getProgress();
|
||||
}
|
||||
|
||||
LOG.log(Level.INFO, "{0} Chunkmanager hello LAST CHUNK WRITTEN -> [{1}] {2}...", new Object[]{Thread.currentThread().getName(), _last_chunk_id_written, _bytes_written});
|
||||
|
||||
}
|
||||
|
||||
public String getChunks_dir() {
|
||||
return _chunks_dir;
|
||||
}
|
||||
@ -149,7 +146,7 @@ public class ChunkWriteManager implements Runnable, SecureSingleThreadNotifiable
|
||||
try {
|
||||
MiscTools.deleteDirectoryRecursion(Paths.get(getChunks_dir()));
|
||||
} catch (IOException ex) {
|
||||
Logger.getLogger(ChunkWriteManager.class.getName()).log(Level.SEVERE, ex.getMessage());
|
||||
Logger.getLogger(ChunkWriterManager.class.getName()).log(Level.SEVERE, ex.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
@ -158,7 +155,9 @@ public class ChunkWriteManager implements Runnable, SecureSingleThreadNotifiable
|
||||
|
||||
try {
|
||||
|
||||
LOG.log(Level.INFO, "{0} Chunkmanager: let's do some work!", Thread.currentThread().getName());
|
||||
LOG.log(Level.INFO, "{0} ChunkWriterManager: let's do some work! {1}", new Object[]{Thread.currentThread().getName(), _download.getFile_name()});
|
||||
|
||||
LOG.log(Level.INFO, "{0} ChunkWriterManager LAST CHUNK WRITTEN -> [{1}] {2} {3}...", new Object[]{Thread.currentThread().getName(), _last_chunk_id_written, _bytes_written, _download.getFile_name()});
|
||||
|
||||
boolean download_finished = false;
|
||||
|
||||
@ -184,7 +183,7 @@ public class ChunkWriteManager implements Runnable, SecureSingleThreadNotifiable
|
||||
|
||||
int reads;
|
||||
|
||||
try (CipherInputStream cis = new CipherInputStream(new FileInputStream(chunk_file), genDecrypter("AES", "AES/CTR/NoPadding", _byte_file_key, forwardMEGALinkKeyIV(_byte_iv, _bytes_written)))) {
|
||||
try (CipherInputStream cis = new CipherInputStream(new BufferedInputStream(new FileInputStream(chunk_file)), genDecrypter("AES", "AES/CTR/NoPadding", _byte_file_key, forwardMEGALinkKeyIV(_byte_iv, _bytes_written)))) {
|
||||
while ((reads = cis.read(buffer)) != -1) {
|
||||
_download.getOutput_stream().write(buffer, 0, reads);
|
||||
}
|
||||
@ -194,7 +193,7 @@ public class ChunkWriteManager implements Runnable, SecureSingleThreadNotifiable
|
||||
|
||||
_bytes_written += chunk_file.length();
|
||||
|
||||
LOG.log(Level.INFO, "{0} Chunkmanager has written to disk chunk [{1}] {2} {3}...", new Object[]{Thread.currentThread().getName(), _last_chunk_id_written + 1, _bytes_written, _download.calculateLastWrittenChunk(_bytes_written)});
|
||||
LOG.log(Level.INFO, "{0} ChunkWriterManager has written to disk chunk [{1}] {2} {3} {4}...", new Object[]{Thread.currentThread().getName(), _last_chunk_id_written + 1, _bytes_written, _download.calculateLastWrittenChunk(_bytes_written), _download.getFile_name()});
|
||||
|
||||
_last_chunk_id_written++;
|
||||
|
||||
@ -205,7 +204,7 @@ public class ChunkWriteManager implements Runnable, SecureSingleThreadNotifiable
|
||||
|
||||
if (!_exit && (!_download.isStopped() || !_download.getChunkworkers().isEmpty()) && _bytes_written < _file_size) {
|
||||
|
||||
LOG.log(Level.INFO, "{0} Chunkmanager waiting for chunk [{1}]...", new Object[]{Thread.currentThread().getName(), _last_chunk_id_written + 1});
|
||||
LOG.log(Level.INFO, "{0} ChunkWriterManager waiting for chunk [{1}] {2}...", new Object[]{Thread.currentThread().getName(), _last_chunk_id_written + 1, _download.getFile_name()});
|
||||
|
||||
secureWait();
|
||||
|
||||
@ -227,7 +226,7 @@ public class ChunkWriteManager implements Runnable, SecureSingleThreadNotifiable
|
||||
|
||||
_download.secureNotify();
|
||||
|
||||
LOG.log(Level.INFO, "{0} Chunkmanager: bye bye{1}", new Object[]{Thread.currentThread().getName(), _download.getFile_name()});
|
||||
LOG.log(Level.INFO, "{0} ChunkWriterManager: bye bye {1}", new Object[]{Thread.currentThread().getName(), _download.getFile_name()});
|
||||
}
|
||||
|
||||
}
|
@ -80,7 +80,7 @@ public class Download implements Transference, Runnable, SecureSingleThreadNotif
|
||||
private volatile boolean _pause;
|
||||
private final ConcurrentLinkedQueue<Long> _partialProgressQueue;
|
||||
private volatile long _progress;
|
||||
private ChunkWriteManager _chunkmanager;
|
||||
private ChunkWriterManager _chunkmanager;
|
||||
private String _last_download_url;
|
||||
private boolean _provision_ok;
|
||||
private boolean _finishing_download;
|
||||
@ -292,7 +292,7 @@ public class Download implements Transference, Runnable, SecureSingleThreadNotif
|
||||
_pause = pause;
|
||||
}
|
||||
|
||||
public ChunkWriteManager getChunkmanager() {
|
||||
public ChunkWriterManager getChunkmanager() {
|
||||
return _chunkmanager;
|
||||
}
|
||||
|
||||
@ -590,7 +590,7 @@ public class Download implements Transference, Runnable, SecureSingleThreadNotif
|
||||
|
||||
if (_use_slots) {
|
||||
|
||||
_chunkmanager = new ChunkWriteManager(this);
|
||||
_chunkmanager = new ChunkWriterManager(this);
|
||||
|
||||
_thread_pool.execute(_chunkmanager);
|
||||
|
||||
@ -1322,11 +1322,11 @@ public class Download implements Transference, Runnable, SecureSingleThreadNotif
|
||||
try {
|
||||
while (!_exit) {
|
||||
|
||||
long chunk_offset = ChunkWriteManager.calculateChunkOffset(chunk_id, 1);
|
||||
long chunk_offset = ChunkWriterManager.calculateChunkOffset(chunk_id, 1);
|
||||
|
||||
long chunk_size = ChunkWriteManager.calculateChunkSize(chunk_id, this.getFile_size(), chunk_offset, 1);
|
||||
long chunk_size = ChunkWriterManager.calculateChunkSize(chunk_id, this.getFile_size(), chunk_offset, 1);
|
||||
|
||||
ChunkWriteManager.checkChunkID(chunk_id, this.getFile_size(), chunk_offset);
|
||||
ChunkWriterManager.checkChunkID(chunk_id, this.getFile_size(), chunk_offset);
|
||||
|
||||
tot += chunk_size;
|
||||
|
||||
|
@ -2,11 +2,13 @@ package com.tonikelope.megabasterd;
|
||||
|
||||
import static com.tonikelope.megabasterd.MainPanel.*;
|
||||
import static com.tonikelope.megabasterd.MiscTools.*;
|
||||
import java.io.BufferedInputStream;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.nio.file.Paths;
|
||||
import java.util.Iterator;
|
||||
import java.util.Set;
|
||||
@ -314,7 +316,7 @@ public class LinkGrabberDialog extends javax.swing.JDialog implements ClipboardC
|
||||
@Override
|
||||
public void run() {
|
||||
|
||||
try (FileInputStream is = new FileInputStream(file); ByteArrayOutputStream out = new ByteArrayOutputStream()) {
|
||||
try (InputStream is = new BufferedInputStream(new FileInputStream(file)); ByteArrayOutputStream out = new ByteArrayOutputStream()) {
|
||||
|
||||
byte[] buffer = new byte[MainPanel.DEFAULT_BYTE_BUFFER_SIZE];
|
||||
|
||||
|
@ -53,7 +53,7 @@ import javax.swing.UIManager;
|
||||
*/
|
||||
public class MainPanel {
|
||||
|
||||
public static final String VERSION = "6.55";
|
||||
public static final String VERSION = "6.56";
|
||||
public static final int THROTTLE_SLICE_SIZE = 16 * 1024;
|
||||
public static final int DEFAULT_BYTE_BUFFER_SIZE = 16 * 1024;
|
||||
public static final int STREAMER_PORT = 1337;
|
||||
|
@ -5,11 +5,14 @@ import static com.tonikelope.megabasterd.MainPanel.*;
|
||||
import static com.tonikelope.megabasterd.MiscTools.*;
|
||||
import java.awt.Dialog;
|
||||
import java.awt.Frame;
|
||||
import java.io.BufferedInputStream;
|
||||
import java.io.BufferedOutputStream;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.ObjectInputStream;
|
||||
import java.io.ObjectOutputStream;
|
||||
import java.nio.file.Paths;
|
||||
@ -2118,7 +2121,7 @@ public class SettingsDialog extends javax.swing.JDialog {
|
||||
|
||||
try {
|
||||
|
||||
try (FileInputStream fis = new FileInputStream(file); ObjectInputStream ois = new ObjectInputStream(fis)) {
|
||||
try (InputStream fis = new BufferedInputStream(new FileInputStream(file)); ObjectInputStream ois = new ObjectInputStream(fis)) {
|
||||
|
||||
HashMap<String, Object> settings = (HashMap<String, Object>) ois.readObject();
|
||||
|
||||
@ -2178,7 +2181,7 @@ public class SettingsDialog extends javax.swing.JDialog {
|
||||
|
||||
file.createNewFile();
|
||||
|
||||
try (FileOutputStream fos = new FileOutputStream(file); ObjectOutputStream oos = new ObjectOutputStream(fos)) {
|
||||
try (BufferedOutputStream fos = new BufferedOutputStream(new FileOutputStream(file)); ObjectOutputStream oos = new ObjectOutputStream(fos)) {
|
||||
|
||||
HashMap<String, Object> settings = new HashMap<>();
|
||||
|
||||
|
@ -127,11 +127,11 @@ public class UploadMACGenerator implements Runnable, SecureSingleThreadNotifiabl
|
||||
|
||||
int reads;
|
||||
|
||||
long chunk_offset = ChunkWriteManager.calculateChunkOffset(chunk_id, 1);
|
||||
long chunk_offset = ChunkWriterManager.calculateChunkOffset(chunk_id, 1);
|
||||
|
||||
long chunk_size = ChunkWriteManager.calculateChunkSize(chunk_id, _upload.getFile_size(), chunk_offset, 1);
|
||||
long chunk_size = ChunkWriterManager.calculateChunkSize(chunk_id, _upload.getFile_size(), chunk_offset, 1);
|
||||
|
||||
ChunkWriteManager.checkChunkID(chunk_id, _upload.getFile_size(), chunk_offset);
|
||||
ChunkWriterManager.checkChunkID(chunk_id, _upload.getFile_size(), chunk_offset);
|
||||
|
||||
try {
|
||||
|
||||
|
Binary file not shown.
Before Width: | Height: | Size: 203 KiB After Width: | Height: | Size: 195 KiB |
Loading…
x
Reference in New Issue
Block a user