mirror of
https://gitlab.bixilon.de/bixilon/minosoft.git
synced 2025-09-18 03:44:54 -04:00
remove some unused util functions
This commit is contained in:
parent
4fda0e0849
commit
e3ee113b2b
@ -13,7 +13,6 @@
|
|||||||
|
|
||||||
package de.bixilon.minosoft.util;
|
package de.bixilon.minosoft.util;
|
||||||
|
|
||||||
import com.google.common.util.concurrent.ThreadFactoryBuilder;
|
|
||||||
import com.google.gson.Gson;
|
import com.google.gson.Gson;
|
||||||
import com.google.gson.JsonObject;
|
import com.google.gson.JsonObject;
|
||||||
import com.google.gson.JsonParser;
|
import com.google.gson.JsonParser;
|
||||||
@ -29,13 +28,13 @@ import org.jetbrains.annotations.NotNull;
|
|||||||
|
|
||||||
import java.io.*;
|
import java.io.*;
|
||||||
import java.lang.reflect.Field;
|
import java.lang.reflect.Field;
|
||||||
import java.net.URL;
|
|
||||||
import java.net.URLEncoder;
|
import java.net.URLEncoder;
|
||||||
import java.nio.charset.StandardCharsets;
|
import java.nio.charset.StandardCharsets;
|
||||||
import java.security.MessageDigest;
|
import java.security.MessageDigest;
|
||||||
import java.security.NoSuchAlgorithmException;
|
import java.security.NoSuchAlgorithmException;
|
||||||
import java.util.*;
|
import java.util.HashMap;
|
||||||
import java.util.concurrent.ThreadFactory;
|
import java.util.Map;
|
||||||
|
import java.util.Random;
|
||||||
import java.util.zip.*;
|
import java.util.zip.*;
|
||||||
|
|
||||||
@Deprecated(forRemoval = true)
|
@Deprecated(forRemoval = true)
|
||||||
@ -136,14 +135,6 @@ public final class Util {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String sha1(File file) throws IOException {
|
|
||||||
return sha1(new FileInputStream(file));
|
|
||||||
}
|
|
||||||
|
|
||||||
public static String sha1Gzip(File file) throws IOException {
|
|
||||||
return sha1(new GZIPInputStream(new FileInputStream(file)));
|
|
||||||
}
|
|
||||||
|
|
||||||
public static String sha1(InputStream inputStream) throws IOException {
|
public static String sha1(InputStream inputStream) throws IOException {
|
||||||
try {
|
try {
|
||||||
return hash(MessageDigest.getInstance("SHA-1"), inputStream);
|
return hash(MessageDigest.getInstance("SHA-1"), inputStream);
|
||||||
@ -195,13 +186,6 @@ public final class Util {
|
|||||||
return stringBuilder.toString();
|
return stringBuilder.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static JsonObject readJsonFromZip(String fileName, ZipFile zipFile) throws IOException {
|
|
||||||
InputStreamReader reader = getInputSteamFromZip(fileName, zipFile);
|
|
||||||
JsonObject json = JsonParser.parseReader(reader).getAsJsonObject();
|
|
||||||
reader.close();
|
|
||||||
return json;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static InputStreamReader getInputSteamFromZip(String fileName, ZipFile zipFile) throws IOException {
|
public static InputStreamReader getInputSteamFromZip(String fileName, ZipFile zipFile) throws IOException {
|
||||||
return new InputStreamReader(zipFile.getInputStream(zipFile.getEntry(fileName)));
|
return new InputStreamReader(zipFile.getInputStream(zipFile.getEntry(fileName)));
|
||||||
}
|
}
|
||||||
@ -211,16 +195,6 @@ public final class Util {
|
|||||||
return readReader(new BufferedReader(reader), true);
|
return readReader(new BufferedReader(reader), true);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void downloadFile(String url, String destination) throws IOException {
|
|
||||||
createParentFolderIfNotExist(destination);
|
|
||||||
copyStream(getInputStreamByURL(url), new FileOutputStream(destination));
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void downloadFileAsGz(String url, String destination) throws IOException {
|
|
||||||
createParentFolderIfNotExist(destination);
|
|
||||||
copyStream(getInputStreamByURL(url), new GZIPOutputStream(new FileOutputStream(destination)));
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void copyStream(InputStream inputStream, OutputStream output) throws IOException {
|
public static void copyStream(InputStream inputStream, OutputStream output) throws IOException {
|
||||||
byte[] buffer = new byte[ProtocolDefinition.DEFAULT_BUFFER_SIZE];
|
byte[] buffer = new byte[ProtocolDefinition.DEFAULT_BUFFER_SIZE];
|
||||||
int length;
|
int length;
|
||||||
@ -231,17 +205,6 @@ public final class Util {
|
|||||||
output.close();
|
output.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static InputStream getInputStreamByURL(String url) throws IOException {
|
|
||||||
return new URL(url).openConnection().getInputStream();
|
|
||||||
}
|
|
||||||
|
|
||||||
public static ThreadFactory getThreadFactory(String threadName) {
|
|
||||||
return new ThreadFactoryBuilder().setNameFormat(threadName + "/%d").build();
|
|
||||||
}
|
|
||||||
|
|
||||||
public static boolean createParentFolderIfNotExist(String file) {
|
|
||||||
return createParentFolderIfNotExist(new File(file));
|
|
||||||
}
|
|
||||||
|
|
||||||
public static boolean createParentFolderIfNotExist(File file) {
|
public static boolean createParentFolderIfNotExist(File file) {
|
||||||
return file.getParentFile().mkdirs();
|
return file.getParentFile().mkdirs();
|
||||||
@ -260,10 +223,6 @@ public final class Util {
|
|||||||
return chars[(RANDOM.nextInt(chars.length))];
|
return chars[(RANDOM.nextInt(chars.length))];
|
||||||
}
|
}
|
||||||
|
|
||||||
public static char getRandomChar() {
|
|
||||||
return (char) RANDOM.nextInt();
|
|
||||||
}
|
|
||||||
|
|
||||||
public static String getStringBetween(String search, String first, String second) {
|
public static String getStringBetween(String search, String first, String second) {
|
||||||
String result = search.substring(search.indexOf(first) + first.length());
|
String result = search.substring(search.indexOf(first) + first.length());
|
||||||
return result.substring(0, result.indexOf(second));
|
return result.substring(0, result.indexOf(second));
|
||||||
@ -330,15 +289,6 @@ public final class Util {
|
|||||||
return builder.toString();
|
return builder.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String[] headersMapToArray(Map<String, String> headers) {
|
|
||||||
List<String> headerList = new ArrayList<>();
|
|
||||||
for (Map.Entry<String, String> entry : headers.entrySet()) {
|
|
||||||
headerList.add(entry.getKey());
|
|
||||||
headerList.add(entry.getValue());
|
|
||||||
}
|
|
||||||
return headerList.toArray(new String[]{});
|
|
||||||
}
|
|
||||||
|
|
||||||
public static String formatString(String string, Map<String, Object> format) {
|
public static String formatString(String string, Map<String, Object> format) {
|
||||||
String output = string;
|
String output = string;
|
||||||
for (Map.Entry<String, Object> entry : format.entrySet()) {
|
for (Map.Entry<String, Object> entry : format.entrySet()) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user