001package io.prometheus.metrics.expositionformats; 002 003import io.prometheus.metrics.model.snapshots.MetricSnapshots; 004import java.io.ByteArrayOutputStream; 005import java.io.IOException; 006import java.io.OutputStream; 007 008public interface ExpositionFormatWriter { 009 boolean accepts(String acceptHeader); 010 011 /** Text formats use UTF-8 encoding. */ 012 void write(OutputStream out, MetricSnapshots metricSnapshots) throws IOException; 013 014 default String toDebugString(MetricSnapshots metricSnapshots) { 015 ByteArrayOutputStream out = new ByteArrayOutputStream(); 016 try { 017 write(out, metricSnapshots); 018 return out.toString("UTF-8"); 019 } catch (IOException e) { 020 throw new RuntimeException(e); 021 } 022 } 023 024 String getContentType(); 025 026 /** 027 * Returns true if the writer is available. If false, the writer will throw an exception if used. 028 */ 029 default boolean isAvailable() { 030 return true; 031 } 032}