mirror of
https://github.com/jwdeveloper/TikTokLiveJava.git
synced 2026-02-27 16:59:39 -05:00
Changes:
`TikTokEventListener` new method of listening events see it at TestApplication/ListenerExample.java Bugs: - Fixed bug: Websocket was sending ping after it was closed
This commit is contained in:
@@ -1,31 +0,0 @@
|
||||
package io.github.jwdeveloper.tiktok;
|
||||
|
||||
import io.github.jwdeveloper.tiktok.events.TikTokEvent;
|
||||
import org.reflections.Reflections;
|
||||
|
||||
public class GenerateEventsListRun
|
||||
{
|
||||
|
||||
|
||||
//[a](https://github.com/jwdeveloper/TikTok-Live-Java/blob/master/API/src/main/java/io/github/jwdeveloper/tiktok/events/messages/TikTokBarrageMessageEvent.java)
|
||||
//Message Events:
|
||||
//- [member](#member)
|
||||
|
||||
public static void main(String[] args)
|
||||
{
|
||||
Reflections reflections = new Reflections("io.github.jwdeveloper.tiktok.events.messages");
|
||||
var classes = reflections.getSubTypesOf(TikTokEvent.class);
|
||||
classes.add(TikTokEvent.class);
|
||||
|
||||
var builder = new StringBuilder();
|
||||
builder.append("Events:").append(System.lineSeparator());
|
||||
for(var event : classes)
|
||||
{
|
||||
var name = event.getSimpleName();
|
||||
var baseUrl ="https://github.com/jwdeveloper/TikTok-Live-Java/blob/master/API/src/main/java/io/github/jwdeveloper/tiktok/events/messages/"+name+".java";
|
||||
builder.append("- [").append(name).append("](").append(baseUrl).append(")").append(System.lineSeparator());
|
||||
}
|
||||
|
||||
System.out.println(builder.toString());
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,6 @@
|
||||
package io.github.jwdeveloper.tiktok.utils;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.nio.file.Files;
|
||||
@@ -18,7 +19,25 @@ public class FilesUtility
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
|
||||
}
|
||||
public static String getFileFromResource(Class clazz, String path)
|
||||
{
|
||||
try {
|
||||
var stream =clazz.getClassLoader().getResourceAsStream(path);
|
||||
var bytes= stream.readAllBytes();
|
||||
stream.close();
|
||||
return new String(bytes);
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
public static List<Path> getFileContent(String input) {
|
||||
Path path = Paths.get(input);
|
||||
try (Stream<Path> paths = Files.list(path)) {
|
||||
return paths.filter(Files::isRegularFile).toList();
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
public static void saveFile(String path, String content)
|
||||
@@ -34,5 +53,42 @@ public class FilesUtility
|
||||
}
|
||||
}
|
||||
|
||||
public static boolean pathExists(String path) {
|
||||
var directory = new File(path);
|
||||
return directory.exists();
|
||||
}
|
||||
|
||||
public static File ensurePath(String path) {
|
||||
var directory = new File(path);
|
||||
if (directory.exists()) {
|
||||
return directory;
|
||||
}
|
||||
directory.mkdirs();
|
||||
return directory;
|
||||
}
|
||||
|
||||
public static void ensureFile(String paths) {
|
||||
var file = new File(paths);
|
||||
if (!file.exists()) {
|
||||
try {
|
||||
file.createNewFile();
|
||||
} catch (IOException e)
|
||||
{
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public static String loadFileContent(String path) {
|
||||
ensureFile(path);
|
||||
Path pathh = Paths.get(path);
|
||||
try {
|
||||
return new String(Files.readAllBytes(pathh));
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,34 @@
|
||||
package io.github.jwdeveloper.tiktok.utils;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
public class TemplateUtility
|
||||
{
|
||||
public static String generateTemplate(String template, Map<String, Object> values) {
|
||||
for(var entry : values.entrySet())
|
||||
{
|
||||
template = doReplacement(template,entry.getKey(), entry.getValue().toString());
|
||||
}
|
||||
return template;
|
||||
}
|
||||
|
||||
public static String generateTemplate2(String template, Map<String, Object> values) {
|
||||
for(var entry : values.entrySet())
|
||||
{
|
||||
template = doReplacement2(template,entry.getKey(), entry.getValue().toString());
|
||||
}
|
||||
return template;
|
||||
}
|
||||
|
||||
private static String doReplacement(String template, String keyword, String value)
|
||||
{
|
||||
var key = "(\\{\\{)"+keyword+"(}})";
|
||||
return template.replaceAll(key, value);
|
||||
}
|
||||
|
||||
private static String doReplacement2(String template, String keyword, String value)
|
||||
{
|
||||
var key = "(\\$)("+keyword+")(\\$)";
|
||||
return template.replaceAll(key, value);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user