MOD:更换为Vertx框架 提高效率

This commit is contained in:
leosam1024
2023-06-15 15:56:41 +08:00
parent 08fe94f020
commit d78c34d18a
21 changed files with 913 additions and 325 deletions
@@ -1,12 +1,12 @@
package com.leosam.tvbox.mv.utils;
import org.springframework.core.io.ClassPathResource;
import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.nio.charset.StandardCharsets;
import java.util.Properties;
/**
* @author admin
@@ -14,19 +14,33 @@ import java.util.Properties;
*/
public class ClassPathReaderUtils {
public static int getSize(String path) {
try {
ClassPathResource resource = new ClassPathResource(path);
InputStream inputStream = resource.getInputStream();
int available = inputStream.available();
return available;
} catch (IOException ex) {
throw new RuntimeException(ex);
}
}
public static InputStreamReader getInputStreamReader(String path) {
try {
ClassPathResource resource = new ClassPathResource(path);
InputStreamReader inputStreamReader = new InputStreamReader(resource.getInputStream(),StandardCharsets.UTF_8);
InputStreamReader inputStreamReader = new InputStreamReader(resource.getInputStream(), StandardCharsets.UTF_8);
return inputStreamReader;
} catch (IOException ex) {
throw new RuntimeException(ex);
}
}
public static BufferedReader getBufferedReader(String path) {
try {
ClassPathResource resource = new ClassPathResource(path);
InputStreamReader inputStreamReader = new InputStreamReader(resource.getInputStream(),StandardCharsets.UTF_8);
BufferedReader reader = new BufferedReader(inputStreamReader);
return reader;
@@ -35,17 +49,6 @@ public class ClassPathReaderUtils {
}
}
public static Properties getProperties(String path) {
Properties properties = new Properties();
try {
ClassPathResource resource = new ClassPathResource(path);
InputStreamReader inputStreamReader = new InputStreamReader(resource.getInputStream());
properties.load(new BufferedReader(inputStreamReader));
} catch (IOException ex) {
throw new RuntimeException(ex);
}
return properties;
}
public static String getContent(String path) {
StringBuilder content = new StringBuilder();
@@ -70,5 +73,52 @@ public class ClassPathReaderUtils {
System.out.println(json);
}
public static class ClassPathResource {
private final String path;
private final ClassLoader classLoader;
public ClassPathResource(String path) {
this.path = path;
this.classLoader = getDefaultClassLoader();
}
public InputStream getInputStream() throws IOException {
InputStream is;
if (this.classLoader != null) {
is = this.classLoader.getResourceAsStream(this.path);
} else {
is = ClassLoader.getSystemResourceAsStream(this.path);
}
if (is == null) {
throw new FileNotFoundException(path + " cannot be opened because it does not exist");
}
return is;
}
public static ClassLoader getDefaultClassLoader() {
ClassLoader cl = null;
try {
cl = Thread.currentThread().getContextClassLoader();
} catch (Throwable ex) {
// Cannot access thread context ClassLoader - falling back...
}
if (cl == null) {
// No thread context class loader -> use class loader of this class.
cl = ClassPathResource.class.getClassLoader();
if (cl == null) {
// getClassLoader() returning null indicates the bootstrap ClassLoader
try {
cl = ClassLoader.getSystemClassLoader();
} catch (Throwable ex) {
// Cannot access system ClassLoader - oh well, maybe the caller can live with null...
}
}
}
return cl;
}
}
}