536 |
Resource getResource(String name) |
Resource getResource(String name) |
537 |
{ |
{ |
538 |
File file = new File(dir, name); |
File file = new File(dir, name); |
539 |
if (file.exists()) |
if (file.exists() && !file.isDirectory()) |
540 |
return new FileResource(this, name, file); |
return new FileResource(this, name, file); |
541 |
return null; |
return null; |
542 |
} |
} |
554 |
|
|
555 |
InputStream getInputStream() throws IOException |
InputStream getInputStream() throws IOException |
556 |
{ |
{ |
|
// Delegate to the URL content handler mechanism to retrieve an |
|
|
// HTML representation of the directory listing if a directory |
|
|
if (file.isDirectory()) |
|
|
{ |
|
|
URL url = getURL(); |
|
|
return url.openStream(); |
|
|
} |
|
|
// Otherwise simply return a FileInputStream |
|
557 |
return new FileInputStream(file); |
return new FileInputStream(file); |
558 |
} |
} |
559 |
|
|
560 |
public int getLength() |
public int getLength() |
561 |
{ |
{ |
|
// Delegate to the URL content handler mechanism to retrieve the |
|
|
// length of the HTML representation of the directory listing if |
|
|
// a directory, or -1 if an exception occurs opening the directory. |
|
|
if (file.isDirectory()) |
|
|
{ |
|
|
URL url = getURL(); |
|
|
try |
|
|
{ |
|
|
URLConnection connection = url.openConnection(); |
|
|
return connection.getContentLength(); |
|
|
} |
|
|
catch (IOException e) |
|
|
{ |
|
|
return -1; |
|
|
} |
|
|
} |
|
|
// Otherwise simply return the file length |
|
562 |
return (int) file.length(); |
return (int) file.length(); |
563 |
} |
} |
564 |
|
|