Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Getting unwanted characters at the start and end of a downloaded xml file  RSS feed

 
Trelston Moraes
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have written the following piece of code in my jsp file. It sends an xml file for download using outputstream

<%

String strPath = application.getRealPath("web/resources/config.xml");
File oFile = new File(strPath);
String strFileName = oFile.getName();
response.setContentType(getResponseType(strFileName));


byte[] bByteArray = new byte[(int)oFile.length()];
FileInputStream oFileInputStream = new FileInputStream(oFile);
oFileInputStream.read(bByteArray);

ServletOutputStream oOutputStream = response.getOutputStream();
oOutputStream.write(bByteArray);
oOutputStream.flush();
%>
When the file is downloaded then when i open notepad i get the following unwanted characters '28d' at the start of the file and at the end of the file we get 0.The snapshot taken from fiddler is as follows. I need it without those characters because then i have an embedded object that reads it.



28d
<?xml version="1.0" encoding="utf-8"?>
<Binary>
<binaries>
<binary />
<binary />
<binary /><binary />
<binary />

<binary />
<binary />
<binary />
</binaries></BinaryManifest>
0
 
Ulf Dittmer
Rancher
Posts: 42970
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to JavaRanch.

JSPs are not meant for streaming files. They'll generally insert white space characters that are hard (or may be impossible) to get rid of. What you're seeing is probably an artifact of that. Use a servlet instead.
 
Trelston Moraes
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Ulf Dittmer:
Welcome to JavaRanch.

JSPs are not meant for streaming files. They'll generally insert white space characters that are hard (or may be impossible) to get rid of. What you're seeing is probably an artifact of that. Use a servlet instead.


Thanks Ulf
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!