~ubuntu-branches/ubuntu/precise/classpath/precise

« back to all changes in this revision

Viewing changes to gnu/java/net/protocol/file/Connection.java

  • Committer: Bazaar Package Importer
  • Author(s): Michael Koch
  • Date: 2006-05-27 16:11:15 UTC
  • mfrom: (1.1.3 upstream)
  • Revision ID: james.westby@ubuntu.com-20060527161115-h6e39eposdt5snb6
Tags: 2:0.91-3
* Install header files to /usr/include/classpath.
* debian/control: classpath: Conflict with jamvm < 1.4.3 and
  cacao < 0.96 (Closes: #368172).

Show diffs side-by-side

added added

removed removed

Lines of Context:
59
59
import java.text.SimpleDateFormat;
60
60
import java.util.Date;
61
61
import java.util.Locale;
 
62
import java.net.MalformedURLException;
62
63
 
63
64
/**
64
65
 * This subclass of java.net.URLConnection models a URLConnection via
125
126
  }
126
127
  
127
128
  /**
 
129
   * Unquote "%" + hex quotes characters
 
130
   *
 
131
   * @param str The string to unquote or null.
 
132
   *
 
133
   * @return The unquoted string or null if str was null.
 
134
   *
 
135
   * @exception MalformedURLException If the given string contains invalid
 
136
   * escape sequences.
 
137
   *
 
138
   */
 
139
  public static String unquote(String str) throws MalformedURLException
 
140
  {
 
141
    if (str == null)
 
142
      return null;
 
143
 
 
144
    final int MAX_BYTES_PER_UTF_8_CHAR = 3;
 
145
    byte[] buf = new byte[str.length()*MAX_BYTES_PER_UTF_8_CHAR];
 
146
    int pos = 0;
 
147
    for (int i = 0; i < str.length(); i++)
 
148
      {
 
149
        char c = str.charAt(i);
 
150
        if (c == '%')
 
151
          {
 
152
            if (i + 2 >= str.length())
 
153
              throw new MalformedURLException(str + " : Invalid quoted character");
 
154
            int hi = Character.digit(str.charAt(++i), 16);
 
155
            int lo = Character.digit(str.charAt(++i), 16);
 
156
            if (lo < 0 || hi < 0)
 
157
              throw new MalformedURLException(str + " : Invalid quoted character");
 
158
            buf[pos++] = (byte) (hi * 16 + lo);
 
159
          }
 
160
        else if (c > 127) {
 
161
            try {
 
162
                byte [] c_as_bytes = Character.toString(c).getBytes("utf-8");
 
163
                final int c_length = c_as_bytes.length;
 
164
                System.arraycopy(c_as_bytes, 0, buf, pos, c_length);
 
165
                pos += c_length;
 
166
            }
 
167
            catch (java.io.UnsupportedEncodingException x2) {
 
168
                throw (Error) new InternalError().initCause(x2);
 
169
            }
 
170
        }    
 
171
        else
 
172
          buf[pos++] = (byte) c;
 
173
      }
 
174
    try
 
175
      {
 
176
        return new String(buf, 0, pos, "utf-8");
 
177
      }
 
178
    catch (java.io.UnsupportedEncodingException x2)
 
179
      {
 
180
        throw (Error) new InternalError().initCause(x2);
 
181
      }
 
182
  }
 
183
 
 
184
  /**
128
185
   * "Connects" to the file by opening it.
129
186
   */
130
187
  public void connect() throws IOException
134
191
      return;
135
192
    
136
193
    // If not connected, then file needs to be openned.
137
 
    file = new File (getURL().getFile());
 
194
    file = new File (unquote(getURL().getFile()));
138
195
 
139
196
    if (! file.isDirectory())
140
197
      {