Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Base64 decoder in ServletOutputStream truncated

Status
Not open for further replies.

daniel135

Programmer
Apr 9, 2002
93
CA
The following code snippet only sends back the first 4 bytes of a .zip file, has an error with .doc but spits out a whole entire text file...

import com.oreilly.servlet.Base64Decoder;

private void testStream(HttpServletRequest req, HttpServletResponse res)
throws ServletException, IOException
{
HttpSession sess = req.getSession(false);
ServletOutputStream out = res.getOutputStream();

String fileName = (String) sess.getValue("fileName");
res.setContentType( "application/octetstream" );
res.setHeader( "Content-Disposition", "filename=" + fileName + ";" );

byte[] bytes = Base64Decoder.decode((String)sess.getValue("fileContents")).getBytes();

out.write(bytes);
}

(String)sess.getValue("fileContents") correctly retrieves the Base64 encoded file... and like I said, it's working fine on text strings.

Anyone have an idea what I'm doing wrong here?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top