www.hascode.com Open in urlscan Pro
2a01:238:20a:202:1067::  Public Scan

Submitted URL: http://hascode.com/
Effective URL: https://www.hascode.com/
Submission: On February 28 via manual from US — Scanned from DE

Form analysis 1 forms found in the DOM

GET https://www.hascode.com/

<form role="search" method="get" id="searchform" action="https://www.hascode.com/">
  <div><label class="screen-reader-text" for="s">Search for:</label>
    <input type="text" value="" name="s" id="s">
    <input type="submit" id="searchsubmit" value="Search">
  </div>
</form>

Text Content

 * Home
 * 
 * About
 * 
 * External Articles
 * 
 * Snippets
 * 
 * Imprint / Impressum
 * 
 * Datenschutzerklärung
 * 
 * 




hasCode.com micha kops' playground


TERMINAL BASED PROGRESS BAR FOR JAVA APPLICATIONS

March 31st, 2019 by Micha Kops

Recently I needed to add a progress bar to a Java based terminal/console
application and I used a specific library that I’d like to demonstrate in the
following snippet.



Terminal based Progress Bar for Java


CONTENTS

 1. Dependencies
 2. Sample Application
 3. Running the Sample
 4. Tutorial Sources
 5. Resources

 


DEPENDENCIES

Using Maven, we just need to add the following dependency:

<dependency>
    <groupId>me.tongfei</groupId>
    <artifactId>progressbar</artifactId>
    <version>0.7.3</version>
</dependency>


SAMPLE APPLICATION

The application shows how to set up the progress bar and how to advance its
status by-one, by a given amount or to a specific number.

package com.hascode.tutorial;
 
import me.tongfei.progressbar.ProgressBar;
 
public class Sample {
 
  public static void main(String[] args) throws InterruptedException {
    System.out.println("\n");
    try (ProgressBar pb = new ProgressBar("Downloading the internet", 2000)) {
      pb.step();
      Thread.sleep(1_000);
      pb.step();
      Thread.sleep(1_000);
 
      pb.stepBy(248); // step by n
      Thread.sleep(1_000);
 
      pb.stepTo(600); // step directly to n
      Thread.sleep(1_000);
 
      pb.maxHint(2500);
      pb.stepTo(1337);
      pb.stepTo(2500);
      pb.setExtraMessage("Downloading..."); // Set extra message to display at the end of the bar
    }
    System.out.println("we have downloaded the internet ...");
  }
}


RUNNING THE SAMPLE

We may now run the sample application e.g. by using Maven like this:

mvn clean compile exec:java -Dexec.mainClass=com.hascode.tutorial.Sample
[..]
 
Downloading the internet 100% │██████████████████████████████████████████████████████████│ 2500/2500 (0:00:04 / 0:00:00) Downloading...
we have downloaded the internet ...
[..]

Depending on the visual style configured the output might look similar to this
one:

Progressbar in action


TUTORIAL SOURCES

Please feel free to download the tutorial sources from my Bitbucket repository,
fork it there or clone it using Git:

git clone https://bitbucket.org/hascode/java-terminal-progressbar-sample.git


RESOURCES

 * progressbar library on GitHub
 * Project Website

Tags: cli, console, progress-bar, terminal, tools
Posted in Java | 1 Comment »

« Older Entries










Recent Articles


 * Terminal Based Progress Bar for Java Applications
 * Annotation based Kubernetes and Openshift Manifests for Java Applications
   with ap4k
 * Using Throwaway Containers for Integration Testing with Java, JUnit 5 and
   Testcontainers.
 * Next Steps to Pattern Matching in Java with Java 12 and Switch Expressions
   aka JEP 325
 * Implementing Reactive Client-Server Communication over TCP or Websockets with
   RSocket and Java
 * Analyzing Java Applications on the Fly with Arthas
 * Capacity Planning using the Universal Scalability Law with Java and usl4j
 * Testing OpenAPI / Swagger Schema Compliance with Java, JUnit and
   assertj-swagger
 * Testing Java Applications for Resilience by Simulating Network Problems with
   Toxiproxy, JUnit and the Docker Maven Plugin
 * Using jetstreamDB as in-memory Database for Java










Search


Search for:









Archive


 * March 2019
 * February 2019
 * January 2019
 * December 2018
 * November 2018
 * October 2018
 * September 2018
 * August 2018
 * July 2018
 * June 2018
 * May 2018
 * April 2018
 * March 2018
 * February 2018
 * January 2018
 * December 2017
 * November 2017
 * October 2017
 * September 2017
 * August 2017
 * July 2017
 * June 2017
 * May 2017
 * April 2017
 * March 2017
 * February 2017
 * January 2017
 * December 2016
 * November 2016
 * October 2016
 * September 2016
 * August 2016
 * July 2016
 * June 2016
 * May 2016
 * April 2016
 * March 2016
 * February 2016
 * January 2016
 * December 2015
 * November 2015
 * October 2015
 * September 2015
 * August 2015
 * July 2015
 * June 2015
 * May 2015
 * April 2015
 * March 2015
 * February 2015
 * January 2015
 * December 2014
 * November 2014
 * October 2014
 * September 2014
 * August 2014
 * July 2014
 * June 2014
 * May 2014
 * April 2014
 * March 2014
 * February 2014
 * January 2014
 * December 2013
 * November 2013
 * October 2013
 * September 2013
 * August 2013
 * July 2013
 * June 2013
 * May 2013
 * April 2013
 * March 2013
 * February 2013
 * January 2013
 * December 2012
 * November 2012
 * October 2012
 * September 2012
 * August 2012
 * July 2012
 * June 2012
 * May 2012
 * April 2012
 * March 2012
 * February 2012
 * January 2012
 * December 2011
 * November 2011
 * October 2011
 * September 2011
 * August 2011
 * July 2011
 * June 2011
 * May 2011
 * April 2011
 * March 2011
 * February 2011
 * January 2011
 * December 2010
 * November 2010
 * October 2010
 * September 2010
 * August 2010
 * July 2010
 * June 2010
 * May 2010
 * April 2010
 * March 2010










Tags


activiti activity adb adt agile ajax analyzer Android annotation aop Apache Api
app architecture arquillian asynchronous Atlassian authentication Axis Axis2 bdd
benchmark Build camel cd cdi certification chat ci client closure cloud config
Confluence consumer container continuous delivery cucumber cypher database db
dependency dependency injection deployment Development di docker document
documentation drools dsl eclipse eclipselink eip ejb embedded emulator
Enterprise event exam example facelet facet failsafe filter functional gatling
generator glassfish google gradle graph groovy gui guvnor hamcrest hibernate
html html5 http imap index indexer integration integrationtest integration test
IoC it jackson Java java8 java9 javaee java ee javaee7 java fx javascript java
server faces jax-b jax-rs jax-ws jaxb jaxrs jbehave jboss jconsole jdbc jee
jenkins jersey jetty jira jmeter jms jmx jndi jpa js jsf json junit jvm lambda
logging lucene matcher maven memory messaging metrics mobile mock mojarra neo4j
netflix node nosql npm oauth2 orm osgi parser persistence plugin primefaces
profiling properties publisher reactive resilient rest rest-assured restful rich
client rule sbt scala scenario schema search security selenium sensor server
service servlet smartphone Snippet soap source spring spring-boot statistics
story stream stub subscribe surefire swagger tdd test testing testrule tomcat
tools tutorial unit test velocity vert.x vertx webdriver webservice websocket
websockets wiki ws wsdl xml yaml zookeeper









Categories


 * Android (18)
 * Apps (9)
 * Confluence (11)
 * Development (29)
 * dvcs (1)
 * Enterprise (22)
 * Groovy/Grails (3)
 * Java (155)
 * Javascript (4)
 * Jira (1)
 * Reading Corner (1)
 * Scala (5)
 * Snippet (5)
 * testing (32)
 * Uncategorized (3)
 * Web (10)
 * Web Services (17)
 * XML (3)










Links


 * Google Profile
 * hasCode on Bitbucket
 * hasCode on ScrumAlliance
 * hasCode on Slideshare
 * hasCode on Twitter
 * hasCode on YouTube
 * Pinterest
 * Pirate Ninja Unicorn
 * Profile Website




















Powered by WordPress and WordPress Theme created with l2aelba.
Entries (RSS) and Comments (RSS).