mirror of
https://github.com/FalsePattern/FalsePatternLib.git
synced 2026-11-17 02:55:02 +00:00
Annotate all the things
This commit is contained in:
63 files changed
+623
-369
No files matched your search
@@ -28,6 +28,7 @@ import java.io.File;
|
||||
|
||||
@StableAPI(since = "0.8.2")
|
||||
public class FileUtil {
|
||||
@StableAPI.Expose
|
||||
public static File getMinecraftHome() {
|
||||
return Launch.minecraftHome == null ? new File(".") : Launch.minecraftHome;
|
||||
}
|
||||
|
||||
@@ -35,13 +35,16 @@ import static lombok.AccessLevel.PRIVATE;
|
||||
@NoArgsConstructor(access = PRIVATE)
|
||||
@StableAPI(since = "0.8.0")
|
||||
public final class LangUtil {
|
||||
@StableAPI.Expose
|
||||
public static final String DEFAULT_LOCALE = "en_US";
|
||||
private static final ThreadLocal<HashMap<String, String>> tempMap = ThreadLocal.withInitial(HashMap::new);
|
||||
|
||||
@StableAPI.Expose
|
||||
public static void defaultLocalization(@NonNull Map<String, String> localeMap) {
|
||||
localeMap.forEach(LangUtil::defaultLocalization);
|
||||
}
|
||||
|
||||
@StableAPI.Expose
|
||||
public static void defaultLocalization(@NonNull String key, @NonNull String value) {
|
||||
if (!LanguageRegistry.instance().getStringLocalization(key, DEFAULT_LOCALE).isEmpty()) {
|
||||
return;
|
||||
|
||||
@@ -26,8 +26,9 @@ import com.falsepattern.lib.compat.Vec3i;
|
||||
import java.util.Random;
|
||||
import java.util.UUID;
|
||||
|
||||
@StableAPI(since = "0.10.0")
|
||||
public class MathUtil {
|
||||
@StableAPI(since = "0.10.0")
|
||||
@StableAPI.Expose
|
||||
public static final float SQRT_2 = sqrt(2.0F);
|
||||
/**
|
||||
* A table of sin values computed from 0 (inclusive) to 2*pi (exclusive), with steps of 2*PI / 65536.
|
||||
@@ -69,7 +70,7 @@ public class MathUtil {
|
||||
/**
|
||||
* sin looked up in a table
|
||||
*/
|
||||
@StableAPI(since = "0.10.0")
|
||||
@StableAPI.Expose
|
||||
public static float sin(float value) {
|
||||
return SIN_TABLE[(int) (value * 10430.378F) & 65535];
|
||||
}
|
||||
@@ -78,17 +79,17 @@ public class MathUtil {
|
||||
* cos looked up in the sin table with the appropriate offset
|
||||
*/
|
||||
|
||||
@StableAPI(since = "0.10.0")
|
||||
@StableAPI.Expose
|
||||
public static float cos(float value) {
|
||||
return SIN_TABLE[(int) (value * 10430.378F + 16384.0F) & 65535];
|
||||
}
|
||||
|
||||
@StableAPI(since = "0.10.0")
|
||||
@StableAPI.Expose
|
||||
public static float sqrt(float value) {
|
||||
return (float) Math.sqrt(value);
|
||||
}
|
||||
|
||||
@StableAPI(since = "0.10.0")
|
||||
@StableAPI.Expose
|
||||
public static float sqrt(double value) {
|
||||
return (float) Math.sqrt(value);
|
||||
}
|
||||
@@ -96,7 +97,7 @@ public class MathUtil {
|
||||
/**
|
||||
* Returns the greatest integer less than or equal to the float argument
|
||||
*/
|
||||
@StableAPI(since = "0.10.0")
|
||||
@StableAPI.Expose
|
||||
public static int floor(float value) {
|
||||
int i = (int) value;
|
||||
return value < (float) i ? i - 1 : i;
|
||||
@@ -105,7 +106,7 @@ public class MathUtil {
|
||||
/**
|
||||
* returns par0 cast as an int, and no greater than Integer.MAX_VALUE-1024
|
||||
*/
|
||||
@StableAPI(since = "0.10.0")
|
||||
@StableAPI.Expose
|
||||
public static int fastFloor(double value) {
|
||||
return (int) (value + 1024.0D) - 1024;
|
||||
}
|
||||
@@ -113,7 +114,7 @@ public class MathUtil {
|
||||
/**
|
||||
* Returns the greatest integer less than or equal to the double argument
|
||||
*/
|
||||
@StableAPI(since = "0.10.0")
|
||||
@StableAPI.Expose
|
||||
public static int floor(double value) {
|
||||
int i = (int) value;
|
||||
return value < (double) i ? i - 1 : i;
|
||||
@@ -122,18 +123,18 @@ public class MathUtil {
|
||||
/**
|
||||
* Long version of floor()
|
||||
*/
|
||||
@StableAPI(since = "0.10.0")
|
||||
@StableAPI.Expose
|
||||
public static long lfloor(double value) {
|
||||
long i = (long) value;
|
||||
return value < (double) i ? i - 1L : i;
|
||||
}
|
||||
|
||||
@StableAPI(since = "0.10.0")
|
||||
@StableAPI.Expose
|
||||
public static int absFloor(double value) {
|
||||
return (int) (value >= 0.0D ? value : -value + 1.0D);
|
||||
}
|
||||
|
||||
@StableAPI(since = "0.10.0")
|
||||
@StableAPI.Expose
|
||||
public static float abs(float value) {
|
||||
return value >= 0.0F ? value : -value;
|
||||
}
|
||||
@@ -141,18 +142,18 @@ public class MathUtil {
|
||||
/**
|
||||
* Returns the unsigned value of an int.
|
||||
*/
|
||||
@StableAPI(since = "0.10.0")
|
||||
@StableAPI.Expose
|
||||
public static int abs(int value) {
|
||||
return value >= 0 ? value : -value;
|
||||
}
|
||||
|
||||
@StableAPI(since = "0.10.0")
|
||||
@StableAPI.Expose
|
||||
public static int ceil(float value) {
|
||||
int i = (int) value;
|
||||
return value > (float) i ? i + 1 : i;
|
||||
}
|
||||
|
||||
@StableAPI(since = "0.10.0")
|
||||
@StableAPI.Expose
|
||||
public static int ceil(double value) {
|
||||
int i = (int) value;
|
||||
return value > (double) i ? i + 1 : i;
|
||||
@@ -162,7 +163,7 @@ public class MathUtil {
|
||||
* Returns the value of the first parameter, clamped to be within the lower and upper limits given by the second and
|
||||
* third parameters.
|
||||
*/
|
||||
@StableAPI(since = "0.10.0")
|
||||
@StableAPI.Expose
|
||||
public static int clamp(int num, int min, int max) {
|
||||
return num < min ? min : Math.min(num, max);
|
||||
}
|
||||
@@ -171,17 +172,17 @@ public class MathUtil {
|
||||
* Returns the value of the first parameter, clamped to be within the lower and upper limits given by the second and
|
||||
* third parameters
|
||||
*/
|
||||
@StableAPI(since = "0.10.0")
|
||||
@StableAPI.Expose
|
||||
public static float clamp(float num, float min, float max) {
|
||||
return num < min ? min : Math.min(num, max);
|
||||
}
|
||||
|
||||
@StableAPI(since = "0.10.0")
|
||||
@StableAPI.Expose
|
||||
public static double clamp(double num, double min, double max) {
|
||||
return num < min ? min : Math.min(num, max);
|
||||
}
|
||||
|
||||
@StableAPI(since = "0.10.0")
|
||||
@StableAPI.Expose
|
||||
public static double clampedLerp(double lowerBnd, double upperBnd, double slide) {
|
||||
if (slide < 0.0D) {
|
||||
return lowerBnd;
|
||||
@@ -193,7 +194,7 @@ public class MathUtil {
|
||||
/**
|
||||
* Maximum of the absolute value of two numbers.
|
||||
*/
|
||||
@StableAPI(since = "0.10.0")
|
||||
@StableAPI.Expose
|
||||
public static double absMax(double a, double b) {
|
||||
if (a < 0.0D) {
|
||||
a = -a;
|
||||
@@ -209,27 +210,27 @@ public class MathUtil {
|
||||
/**
|
||||
* Buckets an integer with specified bucket sizes.
|
||||
*/
|
||||
@StableAPI(since = "0.10.0")
|
||||
@StableAPI.Expose
|
||||
public static int intFloorDiv(int number, int bucket) {
|
||||
return number < 0 ? -((-number - 1) / bucket) - 1 : number / bucket;
|
||||
}
|
||||
|
||||
@StableAPI(since = "0.10.0")
|
||||
@StableAPI.Expose
|
||||
public static int getInt(Random random, int minimum, int maximum) {
|
||||
return minimum >= maximum ? minimum : random.nextInt(maximum - minimum + 1) + minimum;
|
||||
}
|
||||
|
||||
@StableAPI(since = "0.10.0")
|
||||
@StableAPI.Expose
|
||||
public static float nextFloat(Random random, float minimum, float maximum) {
|
||||
return minimum >= maximum ? minimum : random.nextFloat() * (maximum - minimum) + minimum;
|
||||
}
|
||||
|
||||
@StableAPI(since = "0.10.0")
|
||||
@StableAPI.Expose
|
||||
public static double nextDouble(Random random, double minimum, double maximum) {
|
||||
return minimum >= maximum ? minimum : random.nextDouble() * (maximum - minimum) + minimum;
|
||||
}
|
||||
|
||||
@StableAPI(since = "0.10.0")
|
||||
@StableAPI.Expose
|
||||
public static double average(long[] values) {
|
||||
long i = 0L;
|
||||
|
||||
@@ -240,22 +241,22 @@ public class MathUtil {
|
||||
return (double) i / (double) values.length;
|
||||
}
|
||||
|
||||
@StableAPI(since = "0.10.0")
|
||||
@StableAPI.Expose
|
||||
public static boolean epsilonEquals(float a, float b) {
|
||||
return abs(b - a) < 1.0E-5F;
|
||||
}
|
||||
|
||||
@StableAPI(since = "0.10.0")
|
||||
@StableAPI.Expose
|
||||
public static int normalizeAngle(int a, int b) {
|
||||
return (a % b + b) % b;
|
||||
}
|
||||
|
||||
@StableAPI(since = "0.10.0")
|
||||
@StableAPI.Expose
|
||||
public static float positiveModulo(float numerator, float denominator) {
|
||||
return (numerator % denominator + denominator) % denominator;
|
||||
}
|
||||
|
||||
@StableAPI(since = "0.10.0")
|
||||
@StableAPI.Expose
|
||||
public static double positiveModulo(double numerator, double denominator) {
|
||||
return (numerator % denominator + denominator) % denominator;
|
||||
}
|
||||
@@ -263,7 +264,7 @@ public class MathUtil {
|
||||
/**
|
||||
* the angle is reduced to an angle between -180 and +180 by mod, and a 360 check
|
||||
*/
|
||||
@StableAPI(since = "0.10.0")
|
||||
@StableAPI.Expose
|
||||
public static float wrapDegrees(float value) {
|
||||
value = value % 360.0F;
|
||||
|
||||
@@ -281,7 +282,7 @@ public class MathUtil {
|
||||
/**
|
||||
* the angle is reduced to an angle between -180 and +180 by mod, and a 360 check
|
||||
*/
|
||||
@StableAPI(since = "0.10.0")
|
||||
@StableAPI.Expose
|
||||
public static double wrapDegrees(double value) {
|
||||
value = value % 360.0D;
|
||||
|
||||
@@ -299,7 +300,7 @@ public class MathUtil {
|
||||
/**
|
||||
* Adjust the angle so that his value is in range [-180;180[
|
||||
*/
|
||||
@StableAPI(since = "0.10.0")
|
||||
@StableAPI.Expose
|
||||
public static int wrapDegrees(int angle) {
|
||||
angle = angle % 360;
|
||||
|
||||
@@ -317,7 +318,7 @@ public class MathUtil {
|
||||
/**
|
||||
* parses the string as integer or returns the second parameter if it fails
|
||||
*/
|
||||
@StableAPI(since = "0.10.0")
|
||||
@StableAPI.Expose
|
||||
public static int getInt(String value, int defaultValue) {
|
||||
try {
|
||||
return Integer.parseInt(value);
|
||||
@@ -329,7 +330,7 @@ public class MathUtil {
|
||||
/**
|
||||
* parses the string as integer or returns the second parameter if it fails. this value is capped to par2
|
||||
*/
|
||||
@StableAPI(since = "0.10.0")
|
||||
@StableAPI.Expose
|
||||
public static int getInt(String value, int defaultValue, int max) {
|
||||
return Math.max(max, getInt(value, defaultValue));
|
||||
}
|
||||
@@ -337,7 +338,7 @@ public class MathUtil {
|
||||
/**
|
||||
* parses the string as double or returns the second parameter if it fails.
|
||||
*/
|
||||
@StableAPI(since = "0.10.0")
|
||||
@StableAPI.Expose
|
||||
public static double getDouble(String value, double defaultValue) {
|
||||
try {
|
||||
return Double.parseDouble(value);
|
||||
@@ -346,7 +347,7 @@ public class MathUtil {
|
||||
}
|
||||
}
|
||||
|
||||
@StableAPI(since = "0.10.0")
|
||||
@StableAPI.Expose
|
||||
public static double getDouble(String value, double defaultValue, double max) {
|
||||
return Math.max(max, getDouble(value, defaultValue));
|
||||
}
|
||||
@@ -354,7 +355,7 @@ public class MathUtil {
|
||||
/**
|
||||
* Returns the input value rounded up to the next highest power of two.
|
||||
*/
|
||||
@StableAPI(since = "0.10.0")
|
||||
@StableAPI.Expose
|
||||
public static int smallestEncompassingPowerOfTwo(int value) {
|
||||
int i = value - 1;
|
||||
i = i | i >> 1;
|
||||
@@ -368,7 +369,7 @@ public class MathUtil {
|
||||
/**
|
||||
* Is the given value a power of two? (1, 2, 4, 8, 16, ...)
|
||||
*/
|
||||
@StableAPI(since = "0.10.0")
|
||||
@StableAPI.Expose
|
||||
private static boolean isPowerOfTwo(int value) {
|
||||
return value != 0 && (value & value - 1) == 0;
|
||||
}
|
||||
@@ -378,7 +379,7 @@ public class MathUtil {
|
||||
* value. Optimized for cases where the input value is a power-of-two. If the input value is not a power-of-two,
|
||||
* then subtract 1 from the return value.
|
||||
*/
|
||||
@StableAPI(since = "0.10.0")
|
||||
@StableAPI.Expose
|
||||
public static int log2DeBruijn(int value) {
|
||||
value = isPowerOfTwo(value) ? value : smallestEncompassingPowerOfTwo(value);
|
||||
return MULTIPLY_DE_BRUIJN_BIT_POSITION[(int) ((long) value * 125613361L >> 27) & 31];
|
||||
@@ -388,7 +389,7 @@ public class MathUtil {
|
||||
* Efficiently calculates the floor of the base-2 log of an integer value. This is effectively the index of the
|
||||
* highest bit that is set. For example, if the number in binary is 0...100101, this will return 5.
|
||||
*/
|
||||
@StableAPI(since = "0.10.0")
|
||||
@StableAPI.Expose
|
||||
public static int log2(int value) {
|
||||
return log2DeBruijn(value) - (isPowerOfTwo(value) ? 0 : 1);
|
||||
}
|
||||
@@ -399,7 +400,7 @@ public class MathUtil {
|
||||
* For instance, {@code roundUp(1, 4)} returns 4; {@code roundUp(0, 4)} returns 0; and {@code roundUp(4, 4)} returns
|
||||
* 4.
|
||||
*/
|
||||
@StableAPI(since = "0.10.0")
|
||||
@StableAPI.Expose
|
||||
public static int roundUp(int number, int interval) {
|
||||
if (interval == 0) {
|
||||
return 0;
|
||||
@@ -415,7 +416,7 @@ public class MathUtil {
|
||||
}
|
||||
}
|
||||
|
||||
@StableAPI(since = "0.10.0")
|
||||
@StableAPI.Expose
|
||||
public static long getCoordinateRandom(int x, int y, int z) {
|
||||
long i = (x * 3129871L) ^ (long) z * 116129781L ^ (long) y;
|
||||
i = i * i * 42317861L + i * 11L;
|
||||
@@ -425,7 +426,7 @@ public class MathUtil {
|
||||
/**
|
||||
* Makes an integer color from the given red, green, and blue float values
|
||||
*/
|
||||
@StableAPI(since = "0.10.0")
|
||||
@StableAPI.Expose
|
||||
public static int rgb(float rIn, float gIn, float bIn) {
|
||||
return rgb(floor(rIn * 255.0F), floor(gIn * 255.0F), floor(bIn * 255.0F));
|
||||
}
|
||||
@@ -433,14 +434,14 @@ public class MathUtil {
|
||||
/**
|
||||
* Makes a single int color with the given red, green, and blue values.
|
||||
*/
|
||||
@StableAPI(since = "0.10.0")
|
||||
@StableAPI.Expose
|
||||
public static int rgb(int rIn, int gIn, int bIn) {
|
||||
int lvt_3_1_ = (rIn << 8) + gIn;
|
||||
lvt_3_1_ = (lvt_3_1_ << 8) + bIn;
|
||||
return lvt_3_1_;
|
||||
}
|
||||
|
||||
@StableAPI(since = "0.10.0")
|
||||
@StableAPI.Expose
|
||||
public static int multiplyColor(int colorA, int colorB) {
|
||||
int rA = (colorA & 0xFF0000) >> 16;
|
||||
int rB = (colorB & 0xFF0000) >> 16;
|
||||
@@ -457,17 +458,17 @@ public class MathUtil {
|
||||
/**
|
||||
* Gets the decimal portion of the given double. For instance, {@code frac(5.5)} returns {@code .5}.
|
||||
*/
|
||||
@StableAPI(since = "0.10.0")
|
||||
@StableAPI.Expose
|
||||
public static double frac(double number) {
|
||||
return number - Math.floor(number);
|
||||
}
|
||||
|
||||
@StableAPI(since = "0.10.0")
|
||||
@StableAPI.Expose
|
||||
public static long getPositionRandom(Vec3i pos) {
|
||||
return getCoordinateRandom(pos.getX(), pos.getY(), pos.getZ());
|
||||
}
|
||||
|
||||
@StableAPI(since = "0.10.0")
|
||||
@StableAPI.Expose
|
||||
public static UUID getRandomUUID(Random rand) {
|
||||
long i = rand.nextLong() & -61441L | 16384L;
|
||||
long j = rand.nextLong() & 4611686018427387903L | Long.MIN_VALUE;
|
||||
@@ -477,17 +478,17 @@ public class MathUtil {
|
||||
/**
|
||||
* Generates a random UUID using the shared random
|
||||
*/
|
||||
@StableAPI(since = "0.10.0")
|
||||
@StableAPI.Expose
|
||||
public static UUID getRandomUUID() {
|
||||
return getRandomUUID(RANDOM);
|
||||
}
|
||||
|
||||
@StableAPI(since = "0.10.0")
|
||||
@StableAPI.Expose
|
||||
public static double pct(double a, double b, double c) {
|
||||
return (a - b) / (c - b);
|
||||
}
|
||||
|
||||
@StableAPI(since = "0.10.0")
|
||||
@StableAPI.Expose
|
||||
public static double atan2(double y, double x) {
|
||||
double d0 = x * x + y * y;
|
||||
|
||||
@@ -547,7 +548,7 @@ public class MathUtil {
|
||||
* Computes 1/sqrt(n) using <a href="https://en.wikipedia.org/wiki/Fast_inverse_square_root">the fast inverse square
|
||||
* root</a> with a constant of 0x5FE6EB50C7B537AA.
|
||||
*/
|
||||
@StableAPI(since = "0.10.0")
|
||||
@StableAPI.Expose
|
||||
public static double fastInvSqrt(double x) {
|
||||
double d0 = 0.5D * x;
|
||||
long i = Double.doubleToRawLongBits(x);
|
||||
@@ -557,7 +558,7 @@ public class MathUtil {
|
||||
return x;
|
||||
}
|
||||
|
||||
@StableAPI(since = "0.10.0")
|
||||
@StableAPI.Expose
|
||||
public static int hsvToRGB(float hue, float saturation, float value) {
|
||||
int i = (int) (hue * 6.0F) % 6;
|
||||
float f = hue * 6.0F - (float) i;
|
||||
@@ -611,7 +612,7 @@ public class MathUtil {
|
||||
return j << 16 | k << 8 | l;
|
||||
}
|
||||
|
||||
@StableAPI(since = "0.10.0")
|
||||
@StableAPI.Expose
|
||||
public static int hash(int x) {
|
||||
x = x ^ x >>> 16;
|
||||
x = x * -2048144789;
|
||||
|
||||
@@ -1,50 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2022 FalsePattern
|
||||
* All Rights Reserved
|
||||
*
|
||||
* The above copyright notice, this permission notice and the word "SNEED"
|
||||
* shall be included in all copies or substantial portions of the Software.
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser 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 Lesser General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package com.falsepattern.lib.util;
|
||||
|
||||
import lombok.SneakyThrows;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
import java.lang.reflect.Method;
|
||||
import java.lang.reflect.Modifier;
|
||||
|
||||
public class ReflectionUtil {
|
||||
private static final Field f_modifiers;
|
||||
|
||||
static {
|
||||
try {
|
||||
f_modifiers = Field.class.getDeclaredField("modifiers");
|
||||
} catch (NoSuchFieldException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
f_modifiers.setAccessible(true);
|
||||
}
|
||||
|
||||
@SneakyThrows
|
||||
public static void jailBreak(Field field) {
|
||||
field.setAccessible(true);
|
||||
f_modifiers.set(field, field.getModifiers() & ~Modifier.FINAL);
|
||||
}
|
||||
|
||||
public static void jailBreak(Method method) {
|
||||
method.setAccessible(true);
|
||||
}
|
||||
}
|
||||
@@ -41,6 +41,7 @@ import static net.minecraft.client.Minecraft.getMinecraft;
|
||||
public final class RenderUtil {
|
||||
private final static Timer MINECRAFT_TIMER = getMinecraftTimer();
|
||||
|
||||
@StableAPI.Expose
|
||||
@SneakyThrows
|
||||
private static Timer getMinecraftTimer() {
|
||||
val timerField = ReflectionHelper.findField(Minecraft.class, "timer", "field_71428_T");
|
||||
@@ -98,6 +99,7 @@ public final class RenderUtil {
|
||||
};
|
||||
}
|
||||
|
||||
@StableAPI.Expose
|
||||
public static float partialTick() {
|
||||
return MINECRAFT_TIMER.renderPartialTicks;
|
||||
}
|
||||
|
||||
@@ -48,6 +48,7 @@ public class ResourceUtil {
|
||||
*
|
||||
* @throws IOException From {@link #readBytes(InputStream)}
|
||||
*/
|
||||
@StableAPI.Expose
|
||||
public static String getResourceStringFromJar(String resourcePath, Class<?> referenceClass) throws IOException {
|
||||
return getResourceStringFromJar(resourcePath, referenceClass, StandardCharsets.UTF_8);
|
||||
}
|
||||
@@ -64,6 +65,7 @@ public class ResourceUtil {
|
||||
*
|
||||
* @throws IOException From {@link #readBytes(InputStream)}
|
||||
*/
|
||||
@StableAPI.Expose
|
||||
public static String getResourceStringFromJar(String resourcePath, Class<?> referenceClass, Charset charset)
|
||||
throws IOException {
|
||||
return new String(getResourceBytesFromJar(resourcePath, referenceClass), charset);
|
||||
@@ -79,6 +81,7 @@ public class ResourceUtil {
|
||||
*
|
||||
* @throws IOException From {@link #readBytes(InputStream)}
|
||||
*/
|
||||
@StableAPI.Expose
|
||||
public static byte[] getResourceBytesFromJar(String resourcePath, Class<?> referenceClass) throws IOException {
|
||||
return readBytesSafe(getResourceFromJar(resourcePath, referenceClass), resourcePath);
|
||||
}
|
||||
@@ -100,6 +103,7 @@ public class ResourceUtil {
|
||||
*
|
||||
* @return The resource, or null if it was not found.
|
||||
*/
|
||||
@StableAPI.Expose
|
||||
public static InputStream getResourceFromJar(String resourcePath, Class<?> referenceClass) {
|
||||
URL classFile = referenceClass.getResource('/' + referenceClass.getName().replace('.', '/') + ".class");
|
||||
lookup:
|
||||
@@ -136,6 +140,7 @@ public class ResourceUtil {
|
||||
*
|
||||
* @throws IOException From {@link InputStream#read(byte[])}
|
||||
*/
|
||||
@StableAPI.Expose
|
||||
public static byte[] readBytes(InputStream stream) throws IOException {
|
||||
val out = new ByteArrayOutputStream();
|
||||
val buf = new byte[4096];
|
||||
@@ -155,6 +160,7 @@ public class ResourceUtil {
|
||||
*
|
||||
* @throws IOException From {@link #readBytes(InputStream)}
|
||||
*/
|
||||
@StableAPI.Expose
|
||||
public static String getResourceString(String resourcePath) throws IOException {
|
||||
return getResourceString(resourcePath, StandardCharsets.UTF_8);
|
||||
}
|
||||
@@ -169,6 +175,7 @@ public class ResourceUtil {
|
||||
*
|
||||
* @throws IOException From {@link #readBytes(InputStream)}
|
||||
*/
|
||||
@StableAPI.Expose
|
||||
public static String getResourceString(String resourcePath, Charset charset) throws IOException {
|
||||
return new String(getResourceBytes(resourcePath), charset);
|
||||
}
|
||||
@@ -182,6 +189,7 @@ public class ResourceUtil {
|
||||
*
|
||||
* @throws IOException From {@link #readBytes(InputStream)}
|
||||
*/
|
||||
@StableAPI.Expose
|
||||
public static byte[] getResourceBytes(String resourcePath) throws IOException {
|
||||
return readBytesSafe(ResourceUtil.class.getResourceAsStream(resourcePath), resourcePath);
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user