| 167 | } |
| 168 | |
| 169 | private void sendFileData(String file) |
| 170 | throws IOException, FileNotFoundException |
| 171 | { |
| 172 | /* |
| 173 | Why aren't resources being found when this runs on Win95? |
| 174 | */ |
| 175 | InputStream fis = getClass().getResourceAsStream(file); |
| 176 | if(fis == null) |
| 177 | throw new FileNotFoundException(file); |
| 178 | byte[] data = new byte[fis.available()]; |
| 179 | |
| 180 | if(isHttp1) |
| 181 | { |
| 182 | pout.println("HTTP/1.0 200 Document follows"); |
| 183 | |
| 184 | pout.println("Content-length: " + data.length ); |
| 185 | |
| 186 | if ( file.endsWith(".gif") ) |
| 187 | pout.println("Content-type: image/gif"); |
| 188 | else |
| 189 | if( file.endsWith(".html") || file.endsWith(".htm") ) |
| 190 | pout.println("Content-Type: text/html"); |
| 191 | else |
| 192 | pout.println("Content-Type: application/octet-stream"); |
| 193 | |
| 194 | pout.println(); |
| 195 | } |
| 196 | |
| 197 | int bytesread = 0; |
| 198 | // Never, ever trust available() |
| 199 | do { |
| 200 | bytesread = fis.read(data); |
| 201 | if (bytesread > 0) |
| 202 | pout.write( data, 0, bytesread ); |
| 203 | } while( bytesread != -1 ); |
| 204 | pout.flush(); |
| 205 | } |
| 206 | |
| 207 | private void error(int num, String s) |
| 208 | { |