这是indexloc提供的服务,不要输入任何密码
Skip to content
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import java.io.File;
import java.nio.file.Paths;
import java.util.Locale;

import lombok.extern.slf4j.Slf4j;

Expand Down Expand Up @@ -59,7 +60,7 @@ public class InstallationPathConfig {

private static String initializeBasePath() {
if (Boolean.parseBoolean(System.getProperty("STIRLING_PDF_DESKTOP_UI", "false"))) {
String os = System.getProperty("os.name").toLowerCase();
String os = System.getProperty("os.name").toLowerCase(Locale.ROOT);
if (os.contains("win")) {
return Paths.get(
System.getenv("APPDATA"), // parent path
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import java.util.Arrays;
import java.util.Collection;
import java.util.List;
import java.util.Locale;

import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Bean;
Expand Down Expand Up @@ -286,7 +287,7 @@ public static class Client {
private KeycloakProvider keycloak = new KeycloakProvider();

public Provider get(String registrationId) throws UnsupportedProviderException {
return switch (registrationId.toLowerCase()) {
return switch (registrationId.toLowerCase(Locale.ROOT)) {
case "google" -> getGoogle();
case "github" -> getGithub();
case "keycloak" -> getKeycloak();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,11 @@ public Path getFilePathAsPath() {
// Formats the file size into a human-readable string.
public String getFormattedFileSize() {
if (fileSize >= 1024 * 1024 * 1024) {
return String.format(Locale.US, "%.2f GB", fileSize / (1024.0 * 1024 * 1024));
return String.format(Locale.ROOT, "%.2f GB", fileSize / (1024.0 * 1024 * 1024));
} else if (fileSize >= 1024 * 1024) {
return String.format(Locale.US, "%.2f MB", fileSize / (1024.0 * 1024));
return String.format(Locale.ROOT, "%.2f MB", fileSize / (1024.0 * 1024));
} else if (fileSize >= 1024) {
return String.format(Locale.US, "%.2f KB", fileSize / 1024.0);
return String.format(Locale.ROOT, "%.2f KB", fileSize / 1024.0);
} else {
return String.format("%d Bytes", fileSize);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.StandardCopyOption;
import java.util.Locale;
import java.util.concurrent.atomic.AtomicLong;

import org.apache.pdfbox.Loader;
Expand Down Expand Up @@ -249,7 +250,7 @@ public StreamCacheCreateFunction getStreamCacheFunction(long contentSize) {
log.debug(
"Memory status - Free: {}MB ({}%), Used: {}MB, Max: {}MB",
actualFreeMemory / (1024 * 1024),
String.format("%.2f", freeMemoryPercent),
String.format(Locale.ROOT, "%.2f", freeMemoryPercent),
usedMemory / (1024 * 1024),
maxMemory / (1024 * 1024));

Expand All @@ -258,7 +259,7 @@ public StreamCacheCreateFunction getStreamCacheFunction(long contentSize) {
|| actualFreeMemory < MIN_FREE_MEMORY_BYTES) {
log.debug(
"Low memory detected ({}%), forcing file-based cache",
String.format("%.2f", freeMemoryPercent));
String.format(Locale.ROOT, "%.2f", freeMemoryPercent));
return createScratchFileCacheFunction(MemoryUsageSetting.setupTempFileOnly());
} else if (contentSize < SMALL_FILE_THRESHOLD) {
log.debug("Using memory-only cache for small document ({}KB)", contentSize / 1024);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package stirling.software.common.service;

import java.io.IOException;
import java.util.Locale;
import java.util.Map;
import java.util.UUID;
import java.util.concurrent.CompletableFuture;
Expand Down Expand Up @@ -440,7 +441,7 @@ private long parseSessionTimeout(String timeout) {

double numericValue = Double.parseDouble(value);

return switch (unit.toLowerCase()) {
return switch (unit.toLowerCase(Locale.ROOT)) {
case "s" -> (long) (numericValue * 1000);
case "m" -> (long) (numericValue * 60 * 1000);
case "h" -> (long) (numericValue * 60 * 60 * 1000);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -397,7 +397,7 @@ private String getMacAddress() {
if (hardwareAddress != null) {
String[] hexadecimal = new String[hardwareAddress.length];
for (int i = 0; i < hardwareAddress.length; i++) {
hexadecimal[i] = String.format("%02X", hardwareAddress[i]);
hexadecimal[i] = String.format(Locale.ROOT, "%02X", hardwareAddress[i]);
}
return String.join("-", hexadecimal);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import java.lang.management.OperatingSystemMXBean;
import java.time.Duration;
import java.time.Instant;
import java.util.Locale;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;
Expand Down Expand Up @@ -173,8 +174,8 @@ private void updateResourceMetrics() {
log.info("System resource status changed from {} to {}", oldStatus, newStatus);
log.info(
"Current metrics - CPU: {}%, Memory: {}%, Free Memory: {} MB",
String.format("%.1f", cpuUsage * 100),
String.format("%.1f", memoryUsage * 100),
String.format(Locale.ROOT, "%.1f", cpuUsage * 100),
String.format(Locale.ROOT, "%.1f", memoryUsage * 100),
freeMemory / (1024 * 1024));
}
} catch (Exception e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import java.net.InetAddress;
import java.net.URI;
import java.net.UnknownHostException;
import java.util.Locale;
import java.util.regex.Pattern;

import org.springframework.stereotype.Service;
Expand Down Expand Up @@ -83,7 +84,7 @@ private boolean isMaxSecurityAllowed(
return false;
}

return config.getAllowedDomains().contains(host.toLowerCase());
return config.getAllowedDomains().contains(host.toLowerCase(Locale.ROOT));

} catch (Exception e) {
log.debug("Failed to parse URL for MAX security check: {}", url, e);
Expand All @@ -101,7 +102,7 @@ private boolean isMediumSecurityAllowed(
return false;
}

String hostLower = host.toLowerCase();
String hostLower = host.toLowerCase(Locale.ROOT);

// Check explicit blocked domains
if (config.getBlockedDomains().contains(hostLower)) {
Expand All @@ -111,7 +112,7 @@ private boolean isMediumSecurityAllowed(

// Check internal TLD patterns
for (String tld : config.getInternalTlds()) {
if (hostLower.endsWith(tld.toLowerCase())) {
if (hostLower.endsWith(tld.toLowerCase(Locale.ROOT))) {
log.debug("URL blocked by internal TLD pattern '{}': {}", tld, url);
return false;
}
Expand All @@ -123,9 +124,11 @@ private boolean isMediumSecurityAllowed(
config.getAllowedDomains().stream()
.anyMatch(
domain ->
hostLower.equals(domain.toLowerCase())
hostLower.equals(domain.toLowerCase(Locale.ROOT))
|| hostLower.endsWith(
"." + domain.toLowerCase()));
"."
+ domain.toLowerCase(
Locale.ROOT)));

if (!isAllowed) {
log.debug("URL not in allowed domains list: {}", url);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import java.time.temporal.ChronoUnit;
import java.util.ArrayList;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.Executors;
Expand Down Expand Up @@ -101,14 +102,16 @@ public void setFileResult(
if (!extractedFiles.isEmpty()) {
jobResult.completeWithFiles(extractedFiles);
log.debug(
"Set multiple file results for job ID: {} with {} files extracted from ZIP",
"Set multiple file results for job ID: {} with {} files extracted from"
+ " ZIP",
jobId,
extractedFiles.size());
return;
}
} catch (Exception e) {
log.warn(
"Failed to extract ZIP file for job {}: {}. Falling back to single file result.",
"Failed to extract ZIP file for job {}: {}. Falling back to single file"
+ " result.",
jobId,
e.getMessage());
}
Expand Down Expand Up @@ -342,12 +345,12 @@ public void shutdown() {
/** Check if a file is a ZIP file based on content type and filename */
private boolean isZipFile(String contentType, String fileName) {
if (contentType != null
&& (contentType.equals("application/zip")
|| contentType.equals("application/x-zip-compressed"))) {
&& ("application/zip".equals(contentType)
|| "application/x-zip-compressed".equals(contentType))) {
return true;
}

if (fileName != null && fileName.toLowerCase().endsWith(".zip")) {
if (fileName != null && fileName.toLowerCase(Locale.ROOT).endsWith(".zip")) {
return true;
}

Expand Down Expand Up @@ -414,7 +417,7 @@ private String determineContentType(String fileName) {
return MediaType.APPLICATION_OCTET_STREAM_VALUE;
}

String lowerName = fileName.toLowerCase();
String lowerName = fileName.toLowerCase(Locale.ROOT);
if (lowerName.endsWith(".pdf")) {
return MediaType.APPLICATION_PDF_VALUE;
} else if (lowerName.endsWith(".txt")) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import java.util.ArrayList;
import java.util.Comparator;
import java.util.List;
import java.util.Locale;

import org.apache.commons.io.FilenameUtils;
import org.apache.pdfbox.pdmodel.PDDocument;
Expand Down Expand Up @@ -60,10 +61,9 @@ public byte[] convertCbrToPdf(
e.getMessage());
throw ExceptionUtils.createIllegalArgumentException(
"error.invalidFormat",
"Invalid or corrupted CBR/RAR archive. "
+ "The file may be corrupted, use an unsupported RAR format (RAR5+), "
+ "or may not be a valid RAR archive. "
+ "Please ensure the file is a valid RAR archive.");
"Invalid or corrupted CBR/RAR archive. The file may be corrupted, use"
+ " an unsupported RAR format (RAR5+), or may not be a valid RAR"
+ " archive. Please ensure the file is a valid RAR archive.");
} catch (RarException e) {
log.warn("Failed to open CBR/RAR archive: {}", e.getMessage());
String errorMessage;
Expand All @@ -73,13 +73,14 @@ public byte[] convertCbrToPdf(
errorMessage = "Encrypted CBR/RAR archives are not supported.";
} else if (exMessage.isEmpty()) {
errorMessage =
"Invalid CBR/RAR archive. "
+ "The file may be encrypted, corrupted, or use an unsupported format.";
"Invalid CBR/RAR archive. The file may be encrypted, corrupted, or"
+ " use an unsupported format.";
} else {
errorMessage =
"Invalid CBR/RAR archive: "
+ exMessage
+ ". The file may be encrypted, corrupted, or use an unsupported format.";
+ ". The file may be encrypted, corrupted, or use an"
+ " unsupported format.";
}
throw ExceptionUtils.createIllegalArgumentException(
"error.invalidFormat", errorMessage);
Expand Down Expand Up @@ -121,7 +122,8 @@ public byte[] convertCbrToPdf(
if (imageEntries.isEmpty()) {
throw ExceptionUtils.createIllegalArgumentException(
"error.fileProcessing",
"No valid images found in the CBR file. The archive may be empty or contain no supported image formats.");
"No valid images found in the CBR file. The archive may be empty or"
+ " contain no supported image formats.");
}

for (ImageEntryData imageEntry : imageEntries) {
Expand All @@ -146,7 +148,8 @@ public byte[] convertCbrToPdf(
if (document.getNumberOfPages() == 0) {
throw ExceptionUtils.createIllegalArgumentException(
"error.fileProcessing",
"No images could be processed from the CBR file. All images may be corrupted or in unsupported formats.");
"No images could be processed from the CBR file. All images may be"
+ " corrupted or in unsupported formats.");
}

ByteArrayOutputStream baos = new ByteArrayOutputStream();
Expand All @@ -159,7 +162,6 @@ public byte[] convertCbrToPdf(
return GeneralUtils.optimizePdfWithGhostscript(pdfBytes);
} catch (IOException e) {
log.warn("Ghostscript optimization failed, returning unoptimized PDF", e);
return pdfBytes;
}
}

Expand All @@ -178,7 +180,7 @@ private void validateCbrFile(MultipartFile file) {
throw new IllegalArgumentException("File must have a name");
}

String extension = FilenameUtils.getExtension(filename).toLowerCase();
String extension = FilenameUtils.getExtension(filename).toLowerCase(Locale.ROOT);
if (!"cbr".equals(extension) && !"rar".equals(extension)) {
throw new IllegalArgumentException("File must be a CBR or RAR archive");
}
Expand All @@ -190,7 +192,7 @@ public boolean isCbrFile(MultipartFile file) {
return false;
}

String extension = FilenameUtils.getExtension(filename).toLowerCase();
String extension = FilenameUtils.getExtension(filename).toLowerCase(Locale.ROOT);
return "cbr".equals(extension) || "rar".equals(extension);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import java.util.Comparator;
import java.util.Enumeration;
import java.util.List;
import java.util.Locale;
import java.util.zip.ZipEntry;
import java.util.zip.ZipFile;
import java.util.zip.ZipInputStream;
Expand Down Expand Up @@ -119,7 +120,6 @@ public byte[] convertCbzToPdf(
return GeneralUtils.optimizePdfWithGhostscript(pdfBytes);
} catch (IOException e) {
log.warn("Ghostscript optimization failed, returning unoptimized PDF", e);
return pdfBytes;
}
}

Expand All @@ -138,7 +138,7 @@ private void validateCbzFile(MultipartFile file) {
throw new IllegalArgumentException("File must have a name");
}

String extension = FilenameUtils.getExtension(filename).toLowerCase();
String extension = FilenameUtils.getExtension(filename).toLowerCase(Locale.ROOT);
if (!"cbz".equals(extension) && !"zip".equals(extension)) {
throw new IllegalArgumentException("File must be a CBZ or ZIP archive");
}
Expand All @@ -150,7 +150,7 @@ public boolean isCbzFile(MultipartFile file) {
return false;
}

String extension = FilenameUtils.getExtension(filename).toLowerCase();
String extension = FilenameUtils.getExtension(filename).toLowerCase(Locale.ROOT);
return "cbz".equals(extension) || "zip".equals(extension);
}

Expand All @@ -160,7 +160,7 @@ public static boolean isComicBookFile(MultipartFile file) {
return false;
}

String extension = FilenameUtils.getExtension(filename).toLowerCase();
String extension = FilenameUtils.getExtension(filename).toLowerCase(Locale.ROOT);
return "cbz".equals(extension)
|| "zip".equals(extension)
|| "cbr".equals(extension)
Expand Down
Loading
Loading