3131import java .io .ByteArrayInputStream ;
3232import java .io .IOException ;
3333import java .util .Arrays ;
34- import java .util .LinkedList ;
3534
3635import org .slf4j .Logger ;
3736import org .slf4j .LoggerFactory ;
@@ -88,7 +87,6 @@ public class Value {
8887 }
8988
9089 public class ResponseParser {
91- private LinkedList <Value > list ;
9290 public Value retvalue = null ;
9391
9492 public void exec (byte [] res ) throws IOException {
@@ -97,7 +95,6 @@ public void exec(byte[] res) throws IOException {
9795 byte [] end = new byte [5 ];
9896 byte next ;
9997 int length = 0 ;
100- int i = 0 ;
10198
10299 // check if it is the end.
103100 stream .mark (0 );
@@ -107,80 +104,70 @@ public void exec(byte[] res) throws IOException {
107104 }
108105 stream .reset ();
109106
110- while (true ) {
111- Value value = new Value ();
112- // skip "VALUE <key> "
113- stream .skip (B_VALUE .length + key .length () + 1 );
107+ Value value = new Value ();
108+ // skip "VALUE <key> "
109+ stream .skip (B_VALUE .length + key .length () + 1 );
114110
115- // get the length of <flags> and build it.
116- length = 0 ;
117- while ((next = (byte ) stream .read ()) != AscIIUDPClient .B_DELIMITER ) {
118- length ++;
119- sb .append ((char ) next );
120- }
121- try {
122- value .flags = Integer .valueOf (sb .toString ());
123- } catch (NumberFormatException e ) {
124- retvalue = null ;
125- return ;
126- }
127- sb .delete (0 , length );
111+ // get the length of <flags> and build it.
112+ length = 0 ;
113+ while ((next = (byte ) stream .read ()) != AscIIUDPClient .B_DELIMITER ) {
114+ length ++;
115+ sb .append ((char ) next );
116+ }
117+ try {
118+ value .flags = Integer .valueOf (sb .toString ());
119+ } catch (NumberFormatException e ) {
120+ retvalue = null ;
121+ return ;
122+ }
123+ sb .delete (0 , length );
124+
125+ // get the length of <byte> and build it.
126+ length = 0 ;
127+ while (((next = (byte ) stream .read ()) != AscIIUDPClient .B_DELIMITER ) && (next != B_RETURN )) {
128+ length ++;
129+ sb .append ((char ) next );
130+ }
128131
129- // get the length of <byte> and build it.
132+ try {
133+ value .bytes = Integer .valueOf (sb .toString ());
134+ } catch (NumberFormatException e ) {
135+ retvalue = null ;
136+ return ;
137+ }
138+ sb .delete (0 , length );
139+
140+ if (cmd .equals ("gets" )) {
141+ // if gets then get the length of <casUnique> and build it.
130142 length = 0 ;
131- while ((( next = (byte ) stream .read ()) != AscIIUDPClient . B_DELIMITER ) && ( next != B_RETURN ) ) {
143+ while ((next = (byte ) stream .read ()) != B_RETURN ) {
132144 length ++;
133145 sb .append ((char ) next );
134146 }
135-
136147 try {
137- value .bytes = Integer .valueOf (sb .toString ());
148+ value .casUnique = Long .valueOf (sb .toString ());
138149 } catch (NumberFormatException e ) {
139150 retvalue = null ;
140151 return ;
141152 }
142153 sb .delete (0 , length );
154+ }
143155
144- if (cmd .equals ("gets" )) {
145- // if gets then get the length of <casUnique> and build it.
146- length = 0 ;
147- while ((next = (byte ) stream .read ()) != B_RETURN ) {
148- length ++;
149- sb .append ((char ) next );
150- }
151- try {
152- value .casUnique = Long .valueOf (sb .toString ());
153- } catch (NumberFormatException e ) {
154- retvalue = null ;
155- return ;
156- }
157- sb .delete (0 , length );
158- }
159-
160- // skip "\n"
161- stream .skip (1 );
156+ // skip "\n"
157+ stream .skip (1 );
162158
163- // build datablock
164- value .dataBlock = new byte [value .bytes ];
165- stream .read (value .dataBlock );
159+ // build datablock
160+ value .dataBlock = new byte [value .bytes ];
161+ stream .read (value .dataBlock );
166162
167- // skip "\r\n"
168- stream .skip (2 );
163+ // skip "\r\n"
164+ stream .skip (2 );
169165
170- // check if it is the end.
171- stream .mark (0 );
172- stream .read (end );
173- if (Arrays .equals (end , B_END )) {
174- retvalue = value ;
175- break ;
176- } else {
177- stream .reset ();
178- }
179- if (i == 0 ) {
180- list = new LinkedList <Value >();
181- }
182- list .add (value );
183- i ++;
166+ // check if it is the end.
167+ stream .mark (0 );
168+ stream .read (end );
169+ if (Arrays .equals (end , B_END )) {
170+ retvalue = value ;
184171 }
185172 }
186173 }
0 commit comments