bug-classpath
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Bug classpath/26218] New: File.toURL().openConnection().getInputStream(


From: freebeans at xqb dot biglobe dot ne dot jp
Subject: [Bug classpath/26218] New: File.toURL().openConnection().getInputStream() throws MalformedURLException
Date: 11 Feb 2006 07:42:45 -0000

Following code occurres MalformedURLException
---
import java.io.*;
import java.net.*;
public class FileTest {
  static final String JAPANESE_HIRAGANA_LETTER_RA = "\u3089";
  public static void main(String[] args) throws Exception {
    File file = new File(JAPANESE_HIRAGANA_LETTER_RA);
    URL url = file.toURL();
    URLConnection uc = url.openConnection();
    InputStream ins = uc.getInputStream();
  }
}
---
I think gnu.java.net.protocol.file.Connection cannot handle non-ascii character
filename. Method unquote() treat the filename as UTF-8.

gnu.java.net.protocol.file.Connection
---
  public static String unquote(String str) throws MalformedURLException
  {
    if (str == null)
      return null;
    byte[] buf = new byte[str.length()];
    int pos = 0;
    for (int i = 0; i < str.length(); i++)
      {
        char c = str.charAt(i);
        if (c > 127)
          throw new MalformedURLException(str + " : Invalid character");
        if (c == '%')
          {
            if (i + 2 >= str.length())
              throw new MalformedURLException(str + " : Invalid quoted
character");
            int hi = Character.digit(str.charAt(++i), 16);
            int lo = Character.digit(str.charAt(++i), 16);
            if (lo < 0 || hi < 0)
              throw new MalformedURLException(str + " : Invalid quoted
character");
            buf[pos++] = (byte) (hi * 16 + lo);
          }
        else
          buf[pos++] = (byte) c;
      }
    try
      {
        return new String(buf, 0, pos, "utf-8");
      }
    catch (java.io.UnsupportedEncodingException x2)
      {
        throw (Error) new InternalError().initCause(x2);
      }
  }
---


-- 
           Summary: File.toURL().openConnection().getInputStream() throws
                    MalformedURLException
           Product: classpath
           Version: 0.20
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: classpath
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: freebeans at xqb dot biglobe dot ne dot jp


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=26218





reply via email to

[Prev in Thread] Current Thread [Next in Thread]