Apply patch for bugs 2030388 and 3134533: FileProtocolIteratorFactory creates File...
[scannotation] / src / main / java / org / scannotation / archiveiterator / FileProtocolIteratorFactory.java
1 package org.scannotation.archiveiterator;
2
3 import java.io.File;
4 import java.io.IOException;
5 import java.net.URISyntaxException;
6 import java.net.URL;
7
8 /**
9  * @author <a href="mailto:bill@burkecentral.com">Bill Burke</a>
10  * @version $Revision: 1 $
11  */
12 public class FileProtocolIteratorFactory implements DirectoryIteratorFactory
13 {
14
15    public StreamIterator create(URL url, Filter filter) throws IOException
16    {
17        // See http://weblogs.java.net/blog/2007/04/25/how-convert-javaneturl-javaiofile
18        File f;
19        try
20        {
21            f = new File(url.toURI());
22        }
23        catch (URISyntaxException e)
24        {
25            f = new File(url.getPath());
26        }
27
28        if (f.isDirectory())
29       {
30          return new FileIterator(f, filter);
31       }
32       else
33       {
34          return new JarIterator(url.openStream(), filter);
35       }
36    }
37 }