#24 FileLoader.java(210): uri.getPath() return null

open
nobody
None
5
2014-08-25
2012-07-31
Dmitry
No

The error occurs in class FileLoader::openInputStream(URI uri) if the filepath contains the name of the scheme 'file:'.
One solution to resolve this problem is to check the value uri.getPath() to null and if it null then try to use uri.getSchemeSpecificPart().
Some code to solve this problem (the whole class in an attachment):
String filePath = uri.getPath();
if (StringUtils.isEmpty(filePath)) {
filePath = uri.getSchemeSpecificPart();
}
if (StringUtils.isNotEmpty(filePath) && filePath.toLowerCase().endsWith(".zip")) {
ret = fromZipFile(firstStream);
} else if (StringUtils.isNotEmpty(filePath) && filePath.toLowerCase().endsWith(".gz")) {
ret = new GZIPInputStream(firstStream);
} else {
ret = firstStream;
}

Discussion

  • Dmitry
    Dmitry
    2012-07-31

     
    Attachments
  • Luca Passani
    Luca Passani
    2012-08-01

    Isn't the scheme "file:///" ?

    can you try using the correct scheme and report?

    Thanks

     
  • Dmitry
    Dmitry
    2012-08-02

    I'm try to using WURFL-API in Java project (Spring used):
    My wurfl-context.xml :
    <bean id="wurflHolder" class="net.sourceforge.wurfl.core.GeneralWURFLEngine">
    <constructor-arg index="0" value="file:${resource.wurfl}"/>
    <property name="cacheProvider" ref="wurflDeviceCacheProvider"/>
    </bean>
    where ${resource.wurfl} - path to wurfl.xml.
    In Java beans you can use 'file:' or 'classpath:' for setting path to file and using scheme 'file:///' in this case is not correct.
    Moreover, in Windows and Unix systems paths are defined in different ways, as you know.
    Maybe I'm wrong in something? Then explain to me what I'm doing wrong, please.

     
  • Steve Kamerman
    Steve Kamerman
    2012-08-02

    Hi papaich,

    The value to the GeneralWURFLEngine constructor is in the standard URI format as described in the java.net.URI documentation (http://docs.oracle.com/javase/1.4.2/docs/api/java/net/URI.html), which implements RFC 2396 (http://www.ietf.org/rfc/rfc2396.txt). An explanation of using the file:/// format in a URI is available in Wikipedia (http://en.wikipedia.org/wiki/File_URI_scheme).

    Basically the format is:
    scheme://hostname/path
    The scheme for a file is "file", and, in the case of a local file, the hostname is left blank, so you are left with this:
    file:///path
    In a UNIX-like environment, to specify the file /tmp/wurfl.xml, you would thus use this syntax:
    file:////tmp/wurfl.xml
    In a Windows environment, the file C:\temp\wurfl.xml would be represented like this:
    file:///c:/temp/wurfl.xml

    I think your suggestion of the "file:" prefix without the slashes comes from the Spring Framework resource string definition (http://static.springsource.org/spring/docs/3.0.x/spring-framework-reference/html/resources.html#resources-resource-strings), which is not used in this case.

    I trust this solves your problem.

    Thanks,

    Steve Kamerman
    ScientiaMobile, Inc.

     
  • Dmitry
    Dmitry
    2012-08-03

    Hi Steve,

    Yes I used Spring Framework and all resource links in project uses format 'file:' without slashes as in Spring Framework documentation.