@@ -35,24 +35,9 @@ public class SerializationUtil {
3535 */
3636 public static int readPackedInt (ByteInputStream in ) throws IOException {
3737
38- if (in .isDirect ()) {
39- return readPackedIntDirect (in );
40- }
41- in .ensureCapacity (1 );
42- final int offset = in .getOffset ();
43- final byte [] array = in .array ();
44- final int len = PackedInteger .getReadSortedIntLength (array , offset );
45- /* move the offset past the integer; this also ensures length */
46- in .skip (len );
47- return PackedInteger .readSortedInt (array , offset );
48- }
49-
50- private static int readPackedIntDirect (ByteInputStream in )
51- throws IOException {
52-
5338 final byte [] bytes = new byte [PackedInteger .MAX_LENGTH ];
5439 in .readFully (bytes , 0 , 1 );
55- final int len = PackedInteger .getReadSortedIntLength (bytes , 0 );
40+ final int len = PackedInteger .getReadSortedIntLength (bytes [ 0 ] );
5641 try {
5742 in .readFully (bytes , 1 , len - 1 );
5843 } catch (IndexOutOfBoundsException e ) {
@@ -71,23 +56,8 @@ private static int readPackedIntDirect(ByteInputStream in)
7156 public static int skipPackedInt (ByteInputStream in )
7257 throws IOException {
7358
74- if (in .isDirect ()) {
75- return skipPackedIntDirect (in );
76- }
77- in .ensureCapacity (1 );
78- final int offset = in .getOffset ();
79- final byte [] array = in .array ();
80- final int len = PackedInteger .getReadSortedIntLength (array , offset );
81- /* move the offset past the integer; this also ensures length */
82- in .skip (len );
83- return len ;
84- }
85-
86- private static int skipPackedIntDirect (ByteInputStream in )
87- throws IOException {
88-
8959 byte b = in .readByte ();
90- int len = PackedInteger .getReadSortedIntLength (new byte []{ b }, 0 );
60+ int len = PackedInteger .getReadSortedIntLength (b );
9161 if (len > 1 ) {
9262 in .skip (len - 1 );
9363 }
@@ -105,20 +75,6 @@ private static int skipPackedIntDirect(ByteInputStream in)
10575 public static int writePackedInt (ByteOutputStream out , int value )
10676 throws IOException {
10777
108- if (out .isDirect ()) {
109- return writePackedIntDirect (out , value );
110- }
111- final int len = PackedInteger .getWriteSortedIntLength (value );
112- out .ensureCapacity (len );
113- final int offset = out .getOffset ();
114- final byte [] array = out .array ();
115- out .skip (len );
116- return PackedInteger .writeSortedInt (array , offset , value );
117- }
118-
119- public static int writePackedIntDirect (ByteOutputStream out , int value )
120- throws IOException {
121-
12278 final byte [] buf = new byte [PackedInteger .MAX_LENGTH ];
12379 final int offset = PackedInteger .writeSortedInt (buf , 0 , value );
12480 out .write (buf , 0 , offset );
@@ -134,25 +90,10 @@ public static int writePackedIntDirect(ByteOutputStream out, int value)
13490 */
13591 public static long readPackedLong (ByteInputStream in ) throws IOException {
13692
137- if (in .isDirect ()) {
138- return readPackedLongDirect (in );
139- }
140-
141- in .ensureCapacity (1 );
142- final int offset = in .getOffset ();
143- final byte [] array = in .array ();
144- final int len = PackedInteger .getReadSortedLongLength (array , offset );
145- /* move the offset past the integer; this also ensures length */
146- in .skip (len );
147- return PackedInteger .readSortedLong (array , offset );
148- }
149-
150- public static long readPackedLongDirect (ByteInputStream in )
151- throws IOException {
152-
15393 final byte [] bytes = new byte [PackedInteger .MAX_LONG_LENGTH ];
15494 in .readFully (bytes , 0 , 1 );
155- final int len = PackedInteger .getReadSortedLongLength (bytes , 0 );
95+ /* long and int store length the same way */
96+ final int len = PackedInteger .getReadSortedIntLength (bytes [0 ]);
15697 try {
15798 in .readFully (bytes , 1 , len - 1 );
15899 } catch (IndexOutOfBoundsException e ) {
@@ -184,21 +125,6 @@ public static int skipPackedLong(ByteInputStream in) throws IOException {
184125 public static int writePackedLong (ByteOutputStream out , long value )
185126 throws IOException {
186127
187- if (out .isDirect ()) {
188- return writePackedLongDirect (out , value );
189- }
190-
191- final int len = PackedInteger .getWriteSortedLongLength (value );
192- out .ensureCapacity (len );
193- final int offset = out .getOffset ();
194- final byte [] array = out .array ();
195- out .skip (len );
196- return PackedInteger .writeSortedLong (array , offset , value );
197- }
198-
199- public static int writePackedLongDirect (ByteOutputStream out , long value )
200- throws IOException {
201-
202128 final byte [] buf = new byte [PackedInteger .MAX_LONG_LENGTH ];
203129 final int offset = PackedInteger .writeSortedLong (buf , 0 , value );
204130 out .write (buf , 0 , offset );
@@ -285,18 +211,10 @@ private static String readStdUTF8String(ByteInputStream in)
285211 return EMPTY_STRING ;
286212 }
287213
288- if (in .isDirect ()) {
289- final byte [] bytes = new byte [length ];
290- in .readFully (bytes );
291- return StandardCharsets .UTF_8 .decode (
292- ByteBuffer .wrap (bytes )).toString ();
293- } else {
294- final byte [] bytes = in .array ();
295- int offset = in .getOffset ();
296- in .skip (length );
297- return StandardCharsets .UTF_8 .decode (
298- ByteBuffer .wrap (bytes , offset , length )).toString ();
299- }
214+ final byte [] bytes = new byte [length ];
215+ in .readFully (bytes );
216+ return StandardCharsets .UTF_8 .decode (
217+ ByteBuffer .wrap (bytes )).toString ();
300218 }
301219
302220 /**
0 commit comments