init overlay and auto split

This commit is contained in:
Anthony Stirling
2023-12-11 23:20:31 +00:00
parent b6671939e5
commit 1d3e018a56
12 changed files with 529 additions and 4 deletions

View File

@@ -1,6 +1,8 @@
package stirling.software.SPDF.utils;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.net.MalformedURLException;
import java.net.URL;
import java.nio.file.FileVisitResult;
@@ -12,6 +14,8 @@ import java.nio.file.attribute.BasicFileAttributes;
import java.util.ArrayList;
import java.util.List;
import org.springframework.web.multipart.MultipartFile;
import java.io.FileOutputStream;
public class GeneralUtils {
public static void deleteDirectory(Path path) throws IOException {
@@ -48,6 +52,18 @@ public class GeneralUtils {
}
}
public static File multipartToFile(MultipartFile multipart) throws IOException {
Path tempFile = Files.createTempFile("overlay-", ".pdf");
try (InputStream in = multipart.getInputStream();
FileOutputStream out = new FileOutputStream(tempFile.toFile())) {
byte[] buffer = new byte[1024];
int bytesRead;
while ((bytesRead = in.read(buffer)) != -1) {
out.write(buffer, 0, bytesRead);
}
}
return tempFile.toFile();
}
public static Long convertSizeToBytes(String sizeStr) {
if (sizeStr == null) {