mirror of
https://github.com/AngelAuraMC/Amethyst-Android.git
synced 2025-09-15 07:39:00 -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.value.*;
|
||||
import net.kdt.pojavlaunch.prefs.*;
|
||||
import java.nio.*;
|
||||
|
||||
public final class Tools
|
||||
{
|
||||
@ -699,24 +700,29 @@ public final class Tools
|
||||
return getByteArray(new FileInputStream(filePath));
|
||||
}
|
||||
|
||||
public static byte[] getByteArray(InputStream stream) throws IOException
|
||||
{
|
||||
byte[] bytes = new byte[stream.available()];
|
||||
BufferedInputStream buf = new BufferedInputStream(stream);
|
||||
buf.read(bytes, 0, bytes.length);
|
||||
public static byte[] getByteArray(InputStream stream) throws IOException {
|
||||
ByteBuffer byteBuff = ByteBuffer.allocateDirect(stream.available()).order(ByteOrder.nativeOrder());
|
||||
byteBuff.position(0);
|
||||
|
||||
BufferedInputStream buf = new BufferedInputStream(stream);
|
||||
// should be 1kb?
|
||||
byte[] buffer = new byte[512];
|
||||
int read;
|
||||
while((read = buf.read(buffer)) != -1){
|
||||
byteBuff.put(buffer, 0, read);
|
||||
}
|
||||
buf.close();
|
||||
|
||||
return bytes;
|
||||
return byteBuff.array();
|
||||
}
|
||||
|
||||
public static String read(InputStream is) throws Exception
|
||||
{
|
||||
return new String(getByteArray(is));
|
||||
public static String read(InputStream is) throws Exception {
|
||||
byte[] byteArr = getByteArray(is);
|
||||
return new String(byteArr, 0, byteArr.length);
|
||||
}
|
||||
|
||||
public static String read(String path) throws Exception
|
||||
{
|
||||
return new String(getByteArray(path));
|
||||
public static String read(String path) throws Exception {
|
||||
return read(new FileInputStream(path));
|
||||
}
|
||||
|
||||
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());
|
||||
#endif
|
||||
|
||||
isInputReady = true;
|
||||
|
||||
return success == EGL_TRUE ? JNI_TRUE : JNI_FALSE;
|
||||
}
|
||||
|
||||
|
@ -6,7 +6,7 @@ jclass inputBridgeClass;
|
||||
jmethodID inputBridgeMethod;
|
||||
|
||||
JNIEXPORT void JNICALL Java_net_kdt_pojavlaunch_LWJGLInputSender_sendDataToJRE(JNIEnv* env, jclass clazz, jint type, jstring data) {
|
||||
if (isInputReady) {
|
||||
if (runtimeJavaVMPtr != NULL) {
|
||||
if (!isAndroidThreadAttached) {
|
||||
// Allow invoke JRE reflection from Android side
|
||||
(*runtimeJavaVMPtr)->AttachCurrentThread(runtimeJavaVMPtr, &runtimeJNIEnvPtr, NULL);
|
||||
|
@ -9,7 +9,6 @@ JNIEnv *runtimeJNIEnvPtr;
|
||||
JavaVM *dalvikJavaVMPtr;
|
||||
JNIEnv *dalvikJNIEnvPtr;
|
||||
|
||||
bool isInputReady;
|
||||
bool isAndroidThreadAttached;
|
||||
|
||||
char** convert_to_char_array(JNIEnv *env, jobjectArray jstringArray);
|
||||
|
Loading…
x
Reference in New Issue
Block a user