Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/src/share/classes/java/nio/file/FileSystemException.java
38918 views
/*1* Copyright (c) 2007, 2009, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation. Oracle designates this7* particular file as subject to the "Classpath" exception as provided8* by Oracle in the LICENSE file that accompanied this code.9*10* This code is distributed in the hope that it will be useful, but WITHOUT11* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or12* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License13* version 2 for more details (a copy is included in the LICENSE file that14* accompanied this code).15*16* You should have received a copy of the GNU General Public License version17* 2 along with this work; if not, write to the Free Software Foundation,18* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.19*20* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA21* or visit www.oracle.com if you need additional information or have any22* questions.23*/2425package java.nio.file;2627import java.io.IOException;2829/**30* Thrown when a file system operation fails on one or two files. This class is31* the general class for file system exceptions.32*33* @since 1.734*/3536public class FileSystemException37extends IOException38{39static final long serialVersionUID = -3055425747967319812L;4041private final String file;42private final String other;4344/**45* Constructs an instance of this class. This constructor should be used46* when an operation involving one file fails and there isn't any additional47* information to explain the reason.48*49* @param file50* a string identifying the file or {@code null} if not known.51*/52public FileSystemException(String file) {53super((String)null);54this.file = file;55this.other = null;56}5758/**59* Constructs an instance of this class. This constructor should be used60* when an operation involving two files fails, or there is additional61* information to explain the reason.62*63* @param file64* a string identifying the file or {@code null} if not known.65* @param other66* a string identifying the other file or {@code null} if there67* isn't another file or if not known68* @param reason69* a reason message with additional information or {@code null}70*/71public FileSystemException(String file, String other, String reason) {72super(reason);73this.file = file;74this.other = other;75}7677/**78* Returns the file used to create this exception.79*80* @return the file (can be {@code null})81*/82public String getFile() {83return file;84}8586/**87* Returns the other file used to create this exception.88*89* @return the other file (can be {@code null})90*/91public String getOtherFile() {92return other;93}9495/**96* Returns the string explaining why the file system operation failed.97*98* @return the string explaining why the file system operation failed99*/100public String getReason() {101return super.getMessage();102}103104/**105* Returns the detail message string.106*/107@Override108public String getMessage() {109if (file == null && other == null)110return getReason();111StringBuilder sb = new StringBuilder();112if (file != null)113sb.append(file);114if (other != null) {115sb.append(" -> ");116sb.append(other);117}118if (getReason() != null) {119sb.append(": ");120sb.append(getReason());121}122return sb.toString();123}124}125126127