mirror of
git://f0xx.org/android_cast
synced 2026-07-29 06:39:09 +03:00
snap
This commit is contained in:
@@ -13,6 +13,8 @@ package com.foxx.androidcast.crash;
|
||||
**********************************************************************/
|
||||
import org.json.JSONObject;
|
||||
|
||||
import com.foxx.androidcast.util.IoUtils;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FileOutputStream;
|
||||
@@ -82,7 +84,7 @@ public final class CrashReportStore {
|
||||
|
||||
public static JSONObject readJson(File file) {
|
||||
try (FileInputStream fis = new FileInputStream(file)) {
|
||||
return new JSONObject(new String(fis.readAllBytes(), StandardCharsets.UTF_8));
|
||||
return new JSONObject(new String(IoUtils.readAllBytes(fis), StandardCharsets.UTF_8));
|
||||
} catch (Exception e) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -20,6 +20,8 @@ import android.os.Build;
|
||||
import android.os.IBinder;
|
||||
import android.util.Log;
|
||||
|
||||
import com.foxx.androidcast.util.IoUtils;
|
||||
|
||||
import org.json.JSONObject;
|
||||
|
||||
import java.io.File;
|
||||
@@ -117,7 +119,7 @@ public final class CrashWatcherService extends Service {
|
||||
try {
|
||||
byte[] buf;
|
||||
try (FileInputStream fis = new FileInputStream(stub)) {
|
||||
buf = fis.readAllBytes();
|
||||
buf = IoUtils.readAllBytes(fis);
|
||||
}
|
||||
String text = new String(buf, StandardCharsets.UTF_8);
|
||||
String signal = "UNKNOWN";
|
||||
|
||||
@@ -14,6 +14,8 @@ package com.foxx.androidcast.ota;
|
||||
import android.content.Context;
|
||||
import android.util.Log;
|
||||
|
||||
import com.foxx.androidcast.util.IoUtils;
|
||||
|
||||
import org.json.JSONObject;
|
||||
|
||||
import java.io.BufferedInputStream;
|
||||
@@ -81,7 +83,7 @@ public final class OtaBundleInstaller {
|
||||
File signFile = new File(extractDir, ENTRY_SIGN);
|
||||
if (signFile.isFile()) {
|
||||
try (FileInputStream fis = new FileInputStream(signFile)) {
|
||||
byte[] buf = fis.readAllBytes();
|
||||
byte[] buf = IoUtils.readAllBytes(fis);
|
||||
OtaSignBundle sign = OtaSignBundle.fromJson(
|
||||
new JSONObject(new String(buf, StandardCharsets.UTF_8)));
|
||||
expectedSha = sign.sha256Hex;
|
||||
|
||||
@@ -13,8 +13,9 @@ package com.foxx.androidcast.ota;
|
||||
import android.content.Context;
|
||||
|
||||
import com.foxx.androidcast.AppPreferences;
|
||||
import com.foxx.androidcast.crash.CrashSettings;
|
||||
import com.foxx.androidcast.BuildConfig;
|
||||
import com.foxx.androidcast.crash.CrashSettings;
|
||||
import com.foxx.androidcast.util.IoUtils;
|
||||
|
||||
import org.json.JSONArray;
|
||||
import org.json.JSONObject;
|
||||
@@ -90,7 +91,7 @@ final class OtaSettingsStore {
|
||||
private static JSONObject readSettingsJson(Context context) {
|
||||
File f = new File(context.getFilesDir(), SETTINGS_FILE);
|
||||
try (FileInputStream fis = new FileInputStream(f)) {
|
||||
byte[] data = fis.readAllBytes();
|
||||
byte[] data = IoUtils.readAllBytes(fis);
|
||||
String text = new String(data, StandardCharsets.UTF_8);
|
||||
return new JSONObject(text);
|
||||
} catch (Exception ignored) {
|
||||
|
||||
@@ -15,6 +15,8 @@ import android.content.Context;
|
||||
|
||||
import org.json.JSONObject;
|
||||
|
||||
import com.foxx.androidcast.util.IoUtils;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
@@ -31,8 +33,8 @@ public final class AppSettingsJson {
|
||||
return new JSONObject();
|
||||
}
|
||||
try (FileInputStream fis = new FileInputStream(f)) {
|
||||
return new JSONObject(new String(fis.readAllBytes(), StandardCharsets.UTF_8));
|
||||
} catch (Exception ignored) {
|
||||
return new JSONObject(new String(IoUtils.readAllBytes(fis), StandardCharsets.UTF_8));
|
||||
} catch (Throwable ignored) {
|
||||
return new JSONObject();
|
||||
}
|
||||
}
|
||||
|
||||
36
app/src/main/java/com/foxx/androidcast/util/IoUtils.java
Normal file
36
app/src/main/java/com/foxx/androidcast/util/IoUtils.java
Normal file
@@ -0,0 +1,36 @@
|
||||
package com.foxx.androidcast.util;
|
||||
|
||||
/*********************************************************************
|
||||
* IoUtils.java
|
||||
* Created at: Wed 20 May 2026 12:00:00 +0200
|
||||
* Contributors:
|
||||
* - Cursor Agent (project assistant)
|
||||
**********************************************************************/
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
|
||||
/** Stream/file reads compatible with minSdk 29 (no {@code InputStream.readAllBytes()}). */
|
||||
public final class IoUtils {
|
||||
private static final int BUF_SIZE = 8192;
|
||||
|
||||
private IoUtils() {}
|
||||
|
||||
public static byte[] readAllBytes(InputStream in) throws IOException {
|
||||
ByteArrayOutputStream out = new ByteArrayOutputStream();
|
||||
byte[] buf = new byte[BUF_SIZE];
|
||||
int n;
|
||||
while ((n = in.read(buf)) != -1) {
|
||||
out.write(buf, 0, n);
|
||||
}
|
||||
return out.toByteArray();
|
||||
}
|
||||
|
||||
public static byte[] readAllBytes(File file) throws IOException {
|
||||
try (FileInputStream fis = new FileInputStream(file)) {
|
||||
return readAllBytes(fis);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user