BenchmarkResources.java

/*******************************************************************************
 * Copyright (c) 2025 Eclipse RDF4J contributors.
 *
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Distribution License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/org/documents/edl-v10.php.
 *
 * SPDX-License-Identifier: BSD-3-Clause
 *******************************************************************************/
// Some portions generated by Codex
package org.eclipse.rdf4j.benchmark.common;

import java.io.IOException;
import java.io.InputStream;
import java.io.UncheckedIOException;
import java.util.Objects;
import java.util.zip.GZIPInputStream;

public final class BenchmarkResources {

	private BenchmarkResources() {
	}

	public static InputStream openDecompressedStream(String resourcePath) {
		Objects.requireNonNull(resourcePath, "resourcePath");
		InputStream raw = BenchmarkResources.class.getClassLoader().getResourceAsStream(resourcePath);
		if (raw == null) {
			throw new IllegalArgumentException("Resource not found: " + resourcePath);
		}
		if (resourcePath.endsWith(".gz")) {
			try {
				return new GZIPInputStream(raw);
			} catch (IOException e) {
				try {
					raw.close();
				} catch (IOException suppressed) {
					e.addSuppressed(suppressed);
				}
				throw new UncheckedIOException("Failed to open gzip resource: " + resourcePath, e);
			}
		}
		return raw;
	}
}