use of cn.nukkit.nbt.stream.FastByteArrayOutputStream in project Nukkit by Nukkit.
the class QueryRegenerateEvent method getShortQuery.
public byte[] getShortQuery(byte[] buffer) {
if (buffer == null)
buffer = new byte[Character.MAX_VALUE];
FastByteArrayOutputStream query = new FastByteArrayOutputStream(buffer);
try {
query.write(this.serverName.getBytes(StandardCharsets.UTF_8));
query.write((byte) 0x00);
query.write(this.gameType.getBytes(StandardCharsets.UTF_8));
query.write((byte) 0x00);
query.write(this.map.getBytes(StandardCharsets.UTF_8));
query.write((byte) 0x00);
query.write(String.valueOf(this.numPlayers).getBytes(StandardCharsets.UTF_8));
query.write((byte) 0x00);
query.write(String.valueOf(this.maxPlayers).getBytes(StandardCharsets.UTF_8));
query.write((byte) 0x00);
query.write(Binary.writeLShort(this.port));
query.write(this.ip.getBytes(StandardCharsets.UTF_8));
query.write((byte) 0x00);
} catch (IOException e) {
e.printStackTrace();
}
return query.toByteArray();
}
use of cn.nukkit.nbt.stream.FastByteArrayOutputStream in project Nukkit by Nukkit.
the class QueryRegenerateEvent method getLongQuery.
public byte[] getLongQuery(byte[] buffer) {
if (buffer == null)
buffer = new byte[Character.MAX_VALUE];
FastByteArrayOutputStream query = new FastByteArrayOutputStream(buffer);
try {
String plist = this.server_engine;
if (this.plugins.length > 0 && this.listPlugins) {
plist += ":";
for (Plugin p : this.plugins) {
PluginDescription d = p.getDescription();
plist += " " + d.getName().replace(";", "").replace(":", "").replace(" ", "_") + " " + d.getVersion().replace(";", "").replace(":", "").replace(" ", "_") + ";";
}
plist = plist.substring(0, plist.length() - 2);
}
query.write("splitnum".getBytes());
query.write((byte) 0x00);
query.write((byte) 128);
query.write((byte) 0x00);
LinkedHashMap<String, String> KVdata = new LinkedHashMap<>();
KVdata.put("hostname", this.serverName);
KVdata.put("gametype", this.gameType);
KVdata.put("game_id", GAME_ID);
KVdata.put("version", this.version);
KVdata.put("server_engine", this.server_engine);
KVdata.put("plugins", plist);
KVdata.put("map", this.map);
KVdata.put("numplayers", String.valueOf(this.numPlayers));
KVdata.put("maxplayers", String.valueOf(this.maxPlayers));
KVdata.put("whitelist", this.whitelist);
KVdata.put("hostip", this.ip);
KVdata.put("hostport", String.valueOf(this.port));
for (Map.Entry<String, String> entry : KVdata.entrySet()) {
query.write(entry.getKey().getBytes(StandardCharsets.UTF_8));
query.write((byte) 0x00);
query.write(entry.getValue().getBytes(StandardCharsets.UTF_8));
query.write((byte) 0x00);
}
query.write(new byte[] { 0x00, 0x01 });
query.write("player_".getBytes());
query.write(new byte[] { 0x00, 0x00 });
for (Player player : this.players) {
query.write(player.getName().getBytes(StandardCharsets.UTF_8));
query.write((byte) 0x00);
}
query.write((byte) 0x00);
} catch (IOException e) {
e.printStackTrace();
}
return query.toByteArray();
}
use of cn.nukkit.nbt.stream.FastByteArrayOutputStream in project Nukkit by Nukkit.
the class ZlibThreadLocal method deflate.
@Override
public byte[] deflate(byte[] data, int level) throws Exception {
Deflater deflater = getDef(level);
if (deflater == null)
throw new IllegalArgumentException("No deflate for level " + level + " !");
deflater.reset();
deflater.setInput(data);
deflater.finish();
FastByteArrayOutputStream bos = ThreadCache.fbaos.get();
bos.reset();
byte[] buffer = buf.get();
while (!deflater.finished()) {
int i = deflater.deflate(buffer);
bos.write(buffer, 0, i);
}
// Deflater::end is called the time when the process exits.
return bos.toByteArray();
}
use of cn.nukkit.nbt.stream.FastByteArrayOutputStream in project Nukkit by Nukkit.
the class ZlibThreadLocal method inflate.
@Override
public byte[] inflate(InputStream stream) throws IOException {
InflaterInputStream inputStream = new InflaterInputStream(stream);
FastByteArrayOutputStream outputStream = ThreadCache.fbaos.get();
outputStream.reset();
int length;
byte[] result;
byte[] buffer = buf.get();
try {
while ((length = inputStream.read(buffer)) != -1) {
outputStream.write(buffer, 0, length);
}
} finally {
result = outputStream.toByteArray();
outputStream.flush();
outputStream.close();
inputStream.close();
}
return result;
}
use of cn.nukkit.nbt.stream.FastByteArrayOutputStream in project Nukkit by Nukkit.
the class ZlibThreadLocal method deflate.
@Override
public byte[] deflate(byte[][] datas, int level) throws Exception {
Deflater deflater = getDef(level);
if (deflater == null)
throw new IllegalArgumentException("No deflate for level " + level + " !");
deflater.reset();
FastByteArrayOutputStream bos = ThreadCache.fbaos.get();
bos.reset();
byte[] buffer = buf.get();
for (byte[] data : datas) {
deflater.setInput(data);
while (!deflater.needsInput()) {
int i = deflater.deflate(buffer);
bos.write(buffer, 0, i);
}
}
deflater.finish();
while (!deflater.finished()) {
int i = deflater.deflate(buffer);
bos.write(buffer, 0, i);
}
// Deflater::end is called the time when the process exits.
return bos.toByteArray();
}
Aggregations