emul/compact/src/main/java/java/net/URISyntaxException.java
branchjdk7-b147
changeset 1258 724f3e1ea53e
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/emul/compact/src/main/java/java/net/URISyntaxException.java	Sat Sep 07 13:51:24 2013 +0200
     1.3 @@ -0,0 +1,135 @@
     1.4 +/*
     1.5 + * Copyright (c) 2000, 2008, Oracle and/or its affiliates. All rights reserved.
     1.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     1.7 + *
     1.8 + * This code is free software; you can redistribute it and/or modify it
     1.9 + * under the terms of the GNU General Public License version 2 only, as
    1.10 + * published by the Free Software Foundation.  Oracle designates this
    1.11 + * particular file as subject to the "Classpath" exception as provided
    1.12 + * by Oracle in the LICENSE file that accompanied this code.
    1.13 + *
    1.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
    1.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    1.16 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
    1.17 + * version 2 for more details (a copy is included in the LICENSE file that
    1.18 + * accompanied this code).
    1.19 + *
    1.20 + * You should have received a copy of the GNU General Public License version
    1.21 + * 2 along with this work; if not, write to the Free Software Foundation,
    1.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
    1.23 + *
    1.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
    1.25 + * or visit www.oracle.com if you need additional information or have any
    1.26 + * questions.
    1.27 + */
    1.28 +
    1.29 +package java.net;
    1.30 +
    1.31 +
    1.32 +/**
    1.33 + * Checked exception thrown to indicate that a string could not be parsed as a
    1.34 + * URI reference.
    1.35 + *
    1.36 + * @author Mark Reinhold
    1.37 + * @see URI
    1.38 + * @since 1.4
    1.39 + */
    1.40 +
    1.41 +public class URISyntaxException
    1.42 +    extends Exception
    1.43 +{
    1.44 +    private static final long serialVersionUID = 2137979680897488891L;
    1.45 +
    1.46 +    private String input;
    1.47 +    private int index;
    1.48 +
    1.49 +    /**
    1.50 +     * Constructs an instance from the given input string, reason, and error
    1.51 +     * index.
    1.52 +     *
    1.53 +     * @param  input   The input string
    1.54 +     * @param  reason  A string explaining why the input could not be parsed
    1.55 +     * @param  index   The index at which the parse error occurred,
    1.56 +     *                 or <tt>-1</tt> if the index is not known
    1.57 +     *
    1.58 +     * @throws  NullPointerException
    1.59 +     *          If either the input or reason strings are <tt>null</tt>
    1.60 +     *
    1.61 +     * @throws  IllegalArgumentException
    1.62 +     *          If the error index is less than <tt>-1</tt>
    1.63 +     */
    1.64 +    public URISyntaxException(String input, String reason, int index) {
    1.65 +        super(reason);
    1.66 +        if ((input == null) || (reason == null))
    1.67 +            throw new NullPointerException();
    1.68 +        if (index < -1)
    1.69 +            throw new IllegalArgumentException();
    1.70 +        this.input = input;
    1.71 +        this.index = index;
    1.72 +    }
    1.73 +
    1.74 +    /**
    1.75 +     * Constructs an instance from the given input string and reason.  The
    1.76 +     * resulting object will have an error index of <tt>-1</tt>.
    1.77 +     *
    1.78 +     * @param  input   The input string
    1.79 +     * @param  reason  A string explaining why the input could not be parsed
    1.80 +     *
    1.81 +     * @throws  NullPointerException
    1.82 +     *          If either the input or reason strings are <tt>null</tt>
    1.83 +     */
    1.84 +    public URISyntaxException(String input, String reason) {
    1.85 +        this(input, reason, -1);
    1.86 +    }
    1.87 +
    1.88 +    /**
    1.89 +     * Returns the input string.
    1.90 +     *
    1.91 +     * @return  The input string
    1.92 +     */
    1.93 +    public String getInput() {
    1.94 +        return input;
    1.95 +    }
    1.96 +
    1.97 +    /**
    1.98 +     * Returns a string explaining why the input string could not be parsed.
    1.99 +     *
   1.100 +     * @return  The reason string
   1.101 +     */
   1.102 +    public String getReason() {
   1.103 +        return super.getMessage();
   1.104 +    }
   1.105 +
   1.106 +    /**
   1.107 +     * Returns an index into the input string of the position at which the
   1.108 +     * parse error occurred, or <tt>-1</tt> if this position is not known.
   1.109 +     *
   1.110 +     * @return  The error index
   1.111 +     */
   1.112 +    public int getIndex() {
   1.113 +        return index;
   1.114 +    }
   1.115 +
   1.116 +    /**
   1.117 +     * Returns a string describing the parse error.  The resulting string
   1.118 +     * consists of the reason string followed by a colon character
   1.119 +     * (<tt>':'</tt>), a space, and the input string.  If the error index is
   1.120 +     * defined then the string <tt>" at index "</tt> followed by the index, in
   1.121 +     * decimal, is inserted after the reason string and before the colon
   1.122 +     * character.
   1.123 +     *
   1.124 +     * @return  A string describing the parse error
   1.125 +     */
   1.126 +    public String getMessage() {
   1.127 +        StringBuffer sb = new StringBuffer();
   1.128 +        sb.append(getReason());
   1.129 +        if (index > -1) {
   1.130 +            sb.append(" at index ");
   1.131 +            sb.append(index);
   1.132 +        }
   1.133 +        sb.append(": ");
   1.134 +        sb.append(input);
   1.135 +        return sb.toString();
   1.136 +    }
   1.137 +
   1.138 +}