mirror of
https://github.com/VolmitSoftware/Iris.git
synced 2026-04-07 16:26:14 +00:00
Woop works
This commit is contained in:
55
src/main/java/com/volmit/iris/util/data/DUTF.java
Normal file
55
src/main/java/com/volmit/iris/util/data/DUTF.java
Normal file
@@ -0,0 +1,55 @@
|
||||
/*
|
||||
* Iris is a World Generator for Minecraft Bukkit Servers
|
||||
* Copyright (c) 2021 Arcane Arts (Volmit Software)
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.volmit.iris.util.data;
|
||||
|
||||
import java.io.DataInput;
|
||||
import java.io.DataInputStream;
|
||||
import java.io.DataOutput;
|
||||
import java.io.DataOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.OutputStream;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
|
||||
/**
|
||||
* <p>Encodes signed and unsigned values using a common variable-length
|
||||
* scheme, found for example in
|
||||
* <a href="http://code.google.com/apis/protocolbuffers/docs/encoding.html">
|
||||
* Google's Protocol Buffers</a>. It uses fewer bytes to encode smaller values,
|
||||
* but will use slightly more bytes to encode large values.</p>
|
||||
* <p/>
|
||||
* <p>Signed values are further encoded using so-called zig-zag encoding
|
||||
* in order to make them "compatible" with variable-length encoding.</p>
|
||||
*/
|
||||
public final class DUTF {
|
||||
|
||||
private DUTF() {
|
||||
}
|
||||
|
||||
public static void write(String s, DataOutputStream dos) throws IOException {
|
||||
byte[] b = s.getBytes(StandardCharsets.UTF_8);
|
||||
dos.writeShort(b.length);
|
||||
dos.write(b);
|
||||
}
|
||||
|
||||
public static String read(DataInputStream din) throws IOException {
|
||||
byte[] d = new byte[din.readShort()];
|
||||
din.read(d);
|
||||
return new String(d, StandardCharsets.UTF_8);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user