S
Shlomi
Hi.
i have a servlet that receives a binary data in one of its parameters.
i cannot read this binary data to a byte array for some reason
when i am trying to use servletInputStream.available() i am getting 0.
any suggestions ?
what am i donig wrong ?
here is my code :
(don't look for syntax mistakes, i pasted the relevant code only)
public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException
{
throws ServletException, IOException
{
try
{
// get POSTED data
// use servlet input stream
ServletInputStream ins = request.getInputStream();
//count length of data
int len = request.getContentLength();
//allocate bytes buffer
byte[] buf = new byte[len];
int offset = 0;
do
{
int inputLen = ins.read(buf, offset, len - offset);
// MY PROBLEM ----- inputLen always equals -1
if (DEBUG)
System.out.println("POST Input Length = " + inputLen);
if (inputLen <= 0)
{
String msg = "read finished early - read " +
offset + " of " + len + " bytes(contentLength)" ;
throw new IOException(msg);
}
offset += inputLen;
}
}
i have a servlet that receives a binary data in one of its parameters.
i cannot read this binary data to a byte array for some reason
when i am trying to use servletInputStream.available() i am getting 0.
any suggestions ?
what am i donig wrong ?
here is my code :
(don't look for syntax mistakes, i pasted the relevant code only)
public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException
{
throws ServletException, IOException
{
try
{
// get POSTED data
// use servlet input stream
ServletInputStream ins = request.getInputStream();
//count length of data
int len = request.getContentLength();
//allocate bytes buffer
byte[] buf = new byte[len];
int offset = 0;
do
{
int inputLen = ins.read(buf, offset, len - offset);
// MY PROBLEM ----- inputLen always equals -1
if (DEBUG)
System.out.println("POST Input Length = " + inputLen);
if (inputLen <= 0)
{
String msg = "read finished early - read " +
offset + " of " + len + " bytes(contentLength)" ;
throw new IOException(msg);
}
offset += inputLen;
}
}