Package feign
Class Util
- java.lang.Object
-
- feign.Util
-
public class Util extends java.lang.Object
Utilities, typically copied in from guava, so as to avoid dependency conflicts.
-
-
Field Summary
Fields Modifier and Type Field Description static java.lang.String
CONTENT_ENCODING
The HTTP Content-Encoding header field name.static java.lang.String
CONTENT_LENGTH
The HTTP Content-Length header field name.static java.lang.String
ENCODING_DEFLATE
Value for the Content-Encoding header that indicates that DEFLATE encoding is in use.static java.lang.String
ENCODING_GZIP
Value for the Content-Encoding header that indicates that GZIP encoding is in use.static java.nio.charset.Charset
ISO_8859_1
ISO-8859-1: ISO Latin Alphabet Number 1 (ISO-LATIN-1).static java.lang.reflect.Type
MAP_STRING_WILDCARD
Type literal forMap<String, ?>
.static java.lang.String
RETRY_AFTER
The HTTP Retry-After header field name.static java.nio.charset.Charset
UTF_8
UTF-8: eight-bit UCS Transformation Format.
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static void
checkArgument(boolean expression, java.lang.String errorMessageTemplate, java.lang.Object... errorMessageArgs)
Copy ofcom.google.common.base.Preconditions#checkArgument
.static <T> T
checkNotNull(T reference, java.lang.String errorMessageTemplate, java.lang.Object... errorMessageArgs)
Copy ofcom.google.common.base.Preconditions#checkNotNull
.static void
checkState(boolean expression, java.lang.String errorMessageTemplate, java.lang.Object... errorMessageArgs)
Copy ofcom.google.common.base.Preconditions#checkState
.static java.lang.String
decodeOrDefault(byte[] data, java.nio.charset.Charset charset, java.lang.String defaultValue)
static java.lang.String
emptyToNull(java.lang.String string)
Adapted fromcom.google.common.base.Strings#emptyToNull
.static java.lang.Object
emptyValueOf(java.lang.reflect.Type type)
This returns well known empty values for well-known java types.static void
ensureClosed(java.io.Closeable closeable)
static boolean
isBlank(java.lang.String value)
If the provided String is null or empty.static boolean
isDefault(java.lang.reflect.Method method)
Identifies a method as a default instance method.static boolean
isNotBlank(java.lang.String value)
If the provided String is not null or empty.static <T> T[]
removeValues(T[] values, java.util.function.Predicate<T> shouldRemove, java.lang.Class<T> type)
Removes values from the array that meet the criteria for removal via the suppliedPredicate
valuestatic java.lang.reflect.Type
resolveLastTypeParameter(java.lang.reflect.Type genericContext, java.lang.Class<?> supertype)
Resolves the last type parameter of the parameterizedsupertype
, based on thegenericContext
, into its upper bounds.static <T> T[]
toArray(java.lang.Iterable<? extends T> iterable, java.lang.Class<T> type)
Adapted fromcom.google.common.base.Strings#emptyToNull
.static byte[]
toByteArray(java.io.InputStream in)
Adapted fromcom.google.common.io.ByteStreams.toByteArray()
.static java.lang.String
toString(java.io.Reader reader)
Adapted fromcom.google.common.io.CharStreams.toString()
.static <T> java.util.Collection<T>
valuesOrEmpty(java.util.Map<java.lang.String,java.util.Collection<T>> map, java.lang.String key)
Returns an unmodifiable collection which may be empty, but is never null.
-
-
-
Field Detail
-
CONTENT_LENGTH
public static final java.lang.String CONTENT_LENGTH
The HTTP Content-Length header field name.- See Also:
- Constant Field Values
-
CONTENT_ENCODING
public static final java.lang.String CONTENT_ENCODING
The HTTP Content-Encoding header field name.- See Also:
- Constant Field Values
-
RETRY_AFTER
public static final java.lang.String RETRY_AFTER
The HTTP Retry-After header field name.- See Also:
- Constant Field Values
-
ENCODING_GZIP
public static final java.lang.String ENCODING_GZIP
Value for the Content-Encoding header that indicates that GZIP encoding is in use.- See Also:
- Constant Field Values
-
ENCODING_DEFLATE
public static final java.lang.String ENCODING_DEFLATE
Value for the Content-Encoding header that indicates that DEFLATE encoding is in use.- See Also:
- Constant Field Values
-
UTF_8
public static final java.nio.charset.Charset UTF_8
UTF-8: eight-bit UCS Transformation Format.
-
ISO_8859_1
public static final java.nio.charset.Charset ISO_8859_1
ISO-8859-1: ISO Latin Alphabet Number 1 (ISO-LATIN-1).
-
MAP_STRING_WILDCARD
public static final java.lang.reflect.Type MAP_STRING_WILDCARD
Type literal forMap<String, ?>
.
-
-
Method Detail
-
checkArgument
public static void checkArgument(boolean expression, java.lang.String errorMessageTemplate, java.lang.Object... errorMessageArgs)
Copy ofcom.google.common.base.Preconditions#checkArgument
.
-
checkNotNull
public static <T> T checkNotNull(T reference, java.lang.String errorMessageTemplate, java.lang.Object... errorMessageArgs)
Copy ofcom.google.common.base.Preconditions#checkNotNull
.
-
checkState
public static void checkState(boolean expression, java.lang.String errorMessageTemplate, java.lang.Object... errorMessageArgs)
Copy ofcom.google.common.base.Preconditions#checkState
.
-
isDefault
public static boolean isDefault(java.lang.reflect.Method method)
Identifies a method as a default instance method.
-
emptyToNull
public static java.lang.String emptyToNull(java.lang.String string)
Adapted fromcom.google.common.base.Strings#emptyToNull
.
-
removeValues
public static <T> T[] removeValues(T[] values, java.util.function.Predicate<T> shouldRemove, java.lang.Class<T> type)
Removes values from the array that meet the criteria for removal via the suppliedPredicate
value
-
toArray
public static <T> T[] toArray(java.lang.Iterable<? extends T> iterable, java.lang.Class<T> type)
Adapted fromcom.google.common.base.Strings#emptyToNull
.
-
valuesOrEmpty
public static <T> java.util.Collection<T> valuesOrEmpty(java.util.Map<java.lang.String,java.util.Collection<T>> map, java.lang.String key)
Returns an unmodifiable collection which may be empty, but is never null.
-
ensureClosed
public static void ensureClosed(java.io.Closeable closeable)
-
resolveLastTypeParameter
public static java.lang.reflect.Type resolveLastTypeParameter(java.lang.reflect.Type genericContext, java.lang.Class<?> supertype) throws java.lang.IllegalStateException
Resolves the last type parameter of the parameterizedsupertype
, based on thegenericContext
, into its upper bounds. Implementation copied fromretrofit.RestMethodInfo
.- Parameters:
genericContext
- Ex.Field.getGenericType()
supertype
- Ex.Decoder.class
- Returns:
- in the example above, the type parameter of
Decoder
. - Throws:
java.lang.IllegalStateException
- ifsupertype
cannot be resolved into a parameterized type usingcontext
.
-
emptyValueOf
public static java.lang.Object emptyValueOf(java.lang.reflect.Type type)
This returns well known empty values for well-known java types. This returns null for types not in the following list.[Bb]oolean
byte[]
Collection
Iterator
List
Map
Set
decoding HTTP 404 status
, you'll need to teach decoders a default empty value for a type. This method cheaply supports typical types by only looking at the raw type (vs type hierarchy). Decorate for sophistication.
-
toString
public static java.lang.String toString(java.io.Reader reader) throws java.io.IOException
Adapted fromcom.google.common.io.CharStreams.toString()
.- Throws:
java.io.IOException
-
toByteArray
public static byte[] toByteArray(java.io.InputStream in) throws java.io.IOException
Adapted fromcom.google.common.io.ByteStreams.toByteArray()
.- Throws:
java.io.IOException
-
decodeOrDefault
public static java.lang.String decodeOrDefault(byte[] data, java.nio.charset.Charset charset, java.lang.String defaultValue)
-
isNotBlank
public static boolean isNotBlank(java.lang.String value)
If the provided String is not null or empty.- Parameters:
value
- to evaluate.- Returns:
- true of the value is not null and not empty.
-
isBlank
public static boolean isBlank(java.lang.String value)
If the provided String is null or empty.- Parameters:
value
- to evaluate.- Returns:
- true if the value is null or empty.
-
-