Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/src/solaris/classes/sun/nio/fs/UnixException.java
32288 views
/*1* Copyright (c) 2008, 2013, 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 sun.nio.fs;2627import java.nio.file.*;28import java.io.IOException;2930/**31* Internal exception thrown by native methods when error detected.32*/3334class UnixException extends Exception {35static final long serialVersionUID = 7227016794320723218L;3637private int errno;38private String msg;3940UnixException(int errno) {41this.errno = errno;42this.msg = null;43}4445UnixException(String msg) {46this.errno = 0;47this.msg = msg;48}4950int errno() {51return errno;52}5354void setError(int errno) {55this.errno = errno;56this.msg = null;57}5859String errorString() {60if (msg != null) {61return msg;62} else {63return Util.toString(UnixNativeDispatcher.strerror(errno()));64}65}6667@Override68public String getMessage() {69return errorString();70}7172/**73* Map well known errors to specific exceptions where possible; otherwise74* return more general FileSystemException.75*/76private IOException translateToIOException(String file, String other) {77// created with message rather than errno78if (msg != null)79return new IOException(msg);8081// handle specific cases82if (errno() == UnixConstants.EACCES)83return new AccessDeniedException(file, other, null);84if (errno() == UnixConstants.ENOENT)85return new NoSuchFileException(file, other, null);86if (errno() == UnixConstants.EEXIST)87return new FileAlreadyExistsException(file, other, null);8889// fallback to the more general exception90return new FileSystemException(file, other, errorString());91}9293void rethrowAsIOException(String file) throws IOException {94IOException x = translateToIOException(file, null);95throw x;96}9798void rethrowAsIOException(UnixPath file, UnixPath other) throws IOException {99String a = (file == null) ? null : file.getPathForExceptionMessage();100String b = (other == null) ? null : other.getPathForExceptionMessage();101IOException x = translateToIOException(a, b);102throw x;103}104105void rethrowAsIOException(UnixPath file) throws IOException {106rethrowAsIOException(file, null);107}108109IOException asIOException(UnixPath file) {110return translateToIOException(file.getPathForExceptionMessage(), null);111}112}113114115