Java源码示例:com.google.common.net.PercentEscaper

示例1
/**
 * Creates a new {@code ODataFesParser}.
 */
public ODataFesParser() {
    this.urlEscaper = new PercentEscaper("-_.*", false);
    this.odata = new ODataImpl();
    this.csdlProvider = new ObservationCsdlEdmProvider();
    this.edm = new EdmProviderImpl(this.csdlProvider);
    // >=4.2.0
    this.parser = new Parser(this.edm, this.odata);
    // >=4.0.0 <4.2.0
    // this.parser = new Parser();

}
 
示例2
@SuppressWarnings("UnstableApiUsage")
private synchronized MeterRegistry graphiteMeterRegistry(String serviceAddress) {

    if (this.graphiteMeterRegistry == null) {

        HostAndPort address = HostAndPort.fromString(serviceAddress);

        String host = address.getHost();
        int port = address.getPortOrDefault(DEFAULT_GRAPHITE_SERVER_PORT);
        boolean enabled = !Boolean.getBoolean("cosmos.monitoring.graphite.disabled");
        Duration step = Duration.ofSeconds(Integer.getInteger("cosmos.monitoring.graphite.step", this.printingInterval));

        final GraphiteConfig config = new GraphiteConfig() {

            private String[] tagNames = { "source" };

            @Override
            @Nullable
            public String get(@Nullable String key) {
                return null;
            }

            @Override
            public boolean enabled() {
                return enabled;
            }

            @Override
            @Nullable
            public String host() {
                return host;
            }

            @Override
            @Nullable
            public int port() {
                return port;
            }

            @Override
            @Nullable
            public Duration step() {
                return step;
            }

            @Override
            @Nullable
            public String[] tagsAsPrefix() {
                return this.tagNames;
            }
        };

        this.graphiteMeterRegistry = new GraphiteMeterRegistry(config, Clock.SYSTEM);
        String source;

        try {
            PercentEscaper escaper = new PercentEscaper("_-", false);
            source = escaper.escape(InetAddress.getLocalHost().getHostName());
        } catch (UnknownHostException error) {
            source = "unknown-host";
        }

        this.graphiteMeterRegistry.config()
            .namingConvention(NamingConvention.dot)
            .commonTags("source", source);
    }

    return this.graphiteMeterRegistry;
}