jaroslav@1258: /* jaroslav@1258: * Copyright (c) 2000, 2008, Oracle and/or its affiliates. All rights reserved. jaroslav@1258: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. jaroslav@1258: * jaroslav@1258: * This code is free software; you can redistribute it and/or modify it jaroslav@1258: * under the terms of the GNU General Public License version 2 only, as jaroslav@1258: * published by the Free Software Foundation. Oracle designates this jaroslav@1258: * particular file as subject to the "Classpath" exception as provided jaroslav@1258: * by Oracle in the LICENSE file that accompanied this code. jaroslav@1258: * jaroslav@1258: * This code is distributed in the hope that it will be useful, but WITHOUT jaroslav@1258: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or jaroslav@1258: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License jaroslav@1258: * version 2 for more details (a copy is included in the LICENSE file that jaroslav@1258: * accompanied this code). jaroslav@1258: * jaroslav@1258: * You should have received a copy of the GNU General Public License version jaroslav@1258: * 2 along with this work; if not, write to the Free Software Foundation, jaroslav@1258: * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. jaroslav@1258: * jaroslav@1258: * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA jaroslav@1258: * or visit www.oracle.com if you need additional information or have any jaroslav@1258: * questions. jaroslav@1258: */ jaroslav@1258: jaroslav@1258: package java.net; jaroslav@1258: jaroslav@1258: jaroslav@1258: /** jaroslav@1258: * Checked exception thrown to indicate that a string could not be parsed as a jaroslav@1258: * URI reference. jaroslav@1258: * jaroslav@1258: * @author Mark Reinhold jaroslav@1258: * @see URI jaroslav@1258: * @since 1.4 jaroslav@1258: */ jaroslav@1258: jaroslav@1258: public class URISyntaxException jaroslav@1258: extends Exception jaroslav@1258: { jaroslav@1258: private static final long serialVersionUID = 2137979680897488891L; jaroslav@1258: jaroslav@1258: private String input; jaroslav@1258: private int index; jaroslav@1258: jaroslav@1258: /** jaroslav@1258: * Constructs an instance from the given input string, reason, and error jaroslav@1258: * index. jaroslav@1258: * jaroslav@1258: * @param input The input string jaroslav@1258: * @param reason A string explaining why the input could not be parsed jaroslav@1258: * @param index The index at which the parse error occurred, jaroslav@1258: * or -1 if the index is not known jaroslav@1258: * jaroslav@1258: * @throws NullPointerException jaroslav@1258: * If either the input or reason strings are null jaroslav@1258: * jaroslav@1258: * @throws IllegalArgumentException jaroslav@1258: * If the error index is less than -1 jaroslav@1258: */ jaroslav@1258: public URISyntaxException(String input, String reason, int index) { jaroslav@1258: super(reason); jaroslav@1258: if ((input == null) || (reason == null)) jaroslav@1258: throw new NullPointerException(); jaroslav@1258: if (index < -1) jaroslav@1258: throw new IllegalArgumentException(); jaroslav@1258: this.input = input; jaroslav@1258: this.index = index; jaroslav@1258: } jaroslav@1258: jaroslav@1258: /** jaroslav@1258: * Constructs an instance from the given input string and reason. The jaroslav@1258: * resulting object will have an error index of -1. jaroslav@1258: * jaroslav@1258: * @param input The input string jaroslav@1258: * @param reason A string explaining why the input could not be parsed jaroslav@1258: * jaroslav@1258: * @throws NullPointerException jaroslav@1258: * If either the input or reason strings are null jaroslav@1258: */ jaroslav@1258: public URISyntaxException(String input, String reason) { jaroslav@1258: this(input, reason, -1); jaroslav@1258: } jaroslav@1258: jaroslav@1258: /** jaroslav@1258: * Returns the input string. jaroslav@1258: * jaroslav@1258: * @return The input string jaroslav@1258: */ jaroslav@1258: public String getInput() { jaroslav@1258: return input; jaroslav@1258: } jaroslav@1258: jaroslav@1258: /** jaroslav@1258: * Returns a string explaining why the input string could not be parsed. jaroslav@1258: * jaroslav@1258: * @return The reason string jaroslav@1258: */ jaroslav@1258: public String getReason() { jaroslav@1258: return super.getMessage(); jaroslav@1258: } jaroslav@1258: jaroslav@1258: /** jaroslav@1258: * Returns an index into the input string of the position at which the jaroslav@1258: * parse error occurred, or -1 if this position is not known. jaroslav@1258: * jaroslav@1258: * @return The error index jaroslav@1258: */ jaroslav@1258: public int getIndex() { jaroslav@1258: return index; jaroslav@1258: } jaroslav@1258: jaroslav@1258: /** jaroslav@1258: * Returns a string describing the parse error. The resulting string jaroslav@1258: * consists of the reason string followed by a colon character jaroslav@1258: * (':'), a space, and the input string. If the error index is jaroslav@1258: * defined then the string " at index " followed by the index, in jaroslav@1258: * decimal, is inserted after the reason string and before the colon jaroslav@1258: * character. jaroslav@1258: * jaroslav@1258: * @return A string describing the parse error jaroslav@1258: */ jaroslav@1258: public String getMessage() { jaroslav@1258: StringBuffer sb = new StringBuffer(); jaroslav@1258: sb.append(getReason()); jaroslav@1258: if (index > -1) { jaroslav@1258: sb.append(" at index "); jaroslav@1258: sb.append(index); jaroslav@1258: } jaroslav@1258: sb.append(": "); jaroslav@1258: sb.append(input); jaroslav@1258: return sb.toString(); jaroslav@1258: } jaroslav@1258: jaroslav@1258: }