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