In my java servlet program i am getting images from android application.I want to encode again decode image. If i got two images from android: [abc,def].It is decoded using MyHelper.decodeImage1(a). Now problem comes in next step. I want to encode decoded image again. Yes it do encoding. But result is in a single string abcdef. How can i separate two images to send it back to android? How should i manage loop or array in loop. I have tried alot but can't differentiate abc and def. Please help
String imageString=request.getParameter("image");
// image comees in format [abc,def,efg... and son on]
imageString=imageString.replace("[", "");
imageString=imageString.replace("]", "");
imageString=imageString.replace(" " , "");
String[] r = imageString.split(",");
for(int i=0; i<r.length;i++){
String a=r[i];
System.out.println("In loop = "+i);
byte[] imageByteArray = MyHelper.decodeImage1(a);
String encodedimageByteArray=Base64.encodeBytes(imageByteArray) ;
ArrayList<String> StringImages = new ArrayList<String>();
StringImages.add(encodedimageByteArray);
response.getWriter().write(encodedimageByteArray);
}
write
to write a string... so you can write whatever you want. For example, at the start of the loop:if (i != 0) { response.getWriter.write(",")) }
. If you want to put it in square brackets you'll need a little bit more work, but fundamentally you're just writing strings to a writer.