Add base files

This commit is contained in:
Hosein
2026-06-12 12:18:48 +03:30
commit 240eac0504
17 changed files with 530 additions and 0 deletions
@@ -0,0 +1,37 @@
package com.university.chat.Client;
public class TransferProgress {
private final long total;
private final long startTime;
private static final int WIDTH = 30;
public TransferProgress(long total) {
this.total = total;
this.startTime = System.currentTimeMillis();
}
public void update(long current) {
double percent = (double) current / total;
int filled = (int) (percent * WIDTH);
StringBuilder bar = new StringBuilder("[");
for (int i = 0; i < WIDTH; i++) {
bar.append(i < filled ? "" : " ");
}
bar.append("]");
long elapsed = System.currentTimeMillis() - startTime;
double speed = current / 1024.0 / 1024.0 / (elapsed / 1000.0 + 0.001);
System.out.printf("\r%s %3d%% | %.2f MB/s",
bar,
(int) (percent * 100),
speed);
if (current >= total) {
System.out.println();
}
}
}