@Test public void loadResourcePath() throws IOException { byte[] actual = Utils.loadResource(Paths.get("dir/testResource.txt")); assertArrayEquals(expected, actual); }
private static byte[] loadResource(@NotNull InputStream stream) throws IOException { try { ByteArrayOutputStream out = new ByteArrayOutputStream(); byte[] buffer = new byte[4096]; int size; while ((size = stream.read(buffer)) != -1) { out.write(buffer, 0, size); } return out.toByteArray(); } finally { stream.close(); } }
Utils { private static byte[] loadResource(@NotNull InputStream stream) throws IOException { try { ByteArrayOutputStream out = new ByteArrayOutputStream(); byte[] buffer = new byte[4096]; int size; while ((size = stream.read(buffer)) != -1) { out.write(buffer, 0, size); } return out.toByteArray(); } finally { stream.close(); } } }
Utils { private static byte[] loadResource(@NotNull InputStream stream) throws IOException { try { ByteArrayOutputStream out = new ByteArrayOutputStream(); byte[] buffer = new byte[4096]; int size; while ((size = stream.read(buffer)) != -1) { out.write(buffer, 0, size); } return out.toByteArray(); } finally { stream.close(); } }  }
Utils { private static byte[] loadResource(@NotNull InputStream stream) throws IOException { try { ByteArrayOutputStream out = new ByteArrayOutputStream(); byte[] buffer = new byte[4096]; int size; while ((size = stream.read(buffer)) != -1) { out.write(buffer, 0, size); } return out.toByteArray(); } finally { stream.close(); } }  static T of(Supplier<T> supplier); static T firstNonNull(@Nullable T a, T b); static T firstNonNull(@Nullable T a, @Nullable T b, T c); @SafeVarargs static T firstNonNull(T... values); static String nullToEmpty(@Nullable String value); static Set<T> nullToEmpty(@Nullable Set<T> set); static List<T> nullToEmpty(@Nullable List<T> list); static Map<K, V> nullToEmpty(@Nullable Map<K, V> map); static Collection<T> nullToEmpty(@Nullable Collection<T> collection); static Iterable<T> nullToEmpty(@Nullable Iterable<T> iterable); static Iterator<T> nullToEmpty(@Nullable Iterator<T> iterator); static T nullToDefault(@Nullable T value, T defaultValue); static T nullToSupplier(@Nullable T value, Supplier<? extends T> defaultValue); @NotNull static T nullToException(@Nullable T reference, Supplier<E> exceptionSupplier); static int deepHashCode(@Nullable Object value); static boolean arraysEquals(
			byte[] array1, int pos1, int len1,
			byte[] array2, int pos2, int len2); static byte[] loadResource(Path path); static byte[] loadResource(String name); static InetSocketAddress parseInetSocketAddress(String addressAndPort); @Nullable @Contract("_, _ -> null") static V nullify(@Nullable V value, @NotNull Runnable action); @Nullable @Contract("_, _ -> null") static V nullify(@Nullable V value, @NotNull Consumer<@NotNull ? super V> action); @Nullable @Contract("_, _, _ -> null") static V nullify(@Nullable V value, @NotNull BiConsumer<@NotNull ? super V, A> action, A actionArg); }
Utils { private static byte[] loadResource(@NotNull InputStream stream) throws IOException { try { ByteArrayOutputStream out = new ByteArrayOutputStream(); byte[] buffer = new byte[4096]; int size; while ((size = stream.read(buffer)) != -1) { out.write(buffer, 0, size); } return out.toByteArray(); } finally { stream.close(); } }  static T of(Supplier<T> supplier); static T firstNonNull(@Nullable T a, T b); static T firstNonNull(@Nullable T a, @Nullable T b, T c); @SafeVarargs static T firstNonNull(T... values); static String nullToEmpty(@Nullable String value); static Set<T> nullToEmpty(@Nullable Set<T> set); static List<T> nullToEmpty(@Nullable List<T> list); static Map<K, V> nullToEmpty(@Nullable Map<K, V> map); static Collection<T> nullToEmpty(@Nullable Collection<T> collection); static Iterable<T> nullToEmpty(@Nullable Iterable<T> iterable); static Iterator<T> nullToEmpty(@Nullable Iterator<T> iterator); static T nullToDefault(@Nullable T value, T defaultValue); static T nullToSupplier(@Nullable T value, Supplier<? extends T> defaultValue); @NotNull static T nullToException(@Nullable T reference, Supplier<E> exceptionSupplier); static int deepHashCode(@Nullable Object value); static boolean arraysEquals(
			byte[] array1, int pos1, int len1,
			byte[] array2, int pos2, int len2); static byte[] loadResource(Path path); static byte[] loadResource(String name); static InetSocketAddress parseInetSocketAddress(String addressAndPort); @Nullable @Contract("_, _ -> null") static V nullify(@Nullable V value, @NotNull Runnable action); @Nullable @Contract("_, _ -> null") static V nullify(@Nullable V value, @NotNull Consumer<@NotNull ? super V> action); @Nullable @Contract("_, _, _ -> null") static V nullify(@Nullable V value, @NotNull BiConsumer<@NotNull ? super V, A> action, A actionArg);  }