package com.codechecker.cache; import java.io.IOException; import java.io.InputStream; import java.io.UncheckedIOException; import java.nio.charset.StandardCharsets; import java.io.ByteArrayOutputStream; /** * 测试通用工具:加载 classpath 下的 fixture 文本。 */ public final class TestSupport { private TestSupport() { } public static String fixture(String path) { try (InputStream in = TestSupport.class.getClassLoader().getResourceAsStream(path)) { if (in == null) { throw new IllegalArgumentException("fixture 不存在: " + path); } ByteArrayOutputStream buffer = new ByteArrayOutputStream(); byte[] chunk = new byte[8192]; int read; while ((read = in.read(chunk)) != -1) { buffer.write(chunk, 0, read); } return new String(buffer.toByteArray(), StandardCharsets.UTF_8); } catch (IOException e) { throw new UncheckedIOException(e); } } }