mirror of
https://github.com/funkemunky/AntiVPN.git
synced 2026-05-31 17:31:55 +00:00
49 lines
1.2 KiB
Java
49 lines
1.2 KiB
Java
package dev.brighten.antivpn.utils;
|
|
|
|
import java.io.*;
|
|
import java.util.regex.Pattern;
|
|
|
|
public class MiscUtils {
|
|
|
|
private static final Pattern ipv4 = Pattern.compile("[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}");
|
|
|
|
public static void close(Closeable... closeables) {
|
|
try {
|
|
for (Closeable closeable : closeables) if (closeable != null) closeable.close();
|
|
} catch (Exception e) {
|
|
e.printStackTrace();
|
|
}
|
|
}
|
|
|
|
public static void close(AutoCloseable... closeables) {
|
|
try {
|
|
for (AutoCloseable closeable : closeables) if (closeable != null) closeable.close();
|
|
} catch (Exception e) {
|
|
e.printStackTrace();
|
|
}
|
|
}
|
|
|
|
public static void copy(InputStream in, File file) {
|
|
try {
|
|
OutputStream out = new FileOutputStream(file);
|
|
int lenght;
|
|
byte[] buf = new byte[1024];
|
|
|
|
while ((lenght = in.read(buf)) > 0)
|
|
{
|
|
out.write(buf, 0, lenght);
|
|
}
|
|
|
|
out.close();
|
|
in.close();
|
|
} catch (Exception e) {
|
|
e.printStackTrace();
|
|
}
|
|
}
|
|
|
|
public static boolean isIpv4(String ip)
|
|
{
|
|
return ipv4.matcher(ip).matches();
|
|
}
|
|
}
|