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