Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .jules/bolt.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
## 2024-06-30 - Replace String.format with HexFormat for byte-to-hex conversion
**Learning:** Using a loop with `String.format("%02x", b)` to convert byte arrays to hex strings causes unnecessary memory allocations and is a performance bottleneck in this application.
**Action:** Always use `java.util.HexFormat.of().formatHex(bytes)` instead of manual string formatting loops for converting bytes to hex strings to optimize performance and memory usage.
Original file line number Diff line number Diff line change
Expand Up @@ -121,12 +121,7 @@ private String contentHash(MultipartFile file) {
}

byte[] raw = digest.digest();
StringBuilder hex = new StringBuilder(raw.length * 2);
for (byte b : raw) {
hex.append(String.format("%02x", b));
}

return hex.toString();
return java.util.HexFormat.of().formatHex(raw);
} catch (NoSuchAlgorithmException ex) {
throw new IllegalStateException("SHA-256 digest unavailable", ex);
} catch (IOException ex) {
Expand Down
Loading