[Biojava-dev] Spaces in file paths - resolved

Andreas Prlic andreas at sdsc.edu
Thu Sep 10 21:38:22 UTC 2009


Hi Andy,

thanks for figuring this out. I committed the patches to SVN.

what used to read
    URL url = EntryNamRandomAccessTest.class.getResource("entrynam.idx");
        File  f = new File(url.getFile());

now reads:
   URL url = EntryNamRandomAccessTest.class.getResource("entrynam.idx");
        File  f = new File(new URI("file://"+url.getFile()));


Andreas


On Thu, Sep 10, 2009 at 8:00 AM, Andy Law (RI) <andy.law at roslin.ed.ac.uk> wrote:
> All,
>
> I've been digging about in the bowels of the java.io libraries and the
> biojava core tests and I have a fix.
>
> From what I can tell, the problem with spaces in file paths is NOT a
> Mac-specific thing. I threw together some tests (attached as a tgz version
> of the maven project) that demonstrate the problem on the Mac but then when
> I ran them on the linux box, the same tests failed so I think it is a
> general issue. However, in doing so I was able to get to grips with why it
> is failing and how to work around it.
>
> The problem stems from the RandomAccessFile constructor being given a File
> whose path contains encoded spaces. The File objects in question are
> constructed (in the tests) using the file path extracted from a URL object
> i.e. the MO of the tests is:
>
> (1) create URL pointing at the file
> (2) create a File from that (using the *path* extracted from the URL [via
> getFile()! go figure])
> (3) create a RandomAccessFile from the File
>
> There are similar problems creating Streams from the File object but points
> (1) and (2) are the same in that situation.
>
> However, it is possible to construct a File from a URI (note UR*I* not
> UR*L*) and it is possible to extract a URI from a URL. The File generated
> this way seems to have the path escaped or handled properly. Thus if we
> replace step (2) with "create a File from a URI extracted from the URL" then
> all seems to be well.
>
>
>
> Changes required:
>
> Change .getFile() to .getURI() at:
>
> Line 196:
> biojava/core/src/test/java/org/biojava/bio/program/indexdb/IndexToolsTest.java
> Line  53:
> biojava/core/src/test/java/org/biojava/bio/seq/db/emblcd/DivisionLkpReaderTest.java
> Line  58:
> biojava/core/src/test/java/org/biojava/bio/seq/db/emblcd/EntryNamIdxReaderTest.java
> Line  54:
> biojava/core/src/test/java/org/biojava/bio/seq/db/emblcd/EntryNamRandomAccessTest.java
> Line  70:
> biojava/core/src/test/java/org/biojava/bio/seq/db/EmblCDROMIndexStoreTest.java
> Line  71:
> biojava/core/src/test/java/org/biojava/bio/seq/db/EmblCDROMIndexStoreTest.java
>
>
>
> Hope that helps.
>
>
> Later,
>
> Andy
> --------
> Yada, yada, yada...
> The University of Edinburgh is a charitable body, registered in Scotland,
> with registration number SC005336
> Disclaimer: This e-mail and any attachments are confidential and intended
> solely for the use of the recipient(s) to whom they are addressed. If you
> have received it in error, please destroy all copies and inform the sender.
>
>
>
> _______________________________________________
> biojava-dev mailing list
> biojava-dev at lists.open-bio.org
> http://lists.open-bio.org/mailman/listinfo/biojava-dev
>
>




More information about the biojava-dev mailing list