jdk/src/share/classes/java/net/URISyntaxException.java
author xdono
Thu, 02 Oct 2008 19:58:32 -0700
changeset 1247 b4c26443dee5
parent 2 90ce3da70b43
child 1334 21b652819b97
permissions -rw-r--r--
6754988: Update copyright year Summary: Update for files that have been modified starting July 2008 Reviewed-by: ohair, tbell
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
     2
 * Copyright 2000-2006 Sun Microsystems, Inc.  All Rights Reserved.
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
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
    private String input;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
    private int index;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
     * Constructs an instance from the given input string, reason, and error
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
     * index.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
     * @param  input   The input string
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
     * @param  reason  A string explaining why the input could not be parsed
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
     * @param  index   The index at which the parse error occurred,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
     *                 or <tt>-1</tt> if the index is not known
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
     * @throws  NullPointerException
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
     *          If either the input or reason strings are <tt>null</tt>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
     * @throws  IllegalArgumentException
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
     *          If the error index is less than <tt>-1</tt>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
    public URISyntaxException(String input, String reason, int index) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
        super(reason);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
        if ((input == null) || (reason == null))
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
            throw new NullPointerException();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
        if (index < -1)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
            throw new IllegalArgumentException();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
        this.input = input;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
        this.index = index;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
     * Constructs an instance from the given input string and reason.  The
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
     * resulting object will have an error index of <tt>-1</tt>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
     * @param  input   The input string
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
     * @param  reason  A string explaining why the input could not be parsed
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
     * @throws  NullPointerException
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
     *          If either the input or reason strings are <tt>null</tt>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
    public URISyntaxException(String input, String reason) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
        this(input, reason, -1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
     * Returns the input string.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
     * @return  The input string
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
    public String getInput() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
        return input;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
     * Returns a string explaining why the input string could not be parsed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
     * @return  The reason string
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
    public String getReason() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
        return super.getMessage();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
     * Returns an index into the input string of the position at which the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
     * parse error occurred, or <tt>-1</tt> if this position is not known.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
     * @return  The error index
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
    public int getIndex() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
        return index;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
     * Returns a string describing the parse error.  The resulting string
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
     * consists of the reason string followed by a colon character
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
     * (<tt>':'</tt>), a space, and the input string.  If the error index is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
     * defined then the string <tt>" at index "</tt> followed by the index, in
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
     * decimal, is inserted after the reason string and before the colon
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
     * character.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
     * @return  A string describing the parse error
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
    public String getMessage() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
        StringBuffer sb = new StringBuffer();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
        sb.append(getReason());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
        if (index > -1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
            sb.append(" at index ");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
            sb.append(index);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
        sb.append(": ");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
        sb.append(input);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
        return sb.toString();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
}