1
2
3
4
5
6
7
8
9
10
11 package org.eclipse.jgit.patch;
12
13 import static java.nio.charset.StandardCharsets.UTF_8;
14
15 import java.util.Locale;
16
17 import org.eclipse.jgit.util.RawParseUtils;
18
19
20
21
22 public class FormatError {
23
24 public enum Severity {
25
26 WARNING,
27
28
29 ERROR;
30 }
31
32 private final byte[] buf;
33
34 private final int offset;
35
36 private final Severity severity;
37
38 private final String message;
39
40 FormatError(final byte[] buffer, final int ptr, final Severity sev,
41 final String msg) {
42 buf = buffer;
43 offset = ptr;
44 severity = sev;
45 message = msg;
46 }
47
48
49
50
51
52
53 public Severity getSeverity() {
54 return severity;
55 }
56
57
58
59
60
61
62 public String getMessage() {
63 return message;
64 }
65
66
67
68
69
70
71 public byte[] getBuffer() {
72 return buf;
73 }
74
75
76
77
78
79
80 public int getOffset() {
81 return offset;
82 }
83
84
85
86
87
88
89 public String getLineText() {
90 final int eol = RawParseUtils.nextLF(buf, offset);
91 return RawParseUtils.decode(UTF_8, buf, offset, eol);
92 }
93
94
95 @Override
96 public String toString() {
97 final StringBuilder r = new StringBuilder();
98 r.append(getSeverity().name().toLowerCase(Locale.ROOT));
99 r.append(": at offset ");
100 r.append(getOffset());
101 r.append(": ");
102 r.append(getMessage());
103 r.append("\n");
104 r.append(" in ");
105 r.append(getLineText());
106 return r.toString();
107 }
108 }