mirror of
https://github.com/AngelAuraMC/Amethyst-Android.git
synced 2025-09-16 08:05:34 -04:00
Improve byte array reader; Attempt fix input not working
This commit is contained in:
parent
2664976cbd
commit
e71fc849e3
@ -19,6 +19,7 @@ import net.kdt.pojavlaunch.patcher.*;
|
|||||||
import net.kdt.pojavlaunch.util.*;
|
import net.kdt.pojavlaunch.util.*;
|
||||||
import net.kdt.pojavlaunch.value.*;
|
import net.kdt.pojavlaunch.value.*;
|
||||||
import net.kdt.pojavlaunch.prefs.*;
|
import net.kdt.pojavlaunch.prefs.*;
|
||||||
|
import java.nio.*;
|
||||||
|
|
||||||
public final class Tools
|
public final class Tools
|
||||||
{
|
{
|
||||||
@ -699,24 +700,29 @@ public final class Tools
|
|||||||
return getByteArray(new FileInputStream(filePath));
|
return getByteArray(new FileInputStream(filePath));
|
||||||
}
|
}
|
||||||
|
|
||||||
public static byte[] getByteArray(InputStream stream) throws IOException
|
public static byte[] getByteArray(InputStream stream) throws IOException {
|
||||||
{
|
ByteBuffer byteBuff = ByteBuffer.allocateDirect(stream.available()).order(ByteOrder.nativeOrder());
|
||||||
byte[] bytes = new byte[stream.available()];
|
byteBuff.position(0);
|
||||||
|
|
||||||
BufferedInputStream buf = new BufferedInputStream(stream);
|
BufferedInputStream buf = new BufferedInputStream(stream);
|
||||||
buf.read(bytes, 0, bytes.length);
|
// should be 1kb?
|
||||||
|
byte[] buffer = new byte[512];
|
||||||
|
int read;
|
||||||
|
while((read = buf.read(buffer)) != -1){
|
||||||
|
byteBuff.put(buffer, 0, read);
|
||||||
|
}
|
||||||
buf.close();
|
buf.close();
|
||||||
|
|
||||||
return bytes;
|
return byteBuff.array();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String read(InputStream is) throws Exception
|
public static String read(InputStream is) throws Exception {
|
||||||
{
|
byte[] byteArr = getByteArray(is);
|
||||||
return new String(getByteArray(is));
|
return new String(byteArr, 0, byteArr.length);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String read(String path) throws Exception
|
public static String read(String path) throws Exception {
|
||||||
{
|
return read(new FileInputStream(path));
|
||||||
return new String(getByteArray(path));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void write(String path, byte[] content) throws Exception
|
public static void write(String path, byte[] content) throws Exception
|
||||||
|
@ -152,8 +152,6 @@ JNIEXPORT jboolean JNICALL Java_org_lwjgl_glfw_GLFW_nativeEglMakeCurrent(JNIEnv*
|
|||||||
printf("First frame error: %p\n", eglGetError());
|
printf("First frame error: %p\n", eglGetError());
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
isInputReady = true;
|
|
||||||
|
|
||||||
return success == EGL_TRUE ? JNI_TRUE : JNI_FALSE;
|
return success == EGL_TRUE ? JNI_TRUE : JNI_FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -6,7 +6,7 @@ jclass inputBridgeClass;
|
|||||||
jmethodID inputBridgeMethod;
|
jmethodID inputBridgeMethod;
|
||||||
|
|
||||||
JNIEXPORT void JNICALL Java_net_kdt_pojavlaunch_LWJGLInputSender_sendDataToJRE(JNIEnv* env, jclass clazz, jint type, jstring data) {
|
JNIEXPORT void JNICALL Java_net_kdt_pojavlaunch_LWJGLInputSender_sendDataToJRE(JNIEnv* env, jclass clazz, jint type, jstring data) {
|
||||||
if (isInputReady) {
|
if (runtimeJavaVMPtr != NULL) {
|
||||||
if (!isAndroidThreadAttached) {
|
if (!isAndroidThreadAttached) {
|
||||||
// Allow invoke JRE reflection from Android side
|
// Allow invoke JRE reflection from Android side
|
||||||
(*runtimeJavaVMPtr)->AttachCurrentThread(runtimeJavaVMPtr, &runtimeJNIEnvPtr, NULL);
|
(*runtimeJavaVMPtr)->AttachCurrentThread(runtimeJavaVMPtr, &runtimeJNIEnvPtr, NULL);
|
||||||
|
@ -9,7 +9,6 @@ JNIEnv *runtimeJNIEnvPtr;
|
|||||||
JavaVM *dalvikJavaVMPtr;
|
JavaVM *dalvikJavaVMPtr;
|
||||||
JNIEnv *dalvikJNIEnvPtr;
|
JNIEnv *dalvikJNIEnvPtr;
|
||||||
|
|
||||||
bool isInputReady;
|
|
||||||
bool isAndroidThreadAttached;
|
bool isAndroidThreadAttached;
|
||||||
|
|
||||||
char** convert_to_char_array(JNIEnv *env, jobjectArray jstringArray);
|
char** convert_to_char_array(JNIEnv *env, jobjectArray jstringArray);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user