MCPcopy Create free account
hub / github.com/beanshell/beanshell / sendFileData

Method sendFileData

src/bsh/util/Httpd.java:169–205  ·  view source on GitHub ↗
(String file)

Source from the content-addressed store, hash-verified

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 {

Callers 1

serveFileMethod · 0.95

Calls 7

getClassMethod · 0.80
availableMethod · 0.80
flushMethod · 0.80
printlnMethod · 0.65
getResourceAsStreamMethod · 0.45
readMethod · 0.45
writeMethod · 0.45

Tested by

no test coverage detected