Click to See Complete Forum and Search --> : Servlet Syntax


DinoAdor
September 29th, 1999, 11:03 PM
Greetings Gurus! I need help understanding this syntax:

ServletInputStream sis = req.getInputStream();
byte[]buf = new byte[4096];
sis.read(buf);
String name = new String(buf).trim().toUpperCase();
PrintWriter pw = res.getWriter();

It's really the 4th line that confuses me. I didnt know that syntax is legal. Could someone explain to me in detail 'String(buf).trim().toUpperCase()? In fact explaining the whole thing wouldnt hurt :). NOTE: I do know that the PrinterWriter object can be replaced by the ServletOutputStream object. I didnt know u can have a type byte[] variable. I need a clearer understanding of what this does.

Thanks!
Dino

meherss
September 30th, 1999, 12:58 PM
String name = new String(buf).trim().toUpperCase();
// is equal to
Sting name = new String(buf); // Creates a String oject of buf.
name = name.trim(); // removes the white spaces.
name = name.toUpperCase(); // converts the value to upper case...






Meher

DinoAdor
September 30th, 1999, 06:00 PM
Thanks Meher.

I just found the interpretation of that line while reading your response. Yes it just calls the constructor with a 'buf' parameter then it removes white spaces by .trim() then converts the value to Uppercase using .toUpperCase().
from a left to right order. I just didnt know that syntax was legal. Perhaps the authors of my book were simply too lazy to write the methods individually but thanks for the reply anyway. :)

Dino