diff --git a/io/src/main/java/org/apache/pdfbox/io/MemoryUsageSetting.java b/io/src/main/java/org/apache/pdfbox/io/MemoryUsageSetting.java index efd717f3cfc..2b41e11ea3c 100644 --- a/io/src/main/java/org/apache/pdfbox/io/MemoryUsageSetting.java +++ b/io/src/main/java/org/apache/pdfbox/io/MemoryUsageSetting.java @@ -85,8 +85,8 @@ private MemoryUsageSetting(boolean useMainMemory, boolean useTempFile, } } - if (locUseMainMemory && (locMaxStorageBytes > -1) && - ((locMaxMainMemoryBytes == -1) || (locMaxMainMemoryBytes > locMaxStorageBytes))) + if (isMainMemoryValidAndStorageSpecified(locUseMainMemory, locMaxStorageBytes) && + isMainMemoryGreaterOrUnlimitedThanStorage(locMaxMainMemoryBytes, locMaxStorageBytes)) { locMaxStorageBytes = locMaxMainMemoryBytes; } @@ -97,7 +97,15 @@ private MemoryUsageSetting(boolean useMainMemory, boolean useTempFile, this.maxMainMemoryBytes = locMaxMainMemoryBytes; this.maxStorageBytes = locMaxStorageBytes; } - + + private boolean isMainMemoryValidAndStorageSpecified(boolean locUseMainMemory, long locMaxStorageBytes) { + return locUseMainMemory && (locMaxStorageBytes > -1); + } + + private boolean isMainMemoryGreaterOrUnlimitedThanStorage(long locMaxMainMemoryBytes, long locMaxStorageBytes) { + return (locMaxMainMemoryBytes == -1) || (locMaxMainMemoryBytes > locMaxStorageBytes); + } + /** * Setups buffering memory usage to only use main-memory (no temporary file) which is not restricted in size. *