Package net.thauvin.erik.httpstatus
Class Utils
java.lang.Object
net.thauvin.erik.httpstatus.Utils
A collection of utility methods used throughout the project.
This class is not intended to be instantiated.
Provides helpers for XML escaping and safe writer output.
- Since:
- 1.0.0
- Author:
- Erik C. Thauvin
-
Method Summary
Modifier and TypeMethodDescriptionstatic StringConverts the characters<,>,&,', and"to their corresponding XML entity codes.static voidWrites a string value to the given writer, optionally escaping XML characters.
-
Method Details
-
escapeXml
Converts the characters<,>,&,', and"to their corresponding XML entity codes.Returns the original value when empty. Only the predefined XML entities are escaped; all other characters are preserved as-is.
- Parameters:
value- the string to escape- Returns:
- the escaped string
- Throws:
NullPointerException- if the value isnull
-
outWrite
public static void outWrite(Writer out, @Nullable String value, @Nullable String defaultValue, boolean escapeXml) throws IOException Writes a string value to the given writer, optionally escaping XML characters. When the value is null, the provided default value is used instead. If both are null, nothing is written.The writer must not be null. XML escaping is performed using
escapeXml(String).- Parameters:
out- the writer to write tovalue- the string value to write, may benulldefaultValue- the default value to use whenvalueisnull, may benullescapeXml-trueto escape XML characters,falseotherwise- Throws:
IOException- If an I/O error occurs while writingNullPointerException- If the writer isnull
-