893N/A/*
2362N/A * Copyright (c) 2007, 2009, Oracle and/or its affiliates. All rights reserved.
893N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
893N/A *
893N/A * This code is free software; you can redistribute it and/or modify it
893N/A * under the terms of the GNU General Public License version 2 only, as
2362N/A * published by the Free Software Foundation. Oracle designates this
893N/A * particular file as subject to the "Classpath" exception as provided
2362N/A * by Oracle in the LICENSE file that accompanied this code.
893N/A *
893N/A * This code is distributed in the hope that it will be useful, but WITHOUT
893N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
893N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
893N/A * version 2 for more details (a copy is included in the LICENSE file that
893N/A * accompanied this code).
893N/A *
893N/A * You should have received a copy of the GNU General Public License version
893N/A * 2 along with this work; if not, write to the Free Software Foundation,
893N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
893N/A *
2362N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
2362N/A * or visit www.oracle.com if you need additional information or have any
2362N/A * questions.
893N/A */
893N/A
893N/Apackage java.nio.file;
893N/A
893N/Aimport java.io.IOException;
893N/A
893N/A/**
893N/A * Thrown when a file system operation fails on one or two files. This class is
893N/A * the general class for file system exceptions.
893N/A *
893N/A * @since 1.7
893N/A */
893N/A
893N/Apublic class FileSystemException
893N/A extends IOException
893N/A{
893N/A static final long serialVersionUID = -3055425747967319812L;
893N/A
893N/A private final String file;
893N/A private final String other;
893N/A
893N/A /**
893N/A * Constructs an instance of this class. This constructor should be used
893N/A * when an operation involving one file fails and there isn't any additional
893N/A * information to explain the reason.
893N/A *
893N/A * @param file
908N/A * a string identifying the file or {@code null} if not known.
893N/A */
893N/A public FileSystemException(String file) {
893N/A super((String)null);
893N/A this.file = file;
893N/A this.other = null;
893N/A }
893N/A
893N/A /**
893N/A * Constructs an instance of this class. This constructor should be used
893N/A * when an operation involving two files fails, or there is additional
893N/A * information to explain the reason.
893N/A *
893N/A * @param file
908N/A * a string identifying the file or {@code null} if not known.
893N/A * @param other
908N/A * a string identifying the other file or {@code null} if there
893N/A * isn't another file or if not known
893N/A * @param reason
908N/A * a reason message with additional information or {@code null}
893N/A */
893N/A public FileSystemException(String file, String other, String reason) {
893N/A super(reason);
893N/A this.file = file;
893N/A this.other = other;
893N/A }
893N/A
893N/A /**
893N/A * Returns the file used to create this exception.
893N/A *
908N/A * @return the file (can be {@code null})
893N/A */
893N/A public String getFile() {
893N/A return file;
893N/A }
893N/A
893N/A /**
893N/A * Returns the other file used to create this exception.
893N/A *
908N/A * @return the other file (can be {@code null})
893N/A */
893N/A public String getOtherFile() {
893N/A return other;
893N/A }
893N/A
893N/A /**
893N/A * Returns the string explaining why the file system operation failed.
893N/A *
908N/A * @return the string explaining why the file system operation failed
893N/A */
893N/A public String getReason() {
893N/A return super.getMessage();
893N/A }
893N/A
893N/A /**
893N/A * Returns the detail message string.
893N/A */
893N/A @Override
893N/A public String getMessage() {
893N/A if (file == null && other == null)
893N/A return getReason();
893N/A StringBuilder sb = new StringBuilder();
893N/A if (file != null)
893N/A sb.append(file);
893N/A if (other != null) {
893N/A sb.append(" -> ");
893N/A sb.append(other);
893N/A }
893N/A if (getReason() != null) {
893N/A sb.append(": ");
893N/A sb.append(getReason());
893N/A }
893N/A return sb.toString();
893N/A }
893N/A}