Home / Class/ MessageFormatter Class — netty Architecture

MessageFormatter Class — netty Architecture

Architecture documentation for the MessageFormatter class in MessageFormatter.java from the netty codebase.

Entity Profile

Dependency Diagram

graph TD
  15dfd92a_397f_c44b_376f_363fa0eb3c7c["MessageFormatter"]
  fbd2dc6e_ae50_5a94_63cb_745e7ce71f8f["MessageFormatter.java"]
  15dfd92a_397f_c44b_376f_363fa0eb3c7c -->|defined in| fbd2dc6e_ae50_5a94_63cb_745e7ce71f8f
  aa43d43a_7006_3a89_f686_0e8102b22895["FormattingTuple()"]
  15dfd92a_397f_c44b_376f_363fa0eb3c7c -->|method| aa43d43a_7006_3a89_f686_0e8102b22895
  18685557_824c_32da_a77f_c1ade1ad4932["deeplyAppendParameter()"]
  15dfd92a_397f_c44b_376f_363fa0eb3c7c -->|method| 18685557_824c_32da_a77f_c1ade1ad4932
  4f13c2e2_74b8_7113_01aa_e5c8cd81afd4["safeObjectAppend()"]
  15dfd92a_397f_c44b_376f_363fa0eb3c7c -->|method| 4f13c2e2_74b8_7113_01aa_e5c8cd81afd4
  82153434_8f82_dab6_af73_f5294f9f0205["objectArrayAppend()"]
  15dfd92a_397f_c44b_376f_363fa0eb3c7c -->|method| 82153434_8f82_dab6_af73_f5294f9f0205
  a8e9e32c_9ea1_d22a_5a8d_714a8afc44cd["booleanArrayAppend()"]
  15dfd92a_397f_c44b_376f_363fa0eb3c7c -->|method| a8e9e32c_9ea1_d22a_5a8d_714a8afc44cd
  98c0963e_a75d_0b60_b51c_e90065ff3863["byteArrayAppend()"]
  15dfd92a_397f_c44b_376f_363fa0eb3c7c -->|method| 98c0963e_a75d_0b60_b51c_e90065ff3863
  c9150c0c_918e_af04_fcf6_a3e9b7bda657["charArrayAppend()"]
  15dfd92a_397f_c44b_376f_363fa0eb3c7c -->|method| c9150c0c_918e_af04_fcf6_a3e9b7bda657
  a48456c1_449c_5482_6b5f_8cf245ac06eb["shortArrayAppend()"]
  15dfd92a_397f_c44b_376f_363fa0eb3c7c -->|method| a48456c1_449c_5482_6b5f_8cf245ac06eb
  91ac73b1_f921_0deb_0515_b549d5b0b607["intArrayAppend()"]
  15dfd92a_397f_c44b_376f_363fa0eb3c7c -->|method| 91ac73b1_f921_0deb_0515_b549d5b0b607
  eaa3dd45_0016_4dc6_167e_0ecf0f226513["longArrayAppend()"]
  15dfd92a_397f_c44b_376f_363fa0eb3c7c -->|method| eaa3dd45_0016_4dc6_167e_0ecf0f226513
  634e1c3a_6e26_553a_741e_19febf0d73be["floatArrayAppend()"]
  15dfd92a_397f_c44b_376f_363fa0eb3c7c -->|method| 634e1c3a_6e26_553a_741e_19febf0d73be
  e5e365a1_a76c_6671_0a9f_ed3f5567c300["doubleArrayAppend()"]
  15dfd92a_397f_c44b_376f_363fa0eb3c7c -->|method| e5e365a1_a76c_6671_0a9f_ed3f5567c300
  a25649ef_e605_b354_79e2_f28ad8ad93fb["MessageFormatter()"]
  15dfd92a_397f_c44b_376f_363fa0eb3c7c -->|method| a25649ef_e605_b354_79e2_f28ad8ad93fb

Relationship Graph

Source Code

common/src/main/java/io/netty/util/internal/logging/MessageFormatter.java lines 111–397

public final class MessageFormatter {
    private static final String DELIM_STR = "{}";
    private static final char ESCAPE_CHAR = '\\';

    /**
     * Performs single argument substitution for the 'messagePattern' passed as
     * parameter.
     * <p/>
     * For example,
     * <p/>
     * <pre>
     * MessageFormatter.format(&quot;Hi {}.&quot;, &quot;there&quot;);
     * </pre>
     * <p/>
     * will return the string "Hi there.".
     * <p/>
     *
     * @param messagePattern The message pattern which will be parsed and formatted
     * @param arg            The argument to be substituted in place of the formatting anchor
     * @return The formatted message
     */
    public static FormattingTuple format(String messagePattern, Object arg) {
        return arrayFormat(messagePattern, new Object[]{arg});
    }

    /**
     * Performs a two argument substitution for the 'messagePattern' passed as
     * parameter.
     * <p/>
     * For example,
     * <p/>
     * <pre>
     * MessageFormatter.format(&quot;Hi {}. My name is {}.&quot;, &quot;Alice&quot;, &quot;Bob&quot;);
     * </pre>
     * <p/>
     * will return the string "Hi Alice. My name is Bob.".
     *
     * @param messagePattern The message pattern which will be parsed and formatted
     * @param argA           The argument to be substituted in place of the first formatting
     *                       anchor
     * @param argB           The argument to be substituted in place of the second formatting
     *                       anchor
     * @return The formatted message
     */
    public static FormattingTuple format(final String messagePattern,
                                  Object argA, Object argB) {
        return arrayFormat(messagePattern, new Object[]{argA, argB});
    }

    /**
     * Same principle as the {@link #format(String, Object)} and
     * {@link #format(String, Object, Object)} methods except that any number of
     * arguments can be passed in an array.
     *
     * @param messagePattern The message pattern which will be parsed and formatted
     * @param argArray       An array of arguments to be substituted in place of formatting
     *                       anchors
     * @return The formatted message
     */
    public static FormattingTuple arrayFormat(final String messagePattern,
                                       final Object[] argArray) {
        if (argArray == null || argArray.length == 0) {
            return new FormattingTuple(messagePattern, null);
        }

        int lastArrIdx = argArray.length - 1;
        Object lastEntry = argArray[lastArrIdx];
        Throwable throwable = lastEntry instanceof Throwable? (Throwable) lastEntry : null;

        if (messagePattern == null) {
            return new FormattingTuple(null, throwable);
        }

        int j = messagePattern.indexOf(DELIM_STR);
        if (j == -1) {
            // this is a simple string
            return new FormattingTuple(messagePattern, throwable);
        }

        StringBuilder sbuf = new StringBuilder(messagePattern.length() + 50);
        int i = 0;

Frequently Asked Questions

What is the MessageFormatter class?
MessageFormatter is a class in the netty codebase, defined in common/src/main/java/io/netty/util/internal/logging/MessageFormatter.java.
Where is MessageFormatter defined?
MessageFormatter is defined in common/src/main/java/io/netty/util/internal/logging/MessageFormatter.java at line 111.

Analyze Your Own Codebase

Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.

Try Supermodel Free