| 1 | // SPDX-License-Identifier: 0BSD |
| 2 | // SPDX-FileCopyrightText: The XZ for Java authors and contributors |
| 3 | // SPDX-FileContributor: Lasse Collin <[email protected]> |
| 4 | |
| 5 | package org.tukaani.xz; |
| 6 | |
| 7 | /** |
| 8 | * Thrown when the memory usage limit given to the XZ decompressor |
| 9 | * would be exceeded. |
| 10 | * <p> |
| 11 | * The amount of memory required and the memory usage limit are |
| 12 | * included in the error detail message in human readable format. |
| 13 | */ |
| 14 | public class MemoryLimitException extends XZIOException { |
| 15 | private static final long serialVersionUID = 3L; |
| 16 | |
| 17 | private final int memoryNeeded; |
| 18 | private final int memoryLimit; |
| 19 | |
| 20 | /** |
| 21 | * Creates a new MemoryLimitException. |
| 22 | * <p> |
| 23 | * The amount of memory needed and the memory usage limit are |
| 24 | * included in the error detail message. |
| 25 | * |
| 26 | * @param memoryNeeded amount of memory needed as kibibytes (KiB) |
| 27 | * @param memoryLimit specified memory usage limit as kibibytes (KiB) |
| 28 | */ |
| 29 | public MemoryLimitException(int memoryNeeded, int memoryLimit) { |
| 30 | super("" + memoryNeeded + " KiB of memory would be needed; limit was " |
| 31 | + memoryLimit + " KiB"); |
| 32 | |
| 33 | this.memoryNeeded = memoryNeeded; |
| 34 | this.memoryLimit = memoryLimit; |
| 35 | } |
| 36 | |
| 37 | /** |
| 38 | * Gets how much memory is required to decompress the data. |
| 39 | * |
| 40 | * @return amount of memory needed as kibibytes (KiB) |
| 41 | */ |
| 42 | public int getMemoryNeeded() { |
| 43 | return memoryNeeded; |
| 44 | } |
| 45 | |
| 46 | /** |
| 47 | * Gets what the memory usage limit was at the time the exception |
| 48 | * was created. |
| 49 | * |
| 50 | * @return memory usage limit as kibibytes (KiB) |
| 51 | */ |
| 52 | public int getMemoryLimit() { |
| 53 | return memoryLimit; |
| 54 | } |
| 55 | } |