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() && ! file.isDirectory()) |
if (file.exists()) |
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 |
{ |
{ |
557 |
|
// Delegate to the URL content handler mechanism to retrieve an |
558 |
|
// HTML representation of the directory listing if a directory |
559 |
|
if (file.isDirectory()) |
560 |
|
{ |
561 |
|
URL url = getURL(); |
562 |
|
return url.openStream(); |
563 |
|
} |
564 |
|
// Otherwise simply return a FileInputStream |
565 |
return new FileInputStream(file); |
return new FileInputStream(file); |
566 |
} |
} |
567 |
|
|
568 |
public int getLength() |
public int getLength() |
569 |
{ |
{ |
570 |
|
// Delegate to the URL content handler mechanism to retrieve the |
571 |
|
// length of the HTML representation of the directory listing if |
572 |
|
// a directory, or -1 if an exception occurs opening the directory. |
573 |
|
if (file.isDirectory()) |
574 |
|
{ |
575 |
|
URL url = getURL(); |
576 |
|
try |
577 |
|
{ |
578 |
|
URLConnection connection = url.openConnection(); |
579 |
|
return connection.getContentLength(); |
580 |
|
} |
581 |
|
catch (IOException e) |
582 |
|
{ |
583 |
|
return -1; |
584 |
|
} |
585 |
|
} |
586 |
|
// Otherwise simply return the file length |
587 |
return (int) file.length(); |
return (int) file.length(); |
588 |
} |
} |
589 |
|
|