All Downloads are FREE. Search and download functionalities are using the official Maven repository.

me.tongfei.progressbar.Util Maven / Gradle / Ivy

package me.tongfei.progressbar;

import java.io.FileInputStream;
import java.io.InputStream;
import java.io.IOException;
import java.time.Duration;

/**
 * @author Tongfei Chen
 * @since 0.5.0
 */
class Util {

    static String repeat(char c, int n) {
        if (n <= 0) return "";
        char[] s = new char[n];
        for (int i = 0; i < n; i++) s[i] = c;
        return new String(s);
    }

    static String formatDuration(Duration d) {
        long s = d.getSeconds();
        return String.format("%d:%02d:%02d", s / 3600, (s % 3600) / 60, s % 60);
    }

    static long getInputStreamSize(InputStream is) {
        try {
            if (is instanceof FileInputStream)
                return ((FileInputStream) is).getChannel().size();
        }
        catch (IOException e) {
            return -1;
        }
        return -1;
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy