Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/src/java.base/share/classes/java/nio/file/InvalidPathException.java
41159 views
1
/*
2
* Copyright (c) 2007, 2021, Oracle and/or its affiliates. All rights reserved.
3
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4
*
5
* This code is free software; you can redistribute it and/or modify it
6
* under the terms of the GNU General Public License version 2 only, as
7
* published by the Free Software Foundation. Oracle designates this
8
* particular file as subject to the "Classpath" exception as provided
9
* by Oracle in the LICENSE file that accompanied this code.
10
*
11
* This code is distributed in the hope that it will be useful, but WITHOUT
12
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14
* version 2 for more details (a copy is included in the LICENSE file that
15
* accompanied this code).
16
*
17
* You should have received a copy of the GNU General Public License version
18
* 2 along with this work; if not, write to the Free Software Foundation,
19
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20
*
21
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22
* or visit www.oracle.com if you need additional information or have any
23
* questions.
24
*/
25
26
package java.nio.file;
27
28
/**
29
* Unchecked exception thrown when path string cannot be converted into a
30
* {@link Path} because the path string contains invalid characters, or
31
* the path string is invalid for other file system specific reasons.
32
*
33
* @since 1.7
34
*/
35
36
public class InvalidPathException
37
extends IllegalArgumentException
38
{
39
@java.io.Serial
40
static final long serialVersionUID = 4355821422286746137L;
41
42
/**
43
* The input string.
44
*/
45
private String input;
46
47
/**
48
* The index of the input string at which the error occurred or
49
* {@code -1} if not known.
50
*/
51
private int index;
52
53
/**
54
* Constructs an instance from the given input string, reason, and error
55
* index.
56
*
57
* @param input the input string
58
* @param reason a string explaining why the input was rejected
59
* @param index the index at which the error occurred,
60
* or {@code -1} if the index is not known
61
*
62
* @throws NullPointerException
63
* if either the input or reason strings are {@code null}
64
*
65
* @throws IllegalArgumentException
66
* if the error index is less than {@code -1}
67
*/
68
public InvalidPathException(String input, String reason, int index) {
69
super(reason);
70
if ((input == null) || (reason == null))
71
throw new NullPointerException();
72
if (index < -1)
73
throw new IllegalArgumentException();
74
this.input = input;
75
this.index = index;
76
}
77
78
/**
79
* Constructs an instance from the given input string and reason. The
80
* resulting object will have an error index of {@code -1}.
81
*
82
* @param input the input string
83
* @param reason a string explaining why the input was rejected
84
*
85
* @throws NullPointerException
86
* if either the input or reason strings are {@code null}
87
*/
88
public InvalidPathException(String input, String reason) {
89
this(input, reason, -1);
90
}
91
92
/**
93
* Returns the input string.
94
*
95
* @return the input string
96
*/
97
public String getInput() {
98
return input;
99
}
100
101
/**
102
* Returns a string explaining why the input string was rejected.
103
*
104
* @return the reason string
105
*/
106
public String getReason() {
107
return super.getMessage();
108
}
109
110
/**
111
* Returns an index into the input string of the position at which the
112
* error occurred, or {@code -1} if this position is not known.
113
*
114
* @return the error index
115
*/
116
public int getIndex() {
117
return index;
118
}
119
120
/**
121
* Returns a string describing the error. The resulting string
122
* consists of the reason string followed by a colon character
123
* ({@code ':'}), a space, and the input string. If the error index is
124
* defined then the string {@code " at index "} followed by the index, in
125
* decimal, is inserted after the reason string and before the colon
126
* character.
127
*
128
* @return a string describing the error
129
*/
130
public String getMessage() {
131
StringBuilder sb = new StringBuilder();
132
sb.append(getReason());
133
if (index > -1) {
134
sb.append(" at index ");
135
sb.append(index);
136
}
137
sb.append(": ");
138
sb.append(input);
139
return sb.toString();
140
}
141
}
142
143