2525import java .io .RandomAccessFile ;
2626import java .net .InetSocketAddress ;
2727import java .net .URL ;
28+ import java .nio .channels .FileChannel ;
29+ import java .nio .file .OpenOption ;
30+ import java .nio .file .StandardOpenOption ;
2831import java .util .*;
2932
3033import com .biglybt .core .category .Category ;
@@ -329,9 +332,27 @@ protected Boolean initialValue(){
329332
330333 if ( !data_file .exists () || data_file .length () != MD_TORRENT_SIZE ){
331334
335+ if ( !data_file .exists ()){
336+
337+ try {
338+ Set <OpenOption > options = new HashSet <>();
339+
340+ options .add ( StandardOpenOption .WRITE );
341+ options .add ( StandardOpenOption .CREATE_NEW );
342+ options .add ( StandardOpenOption .SPARSE );
343+
344+ FileChannel fc = FileChannel .open ( data_file .toPath (), options );
345+
346+ fc .close ();
347+
348+ }catch ( Throwable e ){
349+ }
350+ }
351+
332352 RandomAccessFile raf = new RandomAccessFile ( data_file , "rw" );
333353
334354 try {
355+ /*
335356 byte[] buffer = new byte[512*1024];
336357
337358 Arrays.fill( buffer, (byte)0xff );
@@ -340,6 +361,11 @@ protected Boolean initialValue(){
340361
341362 raf.write( buffer );
342363 }
364+ */
365+
366+
367+ raf .setLength ( MD_TORRENT_SIZE );
368+
343369 }finally {
344370
345371 raf .close ();
@@ -371,8 +397,7 @@ protected Boolean initialValue(){
371397
372398 meta_torrent = creator .create ( true );
373399 }
374-
375-
400+
376401 List <String > extras = plugin .getExtraTrackers ();
377402
378403 for ( String extra : extras ){
@@ -520,6 +545,7 @@ protected Boolean initialValue(){
520545 download_manager .addDownloadWillBeAddedListener (dwbal );
521546
522547 try {
548+ data_file .delete ();
523549
524550 download = download_manager .addNonPersistentDownloadStopped ( PluginCoreUtils .wrap ( meta_torrent ), torrent_file , data_file );
525551
0 commit comments