[Biojava-dev] Spaces in file paths - resolved

Andy Law (RI) andy.law at roslin.ed.ac.uk
Thu Sep 10 15:00:53 UTC 2009


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.


-------------- next part --------------
A non-text attachment was scrubbed...
Name: testfiles.tgz
Type: application/octet-stream
Size: 1749 bytes
Desc: not available
URL: <http://lists.open-bio.org/pipermail/biojava-dev/attachments/20090910/b7c81ba2/attachment-0002.obj>


More information about the biojava-dev mailing list