1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.apache.commons.compress;
20
21 import java.io.IOException;
22
23
24
25
26
27
28
29 public class MemoryLimitException extends IOException {
30
31 private static final long serialVersionUID = 1L;
32
33 private static String buildMessage(final long memoryNeededInKb, final int memoryLimitInKb) {
34 return memoryNeededInKb + " kb of memory would be needed; limit was " + memoryLimitInKb + " kb. "
35 + "If the file is not corrupt, consider increasing the memory limit.";
36 }
37
38
39 private final long memoryNeededInKb;
40
41 private final int memoryLimitInKb;
42
43 public MemoryLimitException(final long memoryNeededInKb, final int memoryLimitInKb) {
44 super(buildMessage(memoryNeededInKb, memoryLimitInKb));
45 this.memoryNeededInKb = memoryNeededInKb;
46 this.memoryLimitInKb = memoryLimitInKb;
47 }
48
49 public MemoryLimitException(final long memoryNeededInKb, final int memoryLimitInKb, final Exception e) {
50 super(buildMessage(memoryNeededInKb, memoryLimitInKb), e);
51 this.memoryNeededInKb = memoryNeededInKb;
52 this.memoryLimitInKb = memoryLimitInKb;
53 }
54
55 public int getMemoryLimitInKb() {
56 return memoryLimitInKb;
57 }
58
59 public long getMemoryNeededInKb() {
60 return memoryNeededInKb;
61 }
62 }