Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/src/share/classes/java/nio/file/InvalidPathException.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;2627/**28* Unchecked exception thrown when path string cannot be converted into a29* {@link Path} because the path string contains invalid characters, or30* the path string is invalid for other file system specific reasons.31*/3233public class InvalidPathException34extends IllegalArgumentException35{36static final long serialVersionUID = 4355821422286746137L;3738private String input;39private int index;4041/**42* Constructs an instance from the given input string, reason, and error43* index.44*45* @param input the input string46* @param reason a string explaining why the input was rejected47* @param index the index at which the error occurred,48* or <tt>-1</tt> if the index is not known49*50* @throws NullPointerException51* if either the input or reason strings are <tt>null</tt>52*53* @throws IllegalArgumentException54* if the error index is less than <tt>-1</tt>55*/56public InvalidPathException(String input, String reason, int index) {57super(reason);58if ((input == null) || (reason == null))59throw new NullPointerException();60if (index < -1)61throw new IllegalArgumentException();62this.input = input;63this.index = index;64}6566/**67* Constructs an instance from the given input string and reason. The68* resulting object will have an error index of <tt>-1</tt>.69*70* @param input the input string71* @param reason a string explaining why the input was rejected72*73* @throws NullPointerException74* if either the input or reason strings are <tt>null</tt>75*/76public InvalidPathException(String input, String reason) {77this(input, reason, -1);78}7980/**81* Returns the input string.82*83* @return the input string84*/85public String getInput() {86return input;87}8889/**90* Returns a string explaining why the input string was rejected.91*92* @return the reason string93*/94public String getReason() {95return super.getMessage();96}9798/**99* Returns an index into the input string of the position at which the100* error occurred, or <tt>-1</tt> if this position is not known.101*102* @return the error index103*/104public int getIndex() {105return index;106}107108/**109* Returns a string describing the error. The resulting string110* consists of the reason string followed by a colon character111* (<tt>':'</tt>), a space, and the input string. If the error index is112* defined then the string <tt>" at index "</tt> followed by the index, in113* decimal, is inserted after the reason string and before the colon114* character.115*116* @return a string describing the error117*/118public String getMessage() {119StringBuffer sb = new StringBuffer();120sb.append(getReason());121if (index > -1) {122sb.append(" at index ");123sb.append(index);124}125sb.append(": ");126sb.append(input);127return sb.toString();128}129}130131132