From 6978f0a398203b85132162abd12bacecd6205791 Mon Sep 17 00:00:00 2001 From: Sam Brannen <104798+sbrannen@users.noreply.github.com> Date: Sun, 24 Aug 2025 14:02:04 +0200 Subject: [PATCH] Document terms and units in DataSize.parse(...) methods Closes gh-35298 --- .../springframework/util/unit/DataSize.java | 40 ++++++++++++------- 1 file changed, 25 insertions(+), 15 deletions(-) diff --git a/spring-core/src/main/java/org/springframework/util/unit/DataSize.java b/spring-core/src/main/java/org/springframework/util/unit/DataSize.java index 002c5241333..35b85821efe 100644 --- a/spring-core/src/main/java/org/springframework/util/unit/DataSize.java +++ b/spring-core/src/main/java/org/springframework/util/unit/DataSize.java @@ -137,14 +137,19 @@ public final class DataSize implements Comparable, Serializable { } /** - * Obtain a {@link DataSize} from a text string such as {@code 12MB} using + * Obtain a {@link DataSize} from a text string such as {@code "5MB"} using * {@link DataUnit#BYTES} if no unit is specified. - *

Examples: - *

-	 * "12KB" -- parses as "12 kilobytes"
-	 * "5MB"  -- parses as "5 megabytes"
-	 * "20"   -- parses as "20 bytes"
-	 * 
+ *

Examples

+ * + * + * + * + * + * + *
TextParsed AsSize in Bytes
"20"20 bytes20
"20B"20 bytes20
"12KB"12 kilobytes12,288
"5MB"5 megabytes5,242,880
+ *

Note that the terms and units used in the above examples are based on + * binary prefixes. + * Consult the {@linkplain DataSize class-level Javadoc} for details. * @param text the text to parse * @return the parsed {@code DataSize} * @see #parse(CharSequence, DataUnit) @@ -154,19 +159,24 @@ public final class DataSize implements Comparable, Serializable { } /** - * Obtain a {@link DataSize} from a text string such as {@code 12MB} using + * Obtain a {@link DataSize} from a text string such as {@code "5MB"} using * the specified default {@link DataUnit} if no unit is specified. *

The string starts with a number followed optionally by a unit matching * one of the supported {@linkplain DataUnit suffixes}. *

If neither a unit nor a default {@code DataUnit} is specified, * {@link DataUnit#BYTES} will be inferred. - *

Examples: - *

-	 * "12KB" -- parses as "12 kilobytes"
-	 * "5MB"  -- parses as "5 megabytes"
-	 * "20"   -- parses as "20 kilobytes" (where the {@code defaultUnit} is {@link DataUnit#KILOBYTES})
-	 * "20"   -- parses as "20 bytes" (if the {@code defaultUnit} is {@code null})
-	 * 
+ *

Examples

+ * + * + * + * + * + * + * + *
TextDefault UnitParsed AsSize in Bytes
"20"{@code null}20 bytes20
"20"{@link DataUnit#KILOBYTES KILOBYTES}20 kilobytes20,480
"20B"N/A20 bytes20
"12KB"N/A12 kilobytes12,288
"5MB"N/A5 megabytes5,242,880
+ *

Note that the terms and units used in the above examples are based on + * binary prefixes. + * Consult the {@linkplain DataSize class-level Javadoc} for details. * @param text the text to parse * @param defaultUnit the default {@code DataUnit} to use * @return the parsed {@code DataSize}