use of com.genexus.IHttpContext in project JavaClasses by genexuslabs.
the class HttpResponse method addFile.
public void addFile(String fileName) {
resetErrors();
try {
if (ModelContext.getModelContext() != null && !new File(fileName).isAbsolute()) {
IHttpContext webContext = ModelContext.getModelContext().getHttpContext();
if ((webContext != null) && (webContext instanceof HttpContextWeb) && !fileName.isEmpty()) {
fileName = ModelContext.getModelContext().getHttpContext().getDefaultPath() + File.separator + fileName;
}
}
InputStream source = new BufferedInputStream(new FileInputStream(fileName));
int bytes_read;
byte[] buffer = new byte[1024];
while (true) {
bytes_read = source.read(buffer);
if (bytes_read == -1)
break;
httpContext.getOutputStream().write(buffer, 0, bytes_read);
}
source.close();
} catch (FileNotFoundException e) {
errCode = ERROR_IO;
errDescription = e.getMessage();
} catch (IOException e) {
errCode = ERROR_IO;
errDescription = e.getMessage();
}
}
Aggregations