| Author | DaveJarvis <email> |
|---|---|
| Date | 2023-05-06 18:12:40 GMT-0700 |
| Commit | dbb30d02fc805c98cd694e54fe4a4338bf37b832 |
| Parent | 44ad189 |
| Delta | 15 lines added, 15 lines removed |
| import org.junit.jupiter.api.Test; | ||
| +import java.io.File; | ||
| import java.io.IOException; | ||
| -import java.io.OutputStream; | ||
| import java.net.URISyntaxException; | ||
| import java.util.concurrent.ExecutionException; | ||
| import java.util.concurrent.Executors; | ||
| import java.util.concurrent.atomic.AtomicInteger; | ||
| import java.util.concurrent.atomic.AtomicLong; | ||
| import static com.keenwrite.io.downloads.DownloadManager.ProgressListener; | ||
| import static com.keenwrite.io.downloads.DownloadManager.open; | ||
| -import static java.io.OutputStream.nullOutputStream; | ||
| import static java.lang.System.setProperty; | ||
| import static org.junit.jupiter.api.Assertions.*; | ||
| final var transferred = new AtomicLong(); | ||
| - final OutputStream output = nullOutputStream(); | ||
| final ProgressListener listener = ( percentage, bytes ) -> { | ||
| complete.set( percentage ); | ||
| transferred.set( bytes ); | ||
| }; | ||
| + | ||
| + final var file = File.createTempFile("kw-", "test"); | ||
| + file.deleteOnExit(); | ||
| final var token = open( URL ); | ||
| final var executor = Executors.newFixedThreadPool( 1 ); | ||
| - final var result = token.download( output, listener ); | ||
| + final var result = token.download( file, listener ); | ||
| final var future = executor.submit( result ); | ||
| assertFalse( future.isDone() ); | ||
| assertTrue( complete.get() < 100 ); | ||
| - System.out.println( "tx.get: " + transferred.get() ); | ||
| assertTrue( transferred.get() > 100_000 ); | ||
| import java.io.File; | ||
| -import java.io.FileOutputStream; | ||
| import java.net.URI; | ||
| import java.nio.file.Paths; | ||
| final Task<Void> task = createTask( () -> { | ||
| try( final var token = DownloadManager.open( uri ) ) { | ||
| - final var output = new FileOutputStream( file ); | ||
| - final var downloader = token.download( output, listener ); | ||
| - | ||
| - downloader.run(); | ||
| + token.download( file, listener ).run(); | ||
| } | ||
| import java.util.function.Consumer; | ||
| +import static com.keenwrite.events.StatusEvent.clue; | ||
| +import static java.nio.charset.StandardCharsets.UTF_8; | ||
| import static javax.xml.xpath.XPathConstants.NODE; | ||
| return node.getTextContent(); | ||
| } | ||
| - } catch( final XPathExpressionException ignored ) {} | ||
| + } catch( final XPathExpressionException ignored ) { } | ||
| throw new NoSuchElementException( key.toString() ); | ||
| assert config != null; | ||
| - try( final var writer = new FileWriter( config ) ) { | ||
| + try( final var writer = new FileWriter( config, UTF_8 ) ) { | ||
| writer.write( DocumentParser.toString( mDocument ) ); | ||
| } | ||
| node.setTextContent( value ); | ||
| - } catch( final XPathExpressionException ignored ) {} | ||
| + } catch( final XPathExpressionException ex ) { | ||
| + clue( ex ); | ||
| + } | ||
| } | ||
| node.setTextContent( item.toString() ); | ||
| } | ||
| - } catch( final XPathExpressionException ignored ) {} | ||
| + } catch( final XPathExpressionException ignored ) { } | ||
| } | ||
| node.setTextContent( entry.getValue().toString() ); | ||
| - } catch( final XPathExpressionException ignored ) {} | ||
| + } catch( final XPathExpressionException ignored ) { } | ||
| } | ||
| } | ||