emul/compact/src/main/java/java/net/URISyntaxException.java
author Jaroslav Tulach <jaroslav.tulach@apidesign.org>
Sat, 07 Sep 2013 13:51:24 +0200
branchjdk7-b147
changeset 1258 724f3e1ea53e
permissions -rw-r--r--
Additional set of classes to make porting of lookup library more easier
jaroslav@1258
     1
/*
jaroslav@1258
     2
 * Copyright (c) 2000, 2008, Oracle and/or its affiliates. All rights reserved.
jaroslav@1258
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
jaroslav@1258
     4
 *
jaroslav@1258
     5
 * This code is free software; you can redistribute it and/or modify it
jaroslav@1258
     6
 * under the terms of the GNU General Public License version 2 only, as
jaroslav@1258
     7
 * published by the Free Software Foundation.  Oracle designates this
jaroslav@1258
     8
 * particular file as subject to the "Classpath" exception as provided
jaroslav@1258
     9
 * by Oracle in the LICENSE file that accompanied this code.
jaroslav@1258
    10
 *
jaroslav@1258
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
jaroslav@1258
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
jaroslav@1258
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
jaroslav@1258
    14
 * version 2 for more details (a copy is included in the LICENSE file that
jaroslav@1258
    15
 * accompanied this code).
jaroslav@1258
    16
 *
jaroslav@1258
    17
 * You should have received a copy of the GNU General Public License version
jaroslav@1258
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
jaroslav@1258
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
jaroslav@1258
    20
 *
jaroslav@1258
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
jaroslav@1258
    22
 * or visit www.oracle.com if you need additional information or have any
jaroslav@1258
    23
 * questions.
jaroslav@1258
    24
 */
jaroslav@1258
    25
jaroslav@1258
    26
package java.net;
jaroslav@1258
    27
jaroslav@1258
    28
jaroslav@1258
    29
/**
jaroslav@1258
    30
 * Checked exception thrown to indicate that a string could not be parsed as a
jaroslav@1258
    31
 * URI reference.
jaroslav@1258
    32
 *
jaroslav@1258
    33
 * @author Mark Reinhold
jaroslav@1258
    34
 * @see URI
jaroslav@1258
    35
 * @since 1.4
jaroslav@1258
    36
 */
jaroslav@1258
    37
jaroslav@1258
    38
public class URISyntaxException
jaroslav@1258
    39
    extends Exception
jaroslav@1258
    40
{
jaroslav@1258
    41
    private static final long serialVersionUID = 2137979680897488891L;
jaroslav@1258
    42
jaroslav@1258
    43
    private String input;
jaroslav@1258
    44
    private int index;
jaroslav@1258
    45
jaroslav@1258
    46
    /**
jaroslav@1258
    47
     * Constructs an instance from the given input string, reason, and error
jaroslav@1258
    48
     * index.
jaroslav@1258
    49
     *
jaroslav@1258
    50
     * @param  input   The input string
jaroslav@1258
    51
     * @param  reason  A string explaining why the input could not be parsed
jaroslav@1258
    52
     * @param  index   The index at which the parse error occurred,
jaroslav@1258
    53
     *                 or <tt>-1</tt> if the index is not known
jaroslav@1258
    54
     *
jaroslav@1258
    55
     * @throws  NullPointerException
jaroslav@1258
    56
     *          If either the input or reason strings are <tt>null</tt>
jaroslav@1258
    57
     *
jaroslav@1258
    58
     * @throws  IllegalArgumentException
jaroslav@1258
    59
     *          If the error index is less than <tt>-1</tt>
jaroslav@1258
    60
     */
jaroslav@1258
    61
    public URISyntaxException(String input, String reason, int index) {
jaroslav@1258
    62
        super(reason);
jaroslav@1258
    63
        if ((input == null) || (reason == null))
jaroslav@1258
    64
            throw new NullPointerException();
jaroslav@1258
    65
        if (index < -1)
jaroslav@1258
    66
            throw new IllegalArgumentException();
jaroslav@1258
    67
        this.input = input;
jaroslav@1258
    68
        this.index = index;
jaroslav@1258
    69
    }
jaroslav@1258
    70
jaroslav@1258
    71
    /**
jaroslav@1258
    72
     * Constructs an instance from the given input string and reason.  The
jaroslav@1258
    73
     * resulting object will have an error index of <tt>-1</tt>.
jaroslav@1258
    74
     *
jaroslav@1258
    75
     * @param  input   The input string
jaroslav@1258
    76
     * @param  reason  A string explaining why the input could not be parsed
jaroslav@1258
    77
     *
jaroslav@1258
    78
     * @throws  NullPointerException
jaroslav@1258
    79
     *          If either the input or reason strings are <tt>null</tt>
jaroslav@1258
    80
     */
jaroslav@1258
    81
    public URISyntaxException(String input, String reason) {
jaroslav@1258
    82
        this(input, reason, -1);
jaroslav@1258
    83
    }
jaroslav@1258
    84
jaroslav@1258
    85
    /**
jaroslav@1258
    86
     * Returns the input string.
jaroslav@1258
    87
     *
jaroslav@1258
    88
     * @return  The input string
jaroslav@1258
    89
     */
jaroslav@1258
    90
    public String getInput() {
jaroslav@1258
    91
        return input;
jaroslav@1258
    92
    }
jaroslav@1258
    93
jaroslav@1258
    94
    /**
jaroslav@1258
    95
     * Returns a string explaining why the input string could not be parsed.
jaroslav@1258
    96
     *
jaroslav@1258
    97
     * @return  The reason string
jaroslav@1258
    98
     */
jaroslav@1258
    99
    public String getReason() {
jaroslav@1258
   100
        return super.getMessage();
jaroslav@1258
   101
    }
jaroslav@1258
   102
jaroslav@1258
   103
    /**
jaroslav@1258
   104
     * Returns an index into the input string of the position at which the
jaroslav@1258
   105
     * parse error occurred, or <tt>-1</tt> if this position is not known.
jaroslav@1258
   106
     *
jaroslav@1258
   107
     * @return  The error index
jaroslav@1258
   108
     */
jaroslav@1258
   109
    public int getIndex() {
jaroslav@1258
   110
        return index;
jaroslav@1258
   111
    }
jaroslav@1258
   112
jaroslav@1258
   113
    /**
jaroslav@1258
   114
     * Returns a string describing the parse error.  The resulting string
jaroslav@1258
   115
     * consists of the reason string followed by a colon character
jaroslav@1258
   116
     * (<tt>':'</tt>), a space, and the input string.  If the error index is
jaroslav@1258
   117
     * defined then the string <tt>" at index "</tt> followed by the index, in
jaroslav@1258
   118
     * decimal, is inserted after the reason string and before the colon
jaroslav@1258
   119
     * character.
jaroslav@1258
   120
     *
jaroslav@1258
   121
     * @return  A string describing the parse error
jaroslav@1258
   122
     */
jaroslav@1258
   123
    public String getMessage() {
jaroslav@1258
   124
        StringBuffer sb = new StringBuffer();
jaroslav@1258
   125
        sb.append(getReason());
jaroslav@1258
   126
        if (index > -1) {
jaroslav@1258
   127
            sb.append(" at index ");
jaroslav@1258
   128
            sb.append(index);
jaroslav@1258
   129
        }
jaroslav@1258
   130
        sb.append(": ");
jaroslav@1258
   131
        sb.append(input);
jaroslav@1258
   132
        return sb.toString();
jaroslav@1258
   133
    }
jaroslav@1258
   134
jaroslav@1258
   135
}