43 import java.nio.channels.*;
44 import java.nio.charset.*;
52 class FileContent
implements Content {
54 private static File ROOT =
new File(
"root");
58 FileContent(URI uri) {
65 private String type =
null;
67 public String type() {
70 String nm = fn.getName();
71 if (nm.endsWith(
".html"))
72 type =
"text/html; charset=iso-8859-1";
73 else if ((nm.indexOf(
'.') < 0) || nm.endsWith(
".txt"))
74 type =
"text/plain; charset=iso-8859-1";
76 type =
"application/octet-stream";
80 private FileChannel fc =
null;
81 private long length = -1;
82 private long position = -1;
84 public long length() {
88 public void prepare() throws IOException {
90 fc =
new RandomAccessFile(fn,
"r").getChannel();
95 public boolean send(ChannelIO cio)
throws IOException {
97 throw new IllegalStateException();
99 throw new IllegalStateException();
104 if (position >= length) {
108 position += cio.transferTo(fc, position, length - position);
109 return (position < length);
112 public void release() throws IOException {