Clover coverage report -
Coverage timestamp: Do Okt 21 2004 12:21:23 CEST
file stats: LOC: 104   Methods: 4
NCLOC: 82   Classes: 1
 
 Source file Conditionals Statements Methods TOTAL
Response.java 0% 0% 0% 0%
coverage
 1    package org.jconfig.server;
 2   
 3    import java.io.File;
 4    import java.io.FileInputStream;
 5    import java.io.IOException;
 6    import java.io.OutputStream;
 7   
 8    import org.jconfig.utils.ConfigurationUtils;
 9   
 10    /**
 11    * This class implements the Response for the configuration server.
 12    * It supposed to send back the configuration file. If the file
 13    * does not exist it will send back a HTTP 404
 14    *
 15    * @author Andreas Mecky andreasmecky@yahoo.de
 16    * @author Terry Dye terrydye@yahoo.com
 17    */
 18    public class Response {
 19   
 20    private static final int BUFFER_SIZE = 1024;
 21    Request request;
 22    OutputStream output;
 23   
 24  0 public Response(OutputStream output) {
 25  0 this.output = output;
 26    }
 27   
 28  0 public void setRequest(Request request) {
 29  0 this.request = request;
 30    }
 31   
 32  0 public void sendStaticResource(String fileName) throws IOException {
 33  0 byte[] bytes = new byte[BUFFER_SIZE];
 34  0 FileInputStream fis = null;
 35  0 try {
 36  0 File file = new File(fileName);
 37  0 if (file.exists()) {
 38  0 fis = new FileInputStream(file);
 39  0 int ch = fis.read(bytes, 0, BUFFER_SIZE);
 40  0 while (ch!=-1) {
 41  0 output.write(bytes, 0, ch);
 42  0 ch = fis.read(bytes, 0, BUFFER_SIZE);
 43    }
 44    }
 45    else {
 46  0 System.out.println("Cannot find file:"+fileName);
 47    // file not found
 48  0 String errorMessage = "HTTP/1.1 404 File Not Found\r\n" +
 49    "Content-Type: text/html\r\n" +
 50    "Content-Length: 23\r\n" +
 51    "\r\n" +
 52    "<h1>File Not Found</h1>";
 53  0 output.write(errorMessage.getBytes());
 54    }
 55    }
 56    catch (Exception e) {
 57    // thrown if cannot instantiate a File object
 58  0 System.out.println(e.toString() );
 59    }
 60    finally {
 61  0 if (fis!=null)
 62  0 fis.close();
 63    }
 64    }
 65   
 66  0 public void sendStaticResource() throws IOException {
 67  0 byte[] bytes = new byte[BUFFER_SIZE];
 68  0 FileInputStream fis = null;
 69  0 String uri = request.getUri();
 70  0 if ( uri.startsWith("/") ) {
 71  0 uri = uri.substring(1);
 72    }
 73  0 uri += ".xml";
 74  0 try {
 75    //File file = new File(".", request.getUri());
 76  0 File file = ConfigurationUtils.getFileFromInputStream(uri);
 77  0 if (file.exists()) {
 78  0 fis = new FileInputStream(file);
 79  0 int ch = fis.read(bytes, 0, BUFFER_SIZE);
 80  0 while (ch!=-1) {
 81  0 output.write(bytes, 0, ch);
 82  0 ch = fis.read(bytes, 0, BUFFER_SIZE);
 83    }
 84    }
 85    else {
 86    // file not found
 87  0 String errorMessage = "HTTP/1.1 404 File Not Found\r\n" +
 88    "Content-Type: text/html\r\n" +
 89    "Content-Length: 23\r\n" +
 90    "\r\n" +
 91    "<h1>File Not Found</h1>";
 92  0 output.write(errorMessage.getBytes());
 93    }
 94    }
 95    catch (Exception e) {
 96    // thrown if cannot instantiate a File object
 97  0 System.out.println(e.toString() );
 98    }
 99    finally {
 100  0 if (fis!=null)
 101  0 fis.close();
 102    }
 103    }
 104    }