parent
898636c80a
commit
83fcb23e67
@ -0,0 +1,9 @@ |
|||||||
|
package me.bearns.fias.service; |
||||||
|
|
||||||
|
import java.io.InputStream; |
||||||
|
import java.util.concurrent.Future; |
||||||
|
|
||||||
|
public interface Downloader { |
||||||
|
|
||||||
|
public Future<InputStream> download(String url); |
||||||
|
} |
@ -0,0 +1,28 @@ |
|||||||
|
package me.bearns.fias.service; |
||||||
|
|
||||||
|
import java.io.InputStream; |
||||||
|
import java.util.concurrent.CompletableFuture; |
||||||
|
import java.util.concurrent.ExecutorService; |
||||||
|
import java.util.concurrent.Executors; |
||||||
|
import java.util.concurrent.Future; |
||||||
|
|
||||||
|
public class DownloaderImpl implements Downloader { |
||||||
|
|
||||||
|
private static final ExecutorService pool = Executors.newCachedThreadPool(); |
||||||
|
|
||||||
|
@Override |
||||||
|
public Future<InputStream> download(String url) { |
||||||
|
|
||||||
|
CompletableFuture<InputStream> completableFuture |
||||||
|
= new CompletableFuture<>(); |
||||||
|
|
||||||
|
pool.submit(() -> { |
||||||
|
InputStream is = null; |
||||||
|
//todo
|
||||||
|
|
||||||
|
completableFuture.complete(is); |
||||||
|
}); |
||||||
|
|
||||||
|
return completableFuture; |
||||||
|
} |
||||||
|
} |
Loading…
Reference in new issue