aspose file tools*
The moose likes Servlets and the fly likes Streaming PDF, Connecion Error Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "Streaming PDF, Connecion Error" Watch "Streaming PDF, Connecion Error" New topic
Author

Streaming PDF, Connecion Error

Sipho Motha
Greenhorn

Joined: Oct 27, 2003
Posts: 2
Hi, I'm trying to write a program that will open PDF file from the browser.
I tells that the Connection refused.
The code is shown below:
The url is = http://localhost/PdfFile.pdf

private void streamCharacterData(String urlstr,String format, PrintWriter outstr, HttpServletResponse resp)
{
String ErrorStr = null;
try{
//find the right MIME type and set it as contenttype
resp.setContentType(getMimeType(format));
InputStream in = null;
try{
URL url= new URL(urlstr);
URLConnection urlc= url.openConnection();
int length = urlc.getContentLength();
in = urlc.getInputStream();
resp.setContentLength(length);
int ch;
while ( (ch = in.read()) != -1 ) {
outstr.print( (char)ch );
}
} catch (Exception e) {
e.printStackTrace();
ErrorStr = "Error Streaming the Data";
outstr.print(ErrorStr);
} finally {
if( in != null ) {
in.close();
}
if( outstr != null ) {
outstr.flush();
outstr.close();
}
}
}
catch(Exception e){
e.printStackTrace();
}
}
can you show me the error
Thanks


SM Squared
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Streaming PDF, Connecion Error