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 @@
## 2026-07-02 - String.format in loops
**Learning:** `String.format` is slow for hex conversion inside loops.
**Action:** Replace it with `HexFormat.of().formatHex(bytes)` which is significantly faster and doesn't do intermediate string creations.
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@
@Service
public class ArtifactLinkService {

private static final java.util.HexFormat HEX_FORMAT = java.util.HexFormat.of();

/**
* Query parameter used by PDF.js-compatible artifact URLs.
*/
Expand Down Expand Up @@ -423,11 +425,7 @@ private static String sha256Hex(byte[] bytes) {
try {
MessageDigest digest = MessageDigest.getInstance("SHA-256");
byte[] raw = digest.digest(bytes);
StringBuilder hex = new StringBuilder(raw.length * 2);
for (byte b : raw) {
hex.append(String.format("%02x", b));
}
return hex.toString();
return HEX_FORMAT.formatHex(raw);
} catch (GeneralSecurityException ex) {
throw new IllegalStateException("SHA-256 digest unavailable", ex);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@
@Service
public class DefaultDocumentConversionService implements DocumentConversionService {

private static final java.util.HexFormat HEX_FORMAT = java.util.HexFormat.of();

private final ConversionJobRepository repository;
private final ConversionJobStateStore stateStore;
private final DocumentValidationService validationService;
Expand Down Expand Up @@ -160,12 +162,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 HEX_FORMAT.formatHex(raw);
} catch (NoSuchAlgorithmException ex) {
throw new IllegalStateException("SHA-256 digest unavailable", ex);
} catch (IOException ex) {
Expand Down
Loading