mirror of
https://github.com/Frooodle/Stirling-PDF.git
synced 2025-08-11 13:48:37 +02:00
optimize attachment handling and filename normalization
This commit is contained in:
parent
18cc10eab7
commit
0c82446966
@ -68,7 +68,7 @@ public class PdfAttachmentHandler {
|
|||||||
try (PDDocument document = pdfDocumentFactory.load(pdfBytes);
|
try (PDDocument document = pdfDocumentFactory.load(pdfBytes);
|
||||||
ByteArrayOutputStream outputStream = new ByteArrayOutputStream()) {
|
ByteArrayOutputStream outputStream = new ByteArrayOutputStream()) {
|
||||||
|
|
||||||
List<MultipartFile> multipartAttachments = new ArrayList<>();
|
List<MultipartFile> multipartAttachments = new ArrayList<>(attachments.size());
|
||||||
for (int i = 0; i < attachments.size(); i++) {
|
for (int i = 0; i < attachments.size(); i++) {
|
||||||
EmlParser.EmailAttachment attachment = attachments.get(i);
|
EmlParser.EmailAttachment attachment = attachments.get(i);
|
||||||
if (attachment.getData() != null && attachment.getData().length > 0) {
|
if (attachment.getData() != null && attachment.getData().length > 0) {
|
||||||
@ -469,7 +469,10 @@ public class PdfAttachmentHandler {
|
|||||||
}
|
}
|
||||||
|
|
||||||
String normalizedFilename =
|
String normalizedFilename =
|
||||||
java.text.Normalizer.normalize(filename, java.text.Normalizer.Form.NFC);
|
isAscii(filename)
|
||||||
|
? filename
|
||||||
|
: java.text.Normalizer.normalize(
|
||||||
|
filename, java.text.Normalizer.Form.NFC);
|
||||||
String uniqueFilename =
|
String uniqueFilename =
|
||||||
ensureUniqueFilename(normalizedFilename, existingNames.keySet());
|
ensureUniqueFilename(normalizedFilename, existingNames.keySet());
|
||||||
|
|
||||||
@ -664,4 +667,14 @@ public class PdfAttachmentHandler {
|
|||||||
|
|
||||||
page.getAnnotations().add(fileAnnotation);
|
page.getAnnotations().add(fileAnnotation);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static boolean isAscii(String str) {
|
||||||
|
if (str == null) return true;
|
||||||
|
for (int i = 0; i < str.length(); i++) {
|
||||||
|
if (str.charAt(i) > 127) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user