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/FileSystemException.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
import java.io.IOException;
29
30
/**
31
* Thrown when a file system operation fails on one or two files. This class is
32
* the general class for file system exceptions.
33
*
34
* @since 1.7
35
*/
36
37
public class FileSystemException
38
extends IOException
39
{
40
@java.io.Serial
41
static final long serialVersionUID = -3055425747967319812L;
42
43
/**
44
* String identifying the file or {@code null} if not known.
45
*/
46
private final String file;
47
48
/**
49
* String identifying the other file or {@code null} if there isn't
50
* another file or if not known.
51
*/
52
private final String other;
53
54
/**
55
* Constructs an instance of this class. This constructor should be used
56
* when an operation involving one file fails and there isn't any additional
57
* information to explain the reason.
58
*
59
* @param file
60
* a string identifying the file or {@code null} if not known.
61
*/
62
public FileSystemException(String file) {
63
super((String)null);
64
this.file = file;
65
this.other = null;
66
}
67
68
/**
69
* Constructs an instance of this class. This constructor should be used
70
* when an operation involving two files fails, or there is additional
71
* information to explain the reason.
72
*
73
* @param file
74
* a string identifying the file or {@code null} if not known.
75
* @param other
76
* a string identifying the other file or {@code null} if there
77
* isn't another file or if not known
78
* @param reason
79
* a reason message with additional information or {@code null}
80
*/
81
public FileSystemException(String file, String other, String reason) {
82
super(reason);
83
this.file = file;
84
this.other = other;
85
}
86
87
/**
88
* Returns the file used to create this exception.
89
*
90
* @return the file (can be {@code null})
91
*/
92
public String getFile() {
93
return file;
94
}
95
96
/**
97
* Returns the other file used to create this exception.
98
*
99
* @return the other file (can be {@code null})
100
*/
101
public String getOtherFile() {
102
return other;
103
}
104
105
/**
106
* Returns the string explaining why the file system operation failed.
107
*
108
* @return the string explaining why the file system operation failed
109
*/
110
public String getReason() {
111
return super.getMessage();
112
}
113
114
/**
115
* Returns the detail message string.
116
*/
117
@Override
118
public String getMessage() {
119
if (file == null && other == null)
120
return getReason();
121
StringBuilder sb = new StringBuilder();
122
if (file != null)
123
sb.append(file);
124
if (other != null) {
125
sb.append(" -> ");
126
sb.append(other);
127
}
128
if (getReason() != null) {
129
sb.append(": ");
130
sb.append(getReason());
131
}
132
return sb.toString();
133
}
134
}
135
136