File tree Expand file tree Collapse file tree
main/java/io/appulse/utils
test/java/io/appulse/utils Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -136,8 +136,12 @@ public byte[] array () {
136136 return Arrays .copyOfRange (buffer .array (), 0 , buffer .position ());
137137 }
138138
139- public int size () {
140- return buffer .position ();
139+ public int limit () {
140+ return buffer .limit ();
141+ }
142+
143+ public int remaining () {
144+ return buffer .remaining ();
141145 }
142146
143147 public int position () {
Original file line number Diff line number Diff line change @@ -88,4 +88,31 @@ public void array () {
8888 assertThat (bytes .array ())
8989 .isEqualTo (new byte [] { 1 , 2 });
9090 }
91+
92+ @ Test
93+ public void limit () {
94+ Bytes bytes = Bytes .allocate (2 );
95+ assertThat (bytes .limit ()).isEqualTo (2 );
96+
97+ bytes .put4B (4 );
98+ assertThat (bytes .limit ()).isEqualTo (4 );
99+
100+ Bytes wrapped = Bytes .wrap (new byte [] { 1 });
101+ assertThat (wrapped .limit ()).isEqualTo (1 );
102+ }
103+
104+ @ Test
105+ public void remaining () {
106+ Bytes bytes = Bytes .allocate (2 );
107+ assertThat (bytes .remaining ()).isEqualTo (2 );
108+
109+ bytes .put4B (4 );
110+ assertThat (bytes .remaining ()).isEqualTo (0 );
111+
112+ Bytes wrapped = Bytes .wrap (new byte [] { 1 });
113+ assertThat (wrapped .remaining ()).isEqualTo (0 );
114+
115+ wrapped .flip ();
116+ assertThat (wrapped .remaining ()).isEqualTo (1 );
117+ }
91118}
You can’t perform that action at this time.
0 commit comments