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);
        }
    }
}
