01: // Copyright (C) 2003,2004,2005 by Object Mentor, Inc. All rights reserved.
02: // Released under the terms of the GNU General Public License version 2 or later.
03: package fitnesse.http;
04:
05: import java.io.*;
06: import fitnesse.util.StreamReader;
07:
08: public class InputStreamResponse extends Response {
09: private StreamReader reader;
10: private int contentSize = 0;
11:
12: public void readyToSend(ResponseSender sender) throws Exception {
13: addStandardHeaders();
14: sender.send(makeHttpHeaders().getBytes());
15: while (!reader.isEof())
16: sender.send(reader.readBytes(1000));
17: reader.close();
18: sender.close();
19: }
20:
21: protected void addSpecificHeaders() {
22: addHeader("Content-Length", getContentSize() + "");
23: }
24:
25: public int getContentSize() {
26: return contentSize;
27: }
28:
29: public void setBody(InputStream input, int size) {
30: reader = new StreamReader(input);
31: contentSize = size;
32: }
33:
34: public void setBody(File file) throws Exception {
35: FileInputStream input = new FileInputStream(file);
36: int size = (int) file.length();
37: setBody(input, size);
38: }
39: }
|