Search in sources :

Example 1 with ProgressBarBuilder

use of me.tongfei.progressbar.ProgressBarBuilder in project Magma-1.16.x by magmafoundation.

the class LibraryDownloader method run.

public static void run() throws Exception {
    System.out.println("Starting Library Downloader");
    JsonArray libs = parseLibraryJson(new InputStreamReader(LibraryDownloader.class.getResourceAsStream("/magma_libs.json")));
    List<Libary> libaryList = new ArrayList<>();
    ExecutorService executor = Executors.newFixedThreadPool(Runtime.getRuntime().availableProcessors());
    List<CompletableFuture<Void>> futures = new ArrayList<>();
    try (ProgressBar progressBar = new ProgressBarBuilder().setInitialMax(libs.size()).setUpdateIntervalMillis(1000).setTaskName("Downloading libraries").setStyle(ProgressBarStyle.ASCII).showSpeed().build()) {
        libs.forEach(jsonElement -> futures.add(CompletableFuture.runAsync(() -> {
            String name = jsonElement.getAsJsonObject().get("name").getAsString();
            String repo = jsonElement.getAsJsonObject().get("repo").getAsString();
            String md5 = jsonElement.getAsJsonObject().get("md5").getAsString();
            String ext = null;
            if (jsonElement.getAsJsonObject().get("ext") != null) {
                ext = jsonElement.getAsJsonObject().get("ext").getAsString();
            }
            Libary libary = craftLibary(name, repo, md5, ext);
            libaryList.add(libary);
            try {
                libary.file = downloadFile(libary);
                synchronized (progressBar) {
                    progressBar.step();
                }
            } catch (Exception e) {
                e.printStackTrace();
            }
        }, executor)));
        CompletableFuture.allOf(futures.toArray(new CompletableFuture[0])).exceptionally(throwable -> {
            throw new RuntimeException(throwable);
        }).get();
    }
    libaryList.forEach(libary -> {
        try {
            new JarLoader().loadJar(libary.getFile());
        } catch (Exception e) {
            e.printStackTrace();
        }
    });
}
Also used : ProgressBarBuilder(me.tongfei.progressbar.ProgressBarBuilder) ReadableByteChannel(java.nio.channels.ReadableByteChannel) ProgressBar(me.tongfei.progressbar.ProgressBar) JarLoader(org.magmafoundation.magma.utils.JarLoader) URL(java.net.URL) Channels(java.nio.channels.Channels) FileOutputStream(java.io.FileOutputStream) IOException(java.io.IOException) CompletableFuture(java.util.concurrent.CompletableFuture) Reader(java.io.Reader) InputStreamReader(java.io.InputStreamReader) File(java.io.File) Executors(java.util.concurrent.Executors) GsonBuilder(com.google.gson.GsonBuilder) ArrayList(java.util.ArrayList) JsonElement(com.google.gson.JsonElement) List(java.util.List) JsonArray(com.google.gson.JsonArray) Gson(com.google.gson.Gson) ProgressBarStyle(me.tongfei.progressbar.ProgressBarStyle) MD5Checksum(org.magmafoundation.magma.utils.MD5Checksum) ExecutorService(java.util.concurrent.ExecutorService) InputStreamReader(java.io.InputStreamReader) ArrayList(java.util.ArrayList) IOException(java.io.IOException) JsonArray(com.google.gson.JsonArray) CompletableFuture(java.util.concurrent.CompletableFuture) ProgressBarBuilder(me.tongfei.progressbar.ProgressBarBuilder) JarLoader(org.magmafoundation.magma.utils.JarLoader) ExecutorService(java.util.concurrent.ExecutorService) ProgressBar(me.tongfei.progressbar.ProgressBar)

Example 2 with ProgressBarBuilder

use of me.tongfei.progressbar.ProgressBarBuilder in project bsl-language-server by 1c-syntax.

the class FormatCommand method call.

public Integer call() {
    serverContext.clear();
    Path srcDir = Absolute.path(srcDirOption);
    if (!srcDir.toFile().exists()) {
        LOGGER.error("Source dir `{}` is not exists", srcDir);
        return 1;
    }
    Collection<File> files;
    if (srcDir.toFile().isDirectory()) {
        files = FileUtils.listFiles(srcDir.toFile(), new String[] { "bsl", "os" }, true);
    } else {
        files = Collections.singletonList(srcDir.toFile());
    }
    if (silentMode) {
        files.parallelStream().forEach(this::formatFile);
    } else {
        try (ProgressBar pb = new ProgressBarBuilder().setTaskName("Formatting files...").setInitialMax(files.size()).setStyle(ProgressBarStyle.ASCII).build()) {
            files.parallelStream().forEach((File file) -> {
                pb.step();
                formatFile(file);
            });
        }
    }
    return 0;
}
Also used : Path(java.nio.file.Path) ProgressBarBuilder(me.tongfei.progressbar.ProgressBarBuilder) File(java.io.File) ProgressBar(me.tongfei.progressbar.ProgressBar)

Example 3 with ProgressBarBuilder

use of me.tongfei.progressbar.ProgressBarBuilder in project drasyl by drasyl-overlay.

the class WormholeFileReceiver method handlerAdded.

@SuppressWarnings("ResultOfMethodCallIgnored")
@Override
public void handlerAdded(final ChannelHandlerContext ctx) {
    out.println("Receiving file (" + numberToHumanData(length) + ") into: " + file.getName());
    if (file.exists()) {
        ctx.fireExceptionCaught(new FileExistException(file.getName()));
        return;
    }
    try {
        // NOSONAR
        file.createNewFile();
        randomAccessFile = new RandomAccessFile(file, "rw");
    } catch (final IOException e) {
        ctx.fireExceptionCaught(e);
        return;
    }
    progressBar = new ProgressBarBuilder().setInitialMax(length).setUnit("MB", 1_000_000).setStyle(ProgressBarStyle.ASCII).setUpdateIntervalMillis(PROGRESS_BAR_INTERVAL).showSpeed(PROGRESS_BAR_SPEED_FORMAT).build();
    ctx.pipeline().addBefore(ctx.name(), null, new ReadTimeoutHandler(IDLE_TIMEOUT));
}
Also used : RandomAccessFile(java.io.RandomAccessFile) ProgressBarBuilder(me.tongfei.progressbar.ProgressBarBuilder) ReadTimeoutHandler(io.netty.handler.timeout.ReadTimeoutHandler) IOException(java.io.IOException)

Example 4 with ProgressBarBuilder

use of me.tongfei.progressbar.ProgressBarBuilder in project parallel-consumer by confluentinc.

the class ProgressBarUtils method getNewMessagesBar.

public static ProgressBar getNewMessagesBar(String name, Logger log, int initialMax) {
    DelegatingProgressBarConsumer delegatingProgressBarConsumer = new DelegatingProgressBarConsumer(log::info);
    String usedName = "progress";
    if (name != null)
        usedName = name;
    ProgressBar build = new ProgressBarBuilder().setConsumer(delegatingProgressBarConsumer).setInitialMax(initialMax).showSpeed().setTaskName(usedName).setUnit("msg", 1).build();
    return build;
}
Also used : ProgressBarBuilder(me.tongfei.progressbar.ProgressBarBuilder) DelegatingProgressBarConsumer(me.tongfei.progressbar.DelegatingProgressBarConsumer) ProgressBar(me.tongfei.progressbar.ProgressBar)

Example 5 with ProgressBarBuilder

use of me.tongfei.progressbar.ProgressBarBuilder in project Universal-G-Code-Sender by winder.

the class ProgressBarPrinter method UGSEvent.

@Override
public void UGSEvent(UGSEvent event) {
    if (event instanceof FileStateEvent) {
        FileStateEvent fileStateEvent = (FileStateEvent) event;
        if (fileStateEvent.getFileState() == FileState.FILE_LOADED) {
            pb = new ProgressBarBuilder().setStyle(ProgressBarStyle.UNICODE_BLOCK).setInitialMax(100).setTaskName(backend.getGcodeFile().getName()).setPrintStream(System.out).build();
        } else if (fileStateEvent.getFileState() == FileState.FILE_STREAM_COMPLETE) {
            if (pb != null) {
                pb.maxHint(backend.getNumRows());
                pb.stepTo(backend.getNumCompletedRows());
                pb.close();
                pb = null;
            }
        }
    } else if (event instanceof ControllerStateEvent && pb != null) {
        ControllerStateEvent controllerStateEvent = (ControllerStateEvent) event;
        if (controllerStateEvent.getState() == ControllerState.HOLD) {
            pb.setExtraMessage("[PAUSED] 'ENTER' to resume");
        } else {
            pb.setExtraMessage("[" + controllerStateEvent.getState() + "]");
        }
    } else if (event instanceof CommandEvent) {
        if (pb != null) {
            pb.maxHint(backend.getNumRows());
            pb.stepTo(backend.getNumCompletedRows());
        }
    }
}
Also used : ControllerStateEvent(com.willwinder.universalgcodesender.model.events.ControllerStateEvent) ProgressBarBuilder(me.tongfei.progressbar.ProgressBarBuilder) FileStateEvent(com.willwinder.universalgcodesender.model.events.FileStateEvent) CommandEvent(com.willwinder.universalgcodesender.model.events.CommandEvent)

Aggregations

ProgressBarBuilder (me.tongfei.progressbar.ProgressBarBuilder)10 ProgressBar (me.tongfei.progressbar.ProgressBar)6 File (java.io.File)5 Path (java.nio.file.Path)3 IOException (java.io.IOException)2 ArrayList (java.util.ArrayList)2 List (java.util.List)2 ExecutorService (java.util.concurrent.ExecutorService)2 DelegatingProgressBarConsumer (me.tongfei.progressbar.DelegatingProgressBarConsumer)2 ProgressBarStyle (me.tongfei.progressbar.ProgressBarStyle)2 LanguageServerConfiguration (com.github._1c_syntax.bsl.languageserver.configuration.LanguageServerConfiguration)1 AnalysisInfo (com.github._1c_syntax.bsl.languageserver.reporters.data.AnalysisInfo)1 FileInfo (com.github._1c_syntax.bsl.languageserver.reporters.data.FileInfo)1 Gson (com.google.gson.Gson)1 GsonBuilder (com.google.gson.GsonBuilder)1 JsonArray (com.google.gson.JsonArray)1 JsonElement (com.google.gson.JsonElement)1 CommandEvent (com.willwinder.universalgcodesender.model.events.CommandEvent)1 ControllerStateEvent (com.willwinder.universalgcodesender.model.events.ControllerStateEvent)1 FileStateEvent (com.willwinder.universalgcodesender.model.events.FileStateEvent)1