summaryrefslogtreecommitdiff
path: root/NET/worlds/network/ServerOutputStream.java
diff options
context:
space:
mode:
authorFuwn <[email protected]>2026-02-12 22:33:32 -0800
committerFuwn <[email protected]>2026-02-12 22:33:32 -0800
commitc7a9d4a6bd53ed7d61731770f2f10e8b9fd435f9 (patch)
treedf9f48bf128a6c0186a8e91857d6ff30fe0e9f18 /NET/worlds/network/ServerOutputStream.java
downloadworldsplayer-c7a9d4a6bd53ed7d61731770f2f10e8b9fd435f9.tar.xz
worldsplayer-c7a9d4a6bd53ed7d61731770f2f10e8b9fd435f9.zip
Initial commit
Diffstat (limited to 'NET/worlds/network/ServerOutputStream.java')
-rw-r--r--NET/worlds/network/ServerOutputStream.java97
1 files changed, 97 insertions, 0 deletions
diff --git a/NET/worlds/network/ServerOutputStream.java b/NET/worlds/network/ServerOutputStream.java
new file mode 100644
index 0000000..a95a0f1
--- /dev/null
+++ b/NET/worlds/network/ServerOutputStream.java
@@ -0,0 +1,97 @@
+package NET.worlds.network;
+
+import java.io.FilterOutputStream;
+import java.io.IOException;
+import java.io.OutputStream;
+
+public class ServerOutputStream extends FilterOutputStream {
+ private int _version;
+
+ public ServerOutputStream(OutputStream o) {
+ super(o);
+ this.setVersion(24);
+ }
+
+ public ServerOutputStream(OutputStream o, int vers) {
+ super(o);
+ this.setVersion(vers);
+ }
+
+ public void setVersion(int vers) {
+ this._version = vers;
+ }
+
+ public int getVersion() {
+ return this._version;
+ }
+
+ @Override
+ public final void write(int b) throws IOException {
+ this.out.write(b);
+ }
+
+ @Override
+ public final void write(byte[] b, int off, int len) throws IOException {
+ this.out.write(b, off, len);
+ }
+
+ public final void writeByte(int v) throws IOException {
+ this.out.write(v);
+ }
+
+ public final void writeShort(int v) throws IOException {
+ OutputStream out = this.out;
+ out.write(v >>> 8 & 0xFF);
+ out.write(v >>> 0 & 0xFF);
+ }
+
+ public final void writeInt(int v) throws IOException {
+ OutputStream out = this.out;
+ out.write(v >>> 24 & 0xFF);
+ out.write(v >>> 16 & 0xFF);
+ out.write(v >>> 8 & 0xFF);
+ out.write(v >>> 0 & 0xFF);
+ }
+
+ public static int utfLength(String str) {
+ int strlen = str.length();
+ int utflen = 0;
+
+ for (int i = 0; i < strlen; i++) {
+ int c = str.charAt(i);
+ if (c >= 1 && c <= 127) {
+ utflen++;
+ } else if (c > 2047) {
+ utflen += 3;
+ } else {
+ utflen += 2;
+ }
+ }
+
+ return utflen;
+ }
+
+ public void writeUTF(String str) throws IOException {
+ OutputStream out = this.out;
+ int strlen = str.length();
+ int utflen = utfLength(str);
+
+ assert utflen < 256;
+
+ out.write(utflen >>> 0 & 0xFF);
+
+ for (int i = 0; i < strlen; i++) {
+ int c = str.charAt(i);
+ if (c >= 1 && c <= 127) {
+ out.write(c);
+ } else if (c > 2047) {
+ out.write(224 | c >> 12 & 15);
+ out.write(128 | c >> 6 & 63);
+ out.write(128 | c >> 0 & 63);
+ } else {
+ out.write(192 | c >> 6 & 31);
+ out.write(128 | c >> 0 & 63);
+ }
+ }
+ }
+}