Top Description Fields Constructors Methods
org.springframework.core.codec

public abstract Class Hints

extends Object
Class Inheritance
Imports
java.util.Collections, .Map, org.apache.commons.logging.Log, org.springframework.core.io.buffer.DataBuffer, .DataBufferUtils, org.springframework.lang.Nullable, org.springframework.util.CollectionUtils, .ObjectUtils

Constants and convenience methods for working with hints.
Author
Rossen Stoyanchev
Since
5.1
See Also
ResourceRegionEncoder#BOUNDARY_STRING_HINT

Field Summary

Modifier and TypeField and Description
public static final String
LOG_PREFIX_HINT

Name of hint exposing a prefix to use for correlating log messages.

public static final String
SUPPRESS_LOGGING_HINT

Name of boolean hint whether to avoid logging data either because it's potentially sensitive, or because it has been logged by a composite encoder, e.g. for multipart requests.

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public static Map<String, Object>

Returns:

the created map
from
(String
the hint name
hintName
,
Object
the hint value
value
)

Create a map wit a single hint via Collections#singletonMap.

public static String

Returns:

the log prefix
getLogPrefix
(Map<String, Object>
the hints passed to the encode method
hints
)

Obtain the hint LOG_PREFIX_HINT, if present, or an empty String.

public static <
the hint type to cast to
T
>
T

Returns:

the hint value
getRequiredHint
(Map<String, Object>
the hints map
hints
,
String
the required hint name
hintName
)

Obtain the value for a required hint.

public static boolean

Returns:

whether logging of data is allowed
isLoggingSuppressed
(Map<String, Object>
the hints map
hints
)

Whether to suppress logging based on the hint SUPPRESS_LOGGING_HINT.

public static Map<String, Object>

Returns:

a single map with hints from both
merge
(Map<String, Object>
1st map of hints
hints1
,
Map<String, Object>
2nd map of hints
hints2
)

Merge two maps of hints, creating and copying into a new map if both have values, or returning the non-empty map, or an empty map if both are empty.

public static Map<String, Object>

Returns:

a single map with all hints
merge
(Map<String, Object>
a map of hints to be merged
hints
,
String
the hint name to merge
hintName
,
Object
the hint value to merge
hintValue
)

Merge a single hint into a map of hints, possibly creating and copying all hints into a new map, or otherwise if the map of hints is empty, creating a new single entry map.

public static Map<String, Object>

Returns:

the empty map
none
()

Return an empty map of hints via Collections#emptyMap().

public static void
touchDataBuffer(DataBuffer
the buffer to touch
buffer
,
Map<String, Object>
the hints map to check for a log prefix
hints
,
Log
the logger whose level to check
logger
)

If the hints contain a LOG_PREFIX_HINT and the given logger has DEBUG level enabled, apply the log prefix as a hint to the given buffer via DataBufferUtils#touch(DataBuffer, Object).

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

LOG_PREFIX_HINTback to summary
public static final String LOG_PREFIX_HINT

Name of hint exposing a prefix to use for correlating log messages.

SUPPRESS_LOGGING_HINTback to summary
public static final String SUPPRESS_LOGGING_HINT

Name of boolean hint whether to avoid logging data either because it's potentially sensitive, or because it has been logged by a composite encoder, e.g. for multipart requests.

Constructor Detail

Hintsback to summary
public Hints()

Method Detail

fromback to summary
public static Map<String, Object> from(String hintName, Object value)

Create a map wit a single hint via Collections#singletonMap.

Parameters
hintName:String

the hint name

value:Object

the hint value

Returns:Map<String, Object>

the created map

getLogPrefixback to summary
public static String getLogPrefix(Map<String, Object> hints)

Obtain the hint LOG_PREFIX_HINT, if present, or an empty String.

Parameters
hints:Map<String, Object>

the hints passed to the encode method

Returns:String

the log prefix

getRequiredHintback to summary
public static <T> T getRequiredHint(Map<String, Object> hints, String hintName)

Obtain the value for a required hint.

Parameters
<T>
the hint type to cast to
hints:Map<String, Object>

the hints map

hintName:String

the required hint name

Returns:T

the hint value

Annotations
@SuppressWarnings:unchecked
Exceptions
IllegalArgumentException:
if the hint is not found
isLoggingSuppressedback to summary
public static boolean isLoggingSuppressed(Map<String, Object> hints)

Whether to suppress logging based on the hint SUPPRESS_LOGGING_HINT.

Parameters
hints:Map<String, Object>

the hints map

Returns:boolean

whether logging of data is allowed

mergeback to summary
public static Map<String, Object> merge(Map<String, Object> hints1, Map<String, Object> hints2)

Merge two maps of hints, creating and copying into a new map if both have values, or returning the non-empty map, or an empty map if both are empty.

Parameters
hints1:Map<String, Object>

1st map of hints

hints2:Map<String, Object>

2nd map of hints

Returns:Map<String, Object>

a single map with hints from both

mergeback to summary
public static Map<String, Object> merge(Map<String, Object> hints, String hintName, Object hintValue)

Merge a single hint into a map of hints, possibly creating and copying all hints into a new map, or otherwise if the map of hints is empty, creating a new single entry map.

Parameters
hints:Map<String, Object>

a map of hints to be merged

hintName:String

the hint name to merge

hintValue:Object

the hint value to merge

Returns:Map<String, Object>

a single map with all hints

noneback to summary
public static Map<String, Object> none()

Return an empty map of hints via Collections#emptyMap().

Returns:Map<String, Object>

the empty map

touchDataBufferback to summary
public static void touchDataBuffer(DataBuffer buffer, Map<String, Object> hints, Log logger)

If the hints contain a LOG_PREFIX_HINT and the given logger has DEBUG level enabled, apply the log prefix as a hint to the given buffer via DataBufferUtils#touch(DataBuffer, Object).

Parameters
buffer:DataBuffer

the buffer to touch

hints:Map<String, Object>

the hints map to check for a log prefix

logger:Log

the logger whose level to check

Since
5.3.2