spring-framework / org.springframework.util

Package org.springframework.util

Types

AlternativeJdkIdGenerator

open class AlternativeJdkIdGenerator : IdGenerator

An IdGenerator that uses SecureRandom for the initial seed and Random thereafter, instead of calling UUID#randomUUID() every time as org.springframework.util.JdkIdGenerator does. This provides a better balance between securely random ids and performance.

Assert

abstract class Assert

Assertion utility class that assists in validating arguments.

Useful for identifying programmer errors early and clearly at runtime.

For example, if the contract of a public method states it does not allow null arguments, Assert can be used to validate that contract. Doing this clearly indicates a contract violation when it occurs and protects the class's invariants.

Typically used to validate method arguments rather than configuration properties, to check for cases that are usually programmer errors rather than configuration errors. In contrast to configuration initialization code, there is usually no point in falling back to defaults in such methods.

This class is similar to JUnit's assertion library. If an argument value is deemed invalid, an IllegalArgumentException is thrown (typically). For example:

 Assert.notNull(clazz, "The class must not be null"); Assert.isTrue(i > 0, "The value must be greater than zero");

Mainly for internal use within the framework; consider Apache's Commons Lang for a more comprehensive suite of String utilities.

AutoPopulatingList

open class AutoPopulatingList<E : Any> : MutableList<E>, Serializable

Simple List wrapper class that allows for elements to be automatically populated as they are requested. This is particularly useful for data binding to List, allowing for elements to be created and added to the List in a "just in time" fashion.

Note: This class is not thread-safe. To create a thread-safe version, use the java.util.Collections#synchronizedList utility methods.

Inspired by LazyList from Commons Collections.

Base64Utils

abstract class Base64Utils

A simple utility class for Base64 encoding and decoding.

Adapts to Java 8's java.util.Base64 in a convenience fashion.

CollectionUtils

abstract class CollectionUtils

Miscellaneous collection utility methods. Mainly for internal use within the framework.

CommonsLogWriter

open class CommonsLogWriter : Writer

java.io.Writer adapter for a Commons Logging Log.

CompositeIterator

open class CompositeIterator<E : Any> : MutableIterator<E>

Composite iterator that combines multiple other iterators, as registered via #add(Iterator).

This implementation maintains a linked set of iterators which are invoked in sequence until all iterators are exhausted.

DigestUtils

abstract class DigestUtils

Miscellaneous methods for calculating digests.

Mainly for internal use within the framework; consider Apache Commons Codec for a more comprehensive suite of digest utilities.

ExceptionTypeFilter

open class ExceptionTypeFilter : InstanceFilter<Class<out Throwable>>

An InstanceFilter implementation that handles exception types. A type will match against a given candidate if it is assignable to that candidate.

FastByteArrayOutputStream

open class FastByteArrayOutputStream : OutputStream

A speedy alternative to java.io.ByteArrayOutputStream. Note that this variant does not extend ByteArrayOutputStream, unlike its sibling ResizableByteArrayOutputStream.

Unlike java.io.ByteArrayOutputStream, this implementation is backed by a java.util.LinkedList of byte[] instead of 1 constantly resizing byte[]. It does not copy buffers when it gets expanded.

The initial buffer is only created when the stream is first written. There is also no copying of the internal buffer if its contents is extracted with the #writeTo(OutputStream) method.

FileCopyUtils

abstract class FileCopyUtils

Simple utility methods for file and stream copying. All copy methods use a block size of 4096 bytes, and close all affected streams when done. A variation of the copy methods from this class that leave streams open can be found in StreamUtils.

Mainly for use within the framework, but also useful for application code.

FileSystemUtils

abstract class FileSystemUtils

Utility methods for working with the file system.

JdkIdGenerator

open class JdkIdGenerator : IdGenerator

An IdGenerator that calls java.util.UUID#randomUUID().

LinkedCaseInsensitiveMap

open class LinkedCaseInsensitiveMap<V : Any> : MutableMap<String, V>, Serializable, Cloneable

LinkedHashMap variant that stores String keys in a case-insensitive manner, for example for key-based access in a results table.

Preserves the original order as well as the original casing of keys, while allowing for contains, get and remove calls with any case of key.

Does not support null keys.

PatternMatchUtils

abstract class PatternMatchUtils

Utility methods for simple pattern matching, in particular for Spring's typical "xxx*", "*xxx" and "*xxx*" pattern styles.

ReflectionUtils

abstract class ReflectionUtils

Simple utility class for working with the reflection API and handling reflection exceptions.

Only intended for internal use.

ResizableByteArrayOutputStream

open class ResizableByteArrayOutputStream : ByteArrayOutputStream

An extension of java.io.ByteArrayOutputStream that:

As of 4.2, this class has been superseded by FastByteArrayOutputStream for Spring's internal use where no assignability to ByteArrayOutputStream is needed (since FastByteArrayOutputStream is more efficient with buffer resize management but doesn't extend the standard ByteArrayOutputStream).

SerializationUtils

abstract class SerializationUtils

Static utilities for serialization and deserialization.

SimpleIdGenerator

open class SimpleIdGenerator : IdGenerator

A simple IdGenerator that starts at 1 and increments by 1 with each call.

SocketUtils

open class SocketUtils

Simple utility methods for working with network sockets — for example, for finding available ports on localhost.

Within this class, a TCP port refers to a port for a ServerSocket; whereas, a UDP port refers to a port for a DatagramSocket.

StopWatch

open class StopWatch

Simple stop watch, allowing for timing of a number of tasks, exposing total running time and running time for each named task.

Conceals use of System.currentTimeMillis(), improving the readability of application code and reducing the likelihood of calculation errors.

Note that this object is not designed to be thread-safe and does not use synchronization.

This class is normally used to verify performance during proof-of-concepts and in development, rather than as part of production applications.

SystemPropertyUtils

abstract class SystemPropertyUtils

Helper class for resolving placeholders in texts. Usually applied to file paths.

A text may contain ${...} placeholders, to be resolved as system properties: e.g. ${user.dir}. Default values can be supplied using the ":" separator between key and value.

TypeUtils

abstract class TypeUtils

Utility to work with Java 5 generic type parameters. Mainly for internal use within the framework.

Exceptions

InvalidMimeTypeException

open class InvalidMimeTypeException : IllegalArgumentException

Exception thrown from MimeTypeUtils#parseMimeType(String) in case of encountering an invalid content type specification String.