or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

Files

docs

annotation-processing.mdaot-optimization.mdcore-infrastructure.mdenvironment-config.mdindex.mdresource-management.mdtask-execution.mdtype-conversion.mdutilities.md

utilities.mddocs/

0

# Utilities and Bundled Libraries

1

2

Spring Core includes an extensive collection of utility classes and bundled third-party libraries that provide essential functionality for common programming tasks. These utilities handle everything from string manipulation and reflection to bytecode generation and proxy creation.

3

4

## String Utilities

5

6

Spring's `StringUtils` provides comprehensive string manipulation capabilities that are null-safe and performance-optimized.

7

8

**StringUtils Class**

9

```java { .api }

10

public abstract class StringUtils {

11

// Null and empty checks

12

public static boolean isEmpty(Object str);

13

public static boolean hasLength(String str);

14

public static boolean hasText(String str);

15

public static boolean containsWhitespace(String str);

16

17

// Trimming operations

18

public static String trimWhitespace(String str);

19

public static String trimAllWhitespace(String str);

20

public static String trimLeadingWhitespace(String str);

21

public static String trimTrailingWhitespace(String str);

22

public static String trimLeadingCharacter(String str, char leadingCharacter);

23

public static String trimTrailingCharacter(String str, char trailingCharacter);

24

25

// Case operations

26

public static String capitalize(String str);

27

public static String uncapitalize(String str);

28

29

// String parsing and tokenization

30

public static String[] split(String toSplit, String delimiter);

31

public static String[] tokenizeToStringArray(String str, String delimiters);

32

public static String[] tokenizeToStringArray(String str, String delimiters, boolean trimTokens, boolean ignoreEmptyTokens);

33

public static String[] delimitedListToStringArray(String str, String delimiter);

34

public static String[] delimitedListToStringArray(String str, String delimiter, String charsToDelete);

35

public static String[] commaDelimitedListToStringArray(String str);

36

37

// Collection conversions

38

public static String collectionToDelimitedString(Collection<?> coll, String delim);

39

public static String collectionToDelimitedString(Collection<?> coll, String delim, String prefix, String suffix);

40

public static String collectionToCommaDelimitedString(Collection<?> coll);

41

public static String arrayToDelimitedString(Object[] arr, String delim);

42

public static String arrayToCommaDelimitedString(Object[] arr);

43

44

// Path operations

45

public static String cleanPath(String path);

46

public static boolean pathEquals(String path1, String path2);

47

public static String applyRelativePath(String path, String relativePath);

48

public static String getFilename(String path);

49

public static String getFilenameExtension(String path);

50

public static String stripFilenameExtension(String path);

51

52

// Pattern matching

53

public static boolean matchesCharacter(String str, char singleCharacter);

54

public static boolean startsWithIgnoreCase(String str, String prefix);

55

public static boolean endsWithIgnoreCase(String str, String suffix);

56

public static boolean substringMatch(CharSequence str, int index, CharSequence substring);

57

public static int countOccurrencesOf(String str, String sub);

58

59

// String replacement

60

public static String replace(String inString, String oldPattern, String newPattern);

61

public static String delete(String inString, String pattern);

62

public static String deleteAny(String inString, String charsToDelete);

63

64

// Locale and language

65

public static Locale parseLocale(String localeValue);

66

public static Locale parseLocaleString(String localeString);

67

public static String toLanguageTag(Locale locale);

68

69

// Quote handling

70

public static String quote(String str);

71

public static Object quoteIfString(Object obj);

72

public static String unquote(String str);

73

}

74

```

75

76

**Usage Examples**

77

```java

78

// Null-safe string checks

79

String input = " Hello World ";

80

boolean hasContent = StringUtils.hasText(input); // true

81

boolean hasLength = StringUtils.hasLength(""); // false

82

boolean isEmpty = StringUtils.isEmpty(null); // true

83

84

// Trimming operations

85

String trimmed = StringUtils.trimWhitespace(input); // "Hello World"

86

String noWhitespace = StringUtils.trimAllWhitespace(input); // "HelloWorld"

87

88

// Case operations

89

String capitalized = StringUtils.capitalize("hello"); // "Hello"

90

String uncapitalized = StringUtils.uncapitalize("Hello"); // "hello"

91

92

// String tokenization

93

String csv = "apple,banana,cherry";

94

String[] fruits = StringUtils.commaDelimitedListToStringArray(csv);

95

// Result: ["apple", "banana", "cherry"]

96

97

String data = "a;b;c";

98

String[] tokens = StringUtils.tokenizeToStringArray(data, ";", true, true);

99

100

// Collection to string conversion

101

List<String> items = Arrays.asList("one", "two", "three");

102

String delimited = StringUtils.collectionToDelimitedString(items, " | ");

103

// Result: "one | two | three"

104

105

String commaList = StringUtils.collectionToCommaDelimitedString(items);

106

// Result: "one,two,three"

107

108

// Path operations

109

String path = "/user/../admin/./files/document.pdf";

110

String cleanPath = StringUtils.cleanPath(path); // "/admin/files/document.pdf"

111

String filename = StringUtils.getFilename(cleanPath); // "document.pdf"

112

String extension = StringUtils.getFilenameExtension(filename); // "pdf"

113

114

// Pattern matching and replacement

115

String text = "Hello World Hello";

116

int count = StringUtils.countOccurrencesOf(text, "Hello"); // 2

117

String replaced = StringUtils.replace(text, "Hello", "Hi"); // "Hi World Hi"

118

String deleted = StringUtils.delete(text, "Hello"); // " World "

119

120

// Locale parsing

121

Locale locale = StringUtils.parseLocale("en_US"); // Locale.US

122

String languageTag = StringUtils.toLanguageTag(Locale.FRANCE); // "fr-FR"

123

```

124

125

## Collection Utilities

126

127

**MultiValueMap Interface and Implementation**

128

```java { .api }

129

public interface MultiValueMap<K, V> extends Map<K, List<V>> {

130

V getFirst(K key);

131

void add(K key, V value);

132

void addAll(K key, List<? extends V> values);

133

void addAll(MultiValueMap<K, V> values);

134

void set(K key, V value);

135

void setAll(Map<K, V> values);

136

Map<K, V> toSingleValueMap();

137

}

138

139

public class LinkedMultiValueMap<K, V> implements MultiValueMap<K, V>, Serializable, Cloneable {

140

public LinkedMultiValueMap();

141

public LinkedMultiValueMap(int initialCapacity);

142

public LinkedMultiValueMap(Map<K, List<V>> otherMap);

143

144

@Override

145

public V getFirst(K key);

146

@Override

147

public void add(K key, V value);

148

@Override

149

public void addAll(K key, List<? extends V> values);

150

@Override

151

public void addAll(MultiValueMap<K, V> values);

152

@Override

153

public void set(K key, V value);

154

@Override

155

public void setAll(Map<K, V> values);

156

@Override

157

public Map<K, V> toSingleValueMap();

158

159

@Override

160

public LinkedMultiValueMap<K, V> clone();

161

}

162

```

163

164

**ConcurrentReferenceHashMap**

165

```java { .api }

166

public class ConcurrentReferenceHashMap<K, V> extends AbstractMap<K, V> implements ConcurrentMap<K, V> {

167

public enum ReferenceType {

168

SOFT, WEAK

169

}

170

171

public ConcurrentReferenceHashMap();

172

public ConcurrentReferenceHashMap(int initialCapacity);

173

public ConcurrentReferenceHashMap(int initialCapacity, float loadFactor);

174

public ConcurrentReferenceHashMap(int initialCapacity, float loadFactor, int concurrencyLevel);

175

public ConcurrentReferenceHashMap(int initialCapacity, float loadFactor, int concurrencyLevel, ReferenceType referenceType);

176

177

public int size();

178

public boolean isEmpty();

179

public V get(Object key);

180

public boolean containsKey(Object key);

181

public V put(K key, V value);

182

public V putIfAbsent(K key, V value);

183

public V remove(Object key);

184

public boolean remove(Object key, Object value);

185

public V replace(K key, V value);

186

public boolean replace(K key, V oldValue, V newValue);

187

public void clear();

188

public void purgeUnreferencedEntries();

189

}

190

```

191

192

**Usage Examples**

193

```java

194

// MultiValueMap usage

195

MultiValueMap<String, String> headers = new LinkedMultiValueMap<>();

196

headers.add("Accept", "application/json");

197

headers.add("Accept", "application/xml");

198

headers.add("Content-Type", "application/json");

199

200

String firstAccept = headers.getFirst("Accept"); // "application/json"

201

List<String> allAccepts = headers.get("Accept"); // ["application/json", "application/xml"]

202

203

// Convert to single value map

204

Map<String, String> singleValueMap = headers.toSingleValueMap();

205

// Result: {"Accept": "application/json", "Content-Type": "application/json"}

206

207

// Batch operations

208

Map<String, String> additionalHeaders = Map.of(

209

"Authorization", "Bearer token",

210

"User-Agent", "MyApp/1.0"

211

);

212

headers.setAll(additionalHeaders);

213

214

// ConcurrentReferenceHashMap for memory-sensitive caching

215

ConcurrentReferenceHashMap<String, Object> cache = new ConcurrentReferenceHashMap<>(

216

16, 0.75f, 16, ConcurrentReferenceHashMap.ReferenceType.SOFT);

217

218

// Store cached objects that can be garbage collected under memory pressure

219

cache.put("user:123", loadUser(123));

220

cache.put("config:app", loadConfiguration());

221

222

// Objects may be automatically removed by GC

223

Object user = cache.get("user:123"); // May return null if GC'd

224

if (user == null) {

225

user = loadUser(123);

226

cache.put("user:123", user);

227

}

228

229

// Manually clean up unreferenced entries

230

cache.purgeUnreferencedEntries();

231

```

232

233

## Reflection Utilities

234

235

**ReflectionUtils Class**

236

```java { .api }

237

public abstract class ReflectionUtils {

238

// Field operations

239

public static Field findField(Class<?> clazz, String name);

240

public static Field findField(Class<?> clazz, String name, Class<?> type);

241

public static void setField(Field field, Object target, Object value);

242

public static Object getField(Field field, Object target);

243

public static void makeAccessible(Field field);

244

public static boolean isPublicStaticFinal(Field field);

245

246

// Method operations

247

public static Method findMethod(Class<?> clazz, String name);

248

public static Method findMethod(Class<?> clazz, String name, Class<?>... paramTypes);

249

public static Object invokeMethod(Method method, Object target);

250

public static Object invokeMethod(Method method, Object target, Object... args);

251

public static boolean isEqualsMethod(Method method);

252

public static boolean isHashCodeMethod(Method method);

253

public static boolean isToStringMethod(Method method);

254

public static boolean isObjectMethod(Method method);

255

public static boolean isCglibRenamedMethod(Method method);

256

public static void makeAccessible(Method method);

257

258

// Constructor operations

259

public static Constructor<T> accessibleConstructor(Class<T> clazz, Class<?>... parameterTypes) throws NoSuchMethodException;

260

public static void makeAccessible(Constructor<?> ctor);

261

262

// Callback-based iteration

263

public static void doWithLocalFields(Class<?> clazz, FieldCallback fc);

264

public static void doWithFields(Class<?> clazz, FieldCallback fc);

265

public static void doWithFields(Class<?> clazz, FieldCallback fc, FieldFilter ff);

266

public static void doWithLocalMethods(Class<?> clazz, MethodCallback mc);

267

public static void doWithMethods(Class<?> clazz, MethodCallback mc);

268

public static void doWithMethods(Class<?> clazz, MethodCallback mc, MethodFilter mf);

269

270

// Method filtering

271

public static Method[] getAllDeclaredMethods(Class<?> leafClass);

272

public static Method[] getUniqueDeclaredMethods(Class<?> leafClass);

273

public static Method[] getUniqueDeclaredMethods(Class<?> leafClass, MethodFilter mf);

274

275

// Utility filters

276

public static final MethodFilter USER_DECLARED_METHODS;

277

public static final MethodFilter COPYABLE_FIELDS;

278

}

279

280

@FunctionalInterface

281

public interface FieldCallback {

282

void doWith(Field field) throws IllegalArgumentException, IllegalAccessException;

283

}

284

285

@FunctionalInterface

286

public interface MethodCallback {

287

void doWith(Method method) throws IllegalArgumentException, IllegalAccessException;

288

}

289

290

@FunctionalInterface

291

public interface FieldFilter {

292

boolean matches(Field field);

293

}

294

295

@FunctionalInterface

296

public interface MethodFilter {

297

boolean matches(Method method);

298

}

299

```

300

301

**Usage Examples**

302

```java

303

// Field operations

304

public class User {

305

private String name;

306

private int age;

307

private final String id = "USER_001";

308

}

309

310

User user = new User();

311

Class<?> userClass = User.class;

312

313

// Find and set field values

314

Field nameField = ReflectionUtils.findField(userClass, "name");

315

ReflectionUtils.makeAccessible(nameField);

316

ReflectionUtils.setField(nameField, user, "John Doe");

317

318

Field ageField = ReflectionUtils.findField(userClass, "age");

319

ReflectionUtils.makeAccessible(ageField);

320

ReflectionUtils.setField(ageField, user, 30);

321

322

// Get field values

323

String name = (String) ReflectionUtils.getField(nameField, user); // "John Doe"

324

Integer age = (Integer) ReflectionUtils.getField(ageField, user); // 30

325

326

// Method operations

327

Method toStringMethod = ReflectionUtils.findMethod(userClass, "toString");

328

String userString = (String) ReflectionUtils.invokeMethod(toStringMethod, user);

329

330

// Check method types

331

boolean isToString = ReflectionUtils.isToStringMethod(toStringMethod); // true

332

boolean isEquals = ReflectionUtils.isEqualsMethod(toStringMethod); // false

333

334

// Iterate over all fields

335

ReflectionUtils.doWithFields(userClass, field -> {

336

System.out.println("Field: " + field.getName() + " Type: " + field.getType());

337

if (!ReflectionUtils.isPublicStaticFinal(field)) {

338

ReflectionUtils.makeAccessible(field);

339

Object value = ReflectionUtils.getField(field, user);

340

System.out.println(" Value: " + value);

341

}

342

});

343

344

// Iterate over methods with filtering

345

ReflectionUtils.doWithMethods(userClass, method -> {

346

System.out.println("User-declared method: " + method.getName());

347

}, ReflectionUtils.USER_DECLARED_METHODS);

348

349

// Find specific method patterns

350

ReflectionUtils.doWithMethods(userClass, method -> {

351

if (method.getName().startsWith("get") || method.getName().startsWith("set")) {

352

System.out.println("Getter/Setter: " + method.getName());

353

}

354

});

355

356

// Constructor operations

357

Constructor<User> constructor = ReflectionUtils.accessibleConstructor(User.class);

358

User newUser = constructor.newInstance();

359

```

360

361

## Class Utilities

362

363

**ClassUtils Class**

364

```java { .api }

365

public abstract class ClassUtils {

366

// Class loading

367

public static Class<?> forName(String name, ClassLoader classLoader) throws ClassNotFoundException, LinkageError;

368

public static ClassLoader getDefaultClassLoader();

369

public static ClassLoader overrideThreadContextClassLoader(ClassLoader classLoaderToUse);

370

public static boolean isPresent(String className, ClassLoader classLoader);

371

372

// Class inspection

373

public static boolean isVisible(Class<?> clazz, ClassLoader classLoader);

374

public static boolean isCacheSafe(Class<?> clazz, ClassLoader classLoader);

375

public static Class<?> getUserClass(Object instance);

376

public static Class<?> getUserClass(Class<?> clazz);

377

378

// Interface operations

379

public static Class<?>[] getAllInterfaces(Object instance);

380

public static Class<?>[] getAllInterfacesForClass(Class<?> clazz);

381

public static Class<?>[] getAllInterfacesForClass(Class<?> clazz, ClassLoader classLoader);

382

public static Set<Class<?>> getAllInterfacesAsSet(Object instance);

383

public static Set<Class<?>> getAllInterfacesForClassAsSet(Class<?> clazz);

384

public static Set<Class<?>> getAllInterfacesForClassAsSet(Class<?> clazz, ClassLoader classLoader);

385

386

// Package and name operations

387

public static String getShortName(String className);

388

public static String getShortName(Class<?> clazz);

389

public static String getShortNameAsProperty(Class<?> clazz);

390

public static String getClassFileName(Class<?> clazz);

391

public static String getPackageName(Class<?> clazz);

392

public static String getPackageName(String fqClassName);

393

public static String getQualifiedName(Class<?> clazz);

394

public static String getQualifiedMethodName(Method method);

395

public static String getQualifiedMethodName(Method method, Class<?> clazz);

396

397

// Type checking

398

public static boolean matchesTypeName(Class<?> clazz, String typeName);

399

public static boolean hasConstructor(Class<?> clazz, Class<?>... paramTypes);

400

public static Constructor<T> getConstructorIfAvailable(Class<T> clazz, Class<?>... paramTypes);

401

public static boolean hasMethod(Class<?> clazz, String methodName, Class<?>... paramTypes);

402

public static Method getMethod(Class<?> clazz, String methodName, Class<?>... paramTypes);

403

public static Method getMethodIfAvailable(Class<?> clazz, String methodName, Class<?>... paramTypes);

404

public static int getMethodCountForName(Class<?> clazz, String methodName);

405

public static boolean hasAtLeastOneMethodWithName(Class<?> clazz, String methodName);

406

407

// Primitive and wrapper operations

408

public static boolean isPrimitiveWrapper(Class<?> clazz);

409

public static boolean isPrimitiveOrWrapper(Class<?> clazz);

410

public static boolean isPrimitiveArray(Class<?> clazz);

411

public static boolean isPrimitiveWrapperArray(Class<?> clazz);

412

public static Class<?> resolvePrimitiveIfNecessary(Class<?> clazz);

413

public static boolean isAssignable(Class<?> lhsType, Class<?> rhsType);

414

public static boolean isAssignableValue(Class<?> type, Object value);

415

416

// Array operations

417

public static String addResourcePathToPackagePath(Class<?> clazz, String resourceName);

418

public static String classPackageAsResourcePath(Class<?> clazz);

419

public static String classNamesToString(Class<?>... classes);

420

public static String classNamesToString(Collection<Class<?>> classes);

421

public static Class<?>[] toClassArray(Collection<Class<?>> collection);

422

}

423

```

424

425

**Usage Examples**

426

```java

427

// Class loading and presence checking

428

ClassLoader classLoader = ClassUtils.getDefaultClassLoader();

429

boolean hasJackson = ClassUtils.isPresent("com.fasterxml.jackson.databind.ObjectMapper", classLoader);

430

431

if (hasJackson) {

432

Class<?> objectMapperClass = ClassUtils.forName("com.fasterxml.jackson.databind.ObjectMapper", classLoader);

433

}

434

435

// Class name operations

436

Class<?> userClass = User.class;

437

String shortName = ClassUtils.getShortName(userClass); // "User"

438

String packageName = ClassUtils.getPackageName(userClass); // "com.example"

439

String qualifiedName = ClassUtils.getQualifiedName(userClass); // "com.example.User"

440

String propertyName = ClassUtils.getShortNameAsProperty(userClass); // "user"

441

442

// Interface operations

443

Set<Class<?>> allInterfaces = ClassUtils.getAllInterfacesForClassAsSet(ArrayList.class);

444

// Includes: List, Collection, Iterable, RandomAccess, Cloneable, Serializable

445

446

// Method operations

447

boolean hasToString = ClassUtils.hasMethod(userClass, "toString");

448

Method toStringMethod = ClassUtils.getMethodIfAvailable(userClass, "toString");

449

int toStringCount = ClassUtils.getMethodCountForName(userClass, "toString");

450

451

// Constructor operations

452

boolean hasDefaultConstructor = ClassUtils.hasConstructor(userClass);

453

Constructor<User> constructor = ClassUtils.getConstructorIfAvailable(User.class, String.class);

454

455

// Type checking

456

boolean isPrimitive = ClassUtils.isPrimitiveOrWrapper(Integer.class); // true

457

boolean isAssignable = ClassUtils.isAssignable(Number.class, Integer.class); // true

458

boolean canAssignValue = ClassUtils.isAssignableValue(String.class, "hello"); // true

459

460

// Get user class (unwrap proxies)

461

Object proxyObject = createProxyFor(new UserService());

462

Class<?> actualClass = ClassUtils.getUserClass(proxyObject); // UserService.class

463

```

464

465

## Path Matching

466

467

**AntPathMatcher Class**

468

```java { .api }

469

public class AntPathMatcher implements PathMatcher {

470

public static final String DEFAULT_PATH_SEPARATOR = "/";

471

472

public AntPathMatcher();

473

public AntPathMatcher(String pathSeparator);

474

475

public void setPathSeparator(String pathSeparator);

476

public void setCaseSensitive(boolean caseSensitive);

477

public void setTrimTokens(boolean trimTokens);

478

public void setCachePatterns(boolean cachePatterns);

479

480

@Override

481

public boolean isPattern(String path);

482

@Override

483

public boolean match(String pattern, String path);

484

@Override

485

public boolean matchStart(String pattern, String path);

486

@Override

487

public String extractPathWithinPattern(String pattern, String path);

488

@Override

489

public Map<String, String> extractUriTemplateVariables(String pattern, String path);

490

@Override

491

public Comparator<String> getPatternComparator(String path);

492

@Override

493

public String combine(String pattern1, String pattern2);

494

}

495

```

496

497

**Usage Examples**

498

```java

499

// Create path matcher

500

AntPathMatcher pathMatcher = new AntPathMatcher();

501

pathMatcher.setCaseSensitive(false);

502

pathMatcher.setTrimTokens(true);

503

504

// Pattern matching

505

boolean matches1 = pathMatcher.match("*.txt", "readme.txt"); // true

506

boolean matches2 = pathMatcher.match("/users/**", "/users/123/profile"); // true

507

boolean matches3 = pathMatcher.match("/api/{version}/users", "/api/v1/users"); // true

508

509

// Pattern checking

510

boolean isPattern = pathMatcher.isPattern("/users/{id}"); // true

511

boolean isLiteral = pathMatcher.isPattern("/users/123"); // false

512

513

// Extract variables

514

String pattern = "/users/{userId}/orders/{orderId}";

515

String path = "/users/123/orders/456";

516

Map<String, String> variables = pathMatcher.extractUriTemplateVariables(pattern, path);

517

// Result: {userId=123, orderId=456}

518

519

// Extract path within pattern

520

String extracted = pathMatcher.extractPathWithinPattern("/static/**", "/static/css/style.css");

521

// Result: "css/style.css"

522

523

// Pattern combination

524

String combined = pathMatcher.combine("/api/**", "users/{id}"); // "/api/**/users/{id}"

525

526

// Comparator for pattern ordering

527

List<String> patterns = Arrays.asList("/users/*", "/users/**", "/users/{id}");

528

patterns.sort(pathMatcher.getPatternComparator("/users/123"));

529

// Most specific patterns first: ["/users/{id}", "/users/*", "/users/**"]

530

```

531

532

## MIME Type Support

533

534

**MimeType Class**

535

```java { .api }

536

public class MimeType implements Comparable<MimeType>, Serializable {

537

public static final String WILDCARD_TYPE = "*";

538

539

public MimeType(String type);

540

public MimeType(String type, String subtype);

541

public MimeType(String type, String subtype, Charset charset);

542

public MimeType(String type, String subtype, Map<String, String> parameters);

543

public MimeType(MimeType other, Charset charset);

544

public MimeType(MimeType other, Map<String, String> parameters);

545

546

protected MimeType(MimeType other);

547

548

public String getType();

549

public String getSubtype();

550

public Charset getCharset();

551

public Map<String, String> getParameters();

552

public String getParameter(String name);

553

554

public boolean isWildcardType();

555

public boolean isWildcardSubtype();

556

public boolean isConcrete();

557

558

public boolean includes(MimeType other);

559

public boolean isCompatibleWith(MimeType other);

560

public boolean equalsTypeAndSubtype(MimeType other);

561

public boolean isPresentIn(Collection<? extends MimeType> mimeTypes);

562

563

@Override

564

public int compareTo(MimeType other);

565

566

public static MimeType valueOf(String value);

567

}

568

```

569

570

**MimeTypeUtils Class**

571

```java { .api }

572

public abstract class MimeTypeUtils {

573

public static final MimeType ALL;

574

public static final String ALL_VALUE = "*/*";

575

public static final MimeType APPLICATION_JSON;

576

public static final String APPLICATION_JSON_VALUE = "application/json";

577

public static final MimeType APPLICATION_OCTET_STREAM;

578

public static final String APPLICATION_OCTET_STREAM_VALUE = "application/octet-stream";

579

public static final MimeType APPLICATION_XML;

580

public static final String APPLICATION_XML_VALUE = "application/xml";

581

public static final MimeType IMAGE_GIF;

582

public static final String IMAGE_GIF_VALUE = "image/gif";

583

public static final MimeType IMAGE_JPEG;

584

public static final String IMAGE_JPEG_VALUE = "image/jpeg";

585

public static final MimeType IMAGE_PNG;

586

public static final String IMAGE_PNG_VALUE = "image/png";

587

public static final MimeType TEXT_HTML;

588

public static final String TEXT_HTML_VALUE = "text/html";

589

public static final MimeType TEXT_PLAIN;

590

public static final String TEXT_PLAIN_VALUE = "text/plain";

591

public static final MimeType TEXT_XML;

592

public static final String TEXT_XML_VALUE = "text/xml";

593

594

public static MimeType parseMimeType(String mimeType);

595

public static List<MimeType> parseMimeTypes(String mimeTypes);

596

public static List<MimeType> parseMimeTypes(List<String> mimeTypes);

597

public static String toString(Collection<? extends MimeType> mimeTypes);

598

599

public static void sortBySpecificity(List<MimeType> mimeTypes);

600

}

601

```

602

603

**Usage Examples**

604

```java

605

// Create MIME types

606

MimeType jsonType = new MimeType("application", "json");

607

MimeType xmlType = new MimeType("application", "xml", StandardCharsets.UTF_8);

608

MimeType htmlType = MimeType.valueOf("text/html;charset=UTF-8");

609

610

// Use predefined constants

611

MimeType appJson = MimeTypeUtils.APPLICATION_JSON;

612

MimeType textPlain = MimeTypeUtils.TEXT_PLAIN;

613

614

// Parse MIME types

615

MimeType parsed = MimeTypeUtils.parseMimeType("application/json;charset=UTF-8");

616

List<MimeType> accepts = MimeTypeUtils.parseMimeTypes("text/html,application/xml;q=0.9,*/*;q=0.8");

617

618

// Type checking

619

boolean isJson = parsed.equalsTypeAndSubtype(MimeTypeUtils.APPLICATION_JSON); // true

620

boolean isWildcard = MimeTypeUtils.ALL.isWildcardType(); // true

621

boolean isConcrete = jsonType.isConcrete(); // true

622

623

// Compatibility checking

624

boolean includes = MimeTypeUtils.ALL.includes(jsonType); // true

625

boolean compatible = jsonType.isCompatibleWith(MimeTypeUtils.APPLICATION_JSON); // true

626

627

// Parameter access

628

Charset charset = htmlType.getCharset(); // UTF-8

629

String boundaryParam = parsed.getParameter("boundary");

630

631

// Sorting by specificity

632

List<MimeType> mimeTypes = Arrays.asList(

633

MimeTypeUtils.ALL,

634

MimeTypeUtils.APPLICATION_JSON,

635

MimeType.valueOf("application/*")

636

);

637

MimeTypeUtils.sortBySpecificity(mimeTypes);

638

// Result: [APPLICATION_JSON, application/*, */*] (most specific first)

639

640

// Collection operations

641

Collection<MimeType> supportedTypes = Arrays.asList(

642

MimeTypeUtils.APPLICATION_JSON,

643

MimeTypeUtils.APPLICATION_XML,

644

MimeTypeUtils.TEXT_HTML

645

);

646

boolean isSupported = jsonType.isPresentIn(supportedTypes); // true

647

```

648

649

## Bundled Third-Party Libraries

650

651

Spring Core includes several repackaged third-party libraries for internal use.

652

653

**ASM Bytecode Manipulation (org.springframework.asm)**

654

```java

655

// Available packages:

656

// org.springframework.asm - Core ASM functionality

657

// org.springframework.asm.commons - Common ASM utilities

658

// org.springframework.asm.signature - Signature parsing

659

// org.springframework.asm.tree - Tree API for bytecode manipulation

660

// org.springframework.asm.util - Debugging and analysis utilities

661

662

// Note: These are repackaged for Spring's internal use

663

// For application use, depend on ASM directly

664

```

665

666

**CGLib Proxy Creation (org.springframework.cglib)**

667

```java

668

// Available packages:

669

// org.springframework.cglib.core - Core CGLib functionality

670

// org.springframework.cglib.proxy - Proxy creation and enhancement

671

// org.springframework.cglib.beans - Bean utilities and property access

672

// org.springframework.cglib.reflect - Fast reflection utilities

673

// org.springframework.cglib.transform - Bytecode transformation

674

675

// Note: These are repackaged for Spring's internal use

676

// For application use, depend on CGLib directly

677

```

678

679

**JavaPoet Code Generation (org.springframework.javapoet)**

680

```java

681

// Available for AOT code generation:

682

// org.springframework.javapoet.ClassName

683

// org.springframework.javapoet.CodeBlock

684

// org.springframework.javapoet.FieldSpec

685

// org.springframework.javapoet.JavaFile

686

// org.springframework.javapoet.MethodSpec

687

// org.springframework.javapoet.TypeSpec

688

689

// Note: This is bundled for Spring's AOT compilation support

690

```

691

692

**Objenesis Object Instantiation (org.springframework.objenesis)**

693

```java

694

// Available classes:

695

// org.springframework.objenesis.SpringObjenesis - Spring-configured Objenesis

696

// org.springframework.objenesis.ObjenesisException - Exception handling

697

698

// Note: This is bundled for Spring's proxy creation needs

699

```

700

701

**Usage Notes**

702

- These bundled libraries are repackaged under `org.springframework.*` namespaces

703

- They are intended for Spring Framework's internal use

704

- Applications should depend on the original libraries directly if needed

705

- Spring uses these for proxy creation, bytecode generation, and AOT compilation

706

- The bundled versions are tested and guaranteed to work with the specific Spring version

707

708

This comprehensive utility library provides essential tools that power Spring's internal operations while also offering valuable utilities for application developers to handle common programming tasks efficiently and safely.