@@ -26,11 +26,17 @@ public class ArrayBufferInput
2626 implements MessageBufferInput
2727{
2828 private MessageBuffer buffer ;
29- private boolean isRead = false ;
29+ private boolean isEmpty ;
3030
3131 public ArrayBufferInput (MessageBuffer buf )
3232 {
33- this .buffer = checkNotNull (buf , "input buffer is null" );
33+ this .buffer = buf ;
34+ if (buf == null ) {
35+ isEmpty = true ;
36+ }
37+ else {
38+ isEmpty = false ;
39+ }
3440 }
3541
3642 public ArrayBufferInput (byte [] arr )
@@ -40,20 +46,25 @@ public ArrayBufferInput(byte[] arr)
4046
4147 public ArrayBufferInput (byte [] arr , int offset , int length )
4248 {
43- this (MessageBuffer .wrap (checkNotNull (arr , "input array is null" )). slice ( offset , length ));
49+ this (MessageBuffer .wrap (checkNotNull (arr , "input array is null" ), offset , length ));
4450 }
4551
4652 /**
47- * Reset buffer. This method doesn't close the old resource .
53+ * Reset buffer. This method returns the old buffer .
4854 *
49- * @param buf new buffer
50- * @return the old resource
55+ * @param buf new buffer. This can be null to make this input empty.
56+ * @return the old buffer.
5157 */
5258 public MessageBuffer reset (MessageBuffer buf )
5359 {
5460 MessageBuffer old = this .buffer ;
5561 this .buffer = buf ;
56- this .isRead = false ;
62+ if (buf == null ) {
63+ isEmpty = true ;
64+ }
65+ else {
66+ isEmpty = false ;
67+ }
5768 return old ;
5869 }
5970
@@ -64,17 +75,17 @@ public void reset(byte[] arr)
6475
6576 public void reset (byte [] arr , int offset , int len )
6677 {
67- reset (MessageBuffer .wrap (checkNotNull (arr , "input array is null" )). slice ( offset , len ));
78+ reset (MessageBuffer .wrap (checkNotNull (arr , "input array is null" ), offset , len ));
6879 }
6980
7081 @ Override
7182 public MessageBuffer next ()
7283 throws IOException
7384 {
74- if (isRead ) {
85+ if (isEmpty ) {
7586 return null ;
7687 }
77- isRead = true ;
88+ isEmpty = true ;
7889 return buffer ;
7990 }
8091
@@ -83,6 +94,6 @@ public void close()
8394 throws IOException
8495 {
8596 buffer = null ;
86- isRead = false ;
97+ isEmpty = true ;
8798 }
8899}
0 commit comments