UploadStatus .java

com.mojang.realmsclient.client.UploadStatus (class): members: refreshBytesPerSecond, previousBytesWritten, getBytesPerSecond, getBytesWritten, onWrite.

com.mojang.realmsclient.clientclass65 linesclient1.6 KB

API Surface (10)

void setTotalBytes(final long totalBytes)
void restart()
long getTotalBytes()
long getBytesWritten()
void onWrite(final long bytesWritten)
boolean uploadStarted()
boolean uploadCompleted()
double getPercentage()
void refreshBytesPerSecond()
long getBytesPerSecond()

Fields & Constants (5)

bytesWritten
totalBytes
previousTimeSnapshot
previousBytesWritten
bytesPerSecond

Code Graph: Dependencies (1)

Edges (calls / imports / inherits / references) resolved by graphify from the AST. Every chip opens the class source.

Full Source

UploadStatus.java65 lines · Minecraft 26.3 · verbatim
1
package com.mojang.realmsclient.client;
2
3
import net.fabricmc.api.EnvType;
4
import net.fabricmc.api.Environment;
5
import net.minecraft.util.Util;
6
7
@Environment(EnvType.CLIENT)
8
public class UploadStatus {
9
	private volatile long bytesWritten;
10
	private volatile long totalBytes;
11
	private long previousTimeSnapshot = Util.getMillis();
12
	private long previousBytesWritten;
13
	private long bytesPerSecond;
14
15
	public void setTotalBytes(final long totalBytes) {
16
		this.totalBytes = totalBytes;
17
	}
18
19
	public void restart() {
20
		this.bytesWritten = 0L;
21
		this.previousTimeSnapshot = Util.getMillis();
22
		this.previousBytesWritten = 0L;
23
		this.bytesPerSecond = 0L;
24
	}
25
26
	public long getTotalBytes() {
27
		return this.totalBytes;
28
	}
29
30
	public long getBytesWritten() {
31
		return this.bytesWritten;
32
	}
33
34
	public void onWrite(final long bytesWritten) {
35
		this.bytesWritten = bytesWritten;
36
	}
37
38
	public boolean uploadStarted() {
39
		return this.bytesWritten > 0L;
40
	}
41
42
	public boolean uploadCompleted() {
43
		return this.bytesWritten >= this.totalBytes;
44
	}
45
46
	public double getPercentage() {
47
		return Math.min((double)this.getBytesWritten() / this.getTotalBytes(), 1.0);
48
	}
49
50
	public void refreshBytesPerSecond() {
51
		long currentMillis = Util.getMillis();
52
		long timeElapsed = currentMillis - this.previousTimeSnapshot;
53
		if (timeElapsed >= 1000L) {
54
			long bytesWritten = this.bytesWritten;
55
			this.bytesPerSecond = 1000L * (bytesWritten - this.previousBytesWritten) / timeElapsed;
56
			this.previousBytesWritten = bytesWritten;
57
			this.previousTimeSnapshot = currentMillis;
58
		}
59
	}
60
61
	public long getBytesPerSecond() {
62
		return this.bytesPerSecond;
63
	}
64
}
65

Decompiled Minecraft 26.3 source of UploadStatus (com/mojang/realmsclient/client/UploadStatus.java) with Mojang official mappings, stored verbatim on the site.