Compare commits

..

1 Commits

Author SHA1 Message Date
stirlingbot[bot]
81d0e2cb5f
📁 pre-commit
Signed-off-by: stirlingbot[bot] <stirlingbot[bot]@users.noreply.github.com>
2025-09-05 18:46:11 +00:00
5 changed files with 27 additions and 38 deletions

View File

@ -124,21 +124,20 @@ public class FileToPdf {
private static void zipDirectory(Path sourceDir, Path zipFilePath) throws IOException {
try (ZipOutputStream zos =
new ZipOutputStream(new FileOutputStream(zipFilePath.toFile()))) {
try (Stream<Path> walk = Files.walk(sourceDir)) {
walk.filter(path -> !Files.isDirectory(path))
.forEach(
path -> {
ZipEntry zipEntry =
new ZipEntry(sourceDir.relativize(path).toString());
try {
zos.putNextEntry(zipEntry);
Files.copy(path, zos);
zos.closeEntry();
} catch (IOException e) {
throw new UncheckedIOException(e);
}
});
}
Files.walk(sourceDir)
.filter(path -> !Files.isDirectory(path))
.forEach(
path -> {
ZipEntry zipEntry =
new ZipEntry(sourceDir.relativize(path).toString());
try {
zos.putNextEntry(zipEntry);
Files.copy(path, zos);
zos.closeEntry();
} catch (IOException e) {
throw new UncheckedIOException(e);
}
});
}
}

View File

@ -9,7 +9,6 @@ import java.nio.file.Files;
import java.nio.file.Path;
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Stream;
import java.util.zip.ZipEntry;
import java.util.zip.ZipOutputStream;
@ -151,11 +150,10 @@ public class ConvertImgPDFController {
.runCommandWithOutputHandling(command);
// Find all WebP files in the output directory
List<Path> webpFiles;
try (Stream<Path> walkStream = Files.walk(tempOutputDir)) {
webpFiles =
walkStream.filter(path -> path.toString().endsWith(".webp")).toList();
}
List<Path> webpFiles =
Files.walk(tempOutputDir)
.filter(path -> path.toString().endsWith(".webp"))
.toList();
if (webpFiles.isEmpty()) {
log.error("No WebP files were created in: {}", tempOutputDir.toString());

View File

@ -48,12 +48,10 @@ public class FilterController {
String text = request.getText();
String pageNumber = request.getPageNumbers();
try (PDDocument pdfDocument = pdfDocumentFactory.load(inputFile)) {
if (PdfUtils.hasText(pdfDocument, pageNumber, text)) {
return WebResponseUtils.pdfDocToWebResponse(
pdfDocument, Filenames.toSimpleFileName(inputFile.getOriginalFilename()));
}
}
PDDocument pdfDocument = pdfDocumentFactory.load(inputFile);
if (PdfUtils.hasText(pdfDocument, pageNumber, text))
return WebResponseUtils.pdfDocToWebResponse(
pdfDocument, Filenames.toSimpleFileName(inputFile.getOriginalFilename()));
return null;
}

View File

@ -8,7 +8,6 @@ import java.nio.file.Path;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.stream.Stream;
import java.util.zip.ZipEntry;
import java.util.zip.ZipOutputStream;
@ -143,10 +142,7 @@ public class ExtractImageScansController {
.runCommandWithOutputHandling(command);
// Read the output photos in temp directory
List<Path> tempOutputFiles;
try (Stream<Path> listStream = Files.list(tempDir)) {
tempOutputFiles = listStream.sorted().toList();
}
List<Path> tempOutputFiles = Files.list(tempDir).sorted().toList();
for (Path tempOutputFile : tempOutputFiles) {
byte[] imageBytes = Files.readAllBytes(tempOutputFile);
processedImageBytes.add(imageBytes);

View File

@ -7,7 +7,6 @@ import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Stream;
import org.springframework.stereotype.Service;
import org.thymeleaf.util.StringUtils;
@ -67,11 +66,10 @@ public class SignatureService {
private List<SignatureFile> getSignaturesFromFolder(Path folder, String category)
throws IOException {
try (Stream<Path> stream = Files.list(folder)) {
return stream.filter(this::isImageFile)
.map(path -> new SignatureFile(path.getFileName().toString(), category))
.toList();
}
return Files.list(folder)
.filter(path -> isImageFile(path))
.map(path -> new SignatureFile(path.getFileName().toString(), category))
.toList();
}
public byte[] getSignatureBytes(String username, String fileName) throws IOException {