inputStream.available();

This is what I'm trying to do,I want to send image byte[] from a J2ME client to a servlet.But there is no correct length returned.Is there any way can get through this?I heard some one use Printwriter works,but still not work in my case.

on servlet side--

String type=request.getContentType();

int length=request.getContentLength();

videoStream =request.getInputStream();

// int length=0;

// streamBuffer=new byte[videoStream.available()];

// videoStream.readLine(streamBuffer,0,videoStream.available()/4);

// length+=streamBuffer.length;

// byte[] image = streamBuffer;

response.setContentType("text/plain");

String ImageID = request.getParameter("ImagID");

PrintWriter pw = response.getWriter();

pw.write("POST received image package of size "+videoStream.available()+"\n");

// pw.write("length read in the buffer is "+ length+"\n");

pw.write("The image name passed in the parameter is "+ImageID);

pw.close();

-J2ME side

try{

String thisURL=url+"?ImagID=" + "1.jpg";

httpConnection=(HttpConnection)Connector.open(thisURL);

httpConnection.setRequestMethod(HttpConnection.POST);

httpConnection.setRequestProperty("User-Agent",

"Profile/MIDP-2.0 Configuration/CLDC-1.0");

httpConnection.setRequestProperty("Content-Language", "en-US");

// out= new DataOutputStream(httpConnection.openDataOutputStream());

byte[] sendData=null;

sendData=midlet.raw;

int[] sendInt=null;

sendInt=getIntArray(sendData);

pw=new PrintWriter(httpConnection.openOutputStream());

for(int i=0;i<sendInt.length;i++)

pw.write(sendInt);

//for (int i=0; i><sendData.length; i++)

//out.writeByte(sendData);

pw.flush();

pw.close();

//out.flush();

// out.close();

int responseCode = httpConnection.getResponseCode();

if (responseCode != HttpConnection.HTTP_OK)

throw new IOException();

InputStream is = httpConnection.openInputStream();

data = readReplyBody(httpConnection, is);

String message = new String(data, 0, data.length);

System.out.println("Response from servlet "+message);

is.close();

}

catch (ConnectionNotFoundException e)

{

Alert alert = new Alert("No Handler for HTTP", e.toString(),

null, AlertType.ERROR);

alert.setTimeout(Alert.FOREVER);

midlet.getDisplay().setCurrent(alert);

}

catch (IOException e)

{Alert alert = new Alert("IO Error", e.toString(),

null, AlertType.ERROR);

alert.setTimeout(Alert.FOREVER);

midlet.getDisplay().setCurrent(alert);

}>

[2734 byte] By [r19850420@yahoo.com.cna] at [2007-11-27 11:28:52]
# 1

Has this got anything to do with Base64Encoding,as HTTP is ASCII protocol.

All right,now I understand why I can't find useful info from a website or a forum.

Thank you!

r19850420@yahoo.com.cna at 2007-7-29 16:24:35 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...