Java Reference
In-Depth Information
/**
* Determine the correct "content type" based on the file
* extension.
*
* @param path The file being transfered.
* @return The correct content type for this file.
* @throws IOException Thrown if any sort of error occurs.
*/
private String getContent(String path)
{
path = path.toLowerCase();
if (path.endsWith(".jpg") || path.endsWith(".jpeg"))
return "image/jpeg";
else if (path.endsWith(".gif"))
return "image/gif";
else if (path.endsWith(".png"))
return "image/png";
else
return "text/html";
}
/**
* Send a disk file. The path passed in is from the URL, this
* URL is translated into a local disk file, which is then
* transfered.
*
* @param out The output stream.
* @param path The file requested from the URL.
* @throws IOException Thrown if any sort of error occurs.
*/
private void sendFile(OutputStream out, String path)
throws IOException
{
// parse the file by /'s and build a local file
StringTokenizer tok = new StringTokenizer(path, "/", true);
System.out.println(path);
String physicalPath = addSlash(httproot);
while (tok.hasMoreElements())
{
String e = (String) tok.nextElement();
if (!e.trim().equalsIgnoreCase(File.separator))
{
if (e.equals("..") || e.equals("."))
{
Search WWH ::




Custom Search