mirror of
https://gitlab.bixilon.de/bixilon/minosoft.git
synced 2025-09-09 15:29:20 -04:00
Remove magic 4096 and save it in constant (default buffer size)
This commit is contained in:
parent
fe890677e4
commit
2802f5506f
@ -47,12 +47,12 @@ public class ChangeableIdentifier extends VersionValueMap<String> {
|
||||
public boolean isValidName(String name, int versionId) {
|
||||
name = name.toLowerCase();
|
||||
if (name.indexOf(":") != 0) {
|
||||
String[] splittedName = name.split(":", 2);
|
||||
if (!mod.equals(splittedName[0])) {
|
||||
String[] splitName = name.split(":", 2);
|
||||
if (!mod.equals(splitName[0])) {
|
||||
// mod is not correct
|
||||
return false;
|
||||
}
|
||||
name = splittedName[1];
|
||||
name = splitName[1];
|
||||
// split and check mod
|
||||
}
|
||||
|
||||
|
@ -23,6 +23,7 @@ import de.bixilon.minosoft.config.ConfigurationPaths;
|
||||
import de.bixilon.minosoft.config.StaticConfiguration;
|
||||
import de.bixilon.minosoft.logging.Log;
|
||||
import de.bixilon.minosoft.logging.LogLevels;
|
||||
import de.bixilon.minosoft.protocol.protocol.ProtocolDefinition;
|
||||
import de.bixilon.minosoft.util.CountUpAndDownLatch;
|
||||
import de.bixilon.minosoft.util.HTTP;
|
||||
import de.bixilon.minosoft.util.Util;
|
||||
@ -266,9 +267,9 @@ public class AssetsManager {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
|
||||
byte[] buffer = new byte[4096];
|
||||
byte[] buffer = new byte[ProtocolDefinition.DEFAULT_BUFFER_SIZE];
|
||||
int length;
|
||||
while ((length = data.read(buffer, 0, 4096)) != -1) {
|
||||
while ((length = data.read(buffer, 0, buffer.length)) != -1) {
|
||||
crypt.update(buffer, 0, length);
|
||||
out.write(buffer, 0, length);
|
||||
}
|
||||
|
@ -37,6 +37,8 @@ public final class ProtocolDefinition {
|
||||
|
||||
public static final String DEFAULT_MOD = "minecraft";
|
||||
|
||||
public static final int DEFAULT_BUFFER_SIZE = 4096;
|
||||
|
||||
static {
|
||||
try {
|
||||
LAN_SERVER_BROADCAST_ADDRESS = InetAddress.getByName("224.0.2.60");
|
||||
|
@ -18,6 +18,7 @@ import com.google.gson.JsonObject;
|
||||
import com.google.gson.JsonParser;
|
||||
import de.bixilon.minosoft.protocol.network.Connection;
|
||||
import de.bixilon.minosoft.protocol.protocol.InByteBuffer;
|
||||
import de.bixilon.minosoft.protocol.protocol.ProtocolDefinition;
|
||||
import org.apache.commons.compress.archivers.tar.TarArchiveEntry;
|
||||
import org.apache.commons.compress.archivers.tar.TarArchiveInputStream;
|
||||
|
||||
@ -56,7 +57,7 @@ public final class Util {
|
||||
public static byte[] decompress(byte[] bytes) {
|
||||
Inflater inflater = new Inflater();
|
||||
inflater.setInput(bytes, 0, bytes.length);
|
||||
byte[] buffer = new byte[4096];
|
||||
byte[] buffer = new byte[ProtocolDefinition.DEFAULT_BUFFER_SIZE];
|
||||
ByteArrayOutputStream stream = new ByteArrayOutputStream(bytes.length);
|
||||
try {
|
||||
while (!inflater.finished()) {
|
||||
@ -73,7 +74,7 @@ public final class Util {
|
||||
Deflater deflater = new Deflater();
|
||||
deflater.setInput(bytes);
|
||||
deflater.finish();
|
||||
byte[] buffer = new byte[4096];
|
||||
byte[] buffer = new byte[ProtocolDefinition.DEFAULT_BUFFER_SIZE];
|
||||
ByteArrayOutputStream stream = new ByteArrayOutputStream(bytes.length);
|
||||
while (!deflater.finished()) {
|
||||
stream.write(buffer, 0, deflater.deflate(buffer));
|
||||
@ -91,11 +92,11 @@ public final class Util {
|
||||
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
|
||||
|
||||
int res = 0;
|
||||
byte[] buf = new byte[4096];
|
||||
byte[] buffer = new byte[ProtocolDefinition.DEFAULT_BUFFER_SIZE];
|
||||
while (res >= 0) {
|
||||
res = gzipInputStream.read(buf, 0, buf.length);
|
||||
res = gzipInputStream.read(buffer, 0, buffer.length);
|
||||
if (res > 0) {
|
||||
outputStream.write(buf, 0, res);
|
||||
outputStream.write(buffer, 0, res);
|
||||
}
|
||||
}
|
||||
gzipInputStream.close();
|
||||
@ -127,9 +128,9 @@ public final class Util {
|
||||
MessageDigest crypt = MessageDigest.getInstance("SHA-1");
|
||||
crypt.reset();
|
||||
|
||||
byte[] buffer = new byte[4096];
|
||||
byte[] buffer = new byte[ProtocolDefinition.DEFAULT_BUFFER_SIZE];
|
||||
int length;
|
||||
while ((length = inputStream.read(buffer, 0, 4096)) != -1) {
|
||||
while ((length = inputStream.read(buffer, 0, buffer.length)) != -1) {
|
||||
crypt.update(buffer, 0, length);
|
||||
}
|
||||
return byteArrayToHexString(crypt.digest());
|
||||
@ -235,9 +236,9 @@ public final class Util {
|
||||
}
|
||||
|
||||
public static void copyFile(InputStream inputStream, OutputStream output) throws IOException {
|
||||
byte[] buffer = new byte[4096];
|
||||
byte[] buffer = new byte[ProtocolDefinition.DEFAULT_BUFFER_SIZE];
|
||||
int length;
|
||||
while ((length = inputStream.read(buffer, 0, 4096)) != -1) {
|
||||
while ((length = inputStream.read(buffer, 0, buffer.length)) != -1) {
|
||||
output.write(buffer, 0, length);
|
||||
}
|
||||
inputStream.close();
|
||||
|
Loading…
x
Reference in New Issue
Block a user