001package io.prometheus.metrics.expositionformats; 002 003import io.prometheus.metrics.annotations.StableApi; 004import io.prometheus.metrics.config.EscapingScheme; 005import io.prometheus.metrics.model.snapshots.MetricSnapshots; 006import java.io.IOException; 007import java.io.OutputStream; 008 009/** 010 * An exposition format writer paired with the escaping scheme selected from an Accept header. 011 * 012 * <p>Instances are immutable and delegate to the underlying format writer. The content type is the 013 * format's standard content type and does not include an escaping parameter. 014 */ 015@StableApi 016public final class ExpositionFormatWriterWithEscaping { 017 018 private final ExpositionFormatWriter writer; 019 private final EscapingScheme escapingScheme; 020 021 ExpositionFormatWriterWithEscaping(ExpositionFormatWriter writer, EscapingScheme escapingScheme) { 022 this.writer = writer; 023 this.escapingScheme = escapingScheme; 024 } 025 026 /** Writes the given metric snapshots using the negotiated escaping scheme. */ 027 public void write(OutputStream out, MetricSnapshots metricSnapshots) throws IOException { 028 writer.write(out, metricSnapshots, escapingScheme); 029 } 030 031 /** Converts the metric snapshots to a debug string using the negotiated escaping scheme. */ 032 public String toDebugString(MetricSnapshots metricSnapshots) { 033 return writer.toDebugString(metricSnapshots, escapingScheme); 034 } 035 036 /** Returns the standard content type for the selected exposition format. */ 037 public String getContentType() { 038 return writer.getContentType(); 039 } 040 041 /** Returns the escaping scheme selected from the Accept header. */ 042 public EscapingScheme getEscapingScheme() { 043 return escapingScheme; 044 } 045}