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();
}
});
}
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;
}
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));
}
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;
}
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());
}
}
}
Aggregations