Changed license to CC0
[svjatoslav_commons.git] / src / main / java / eu / svjatoslav / commons / data / EnhancedDataInputStream.java
1 /*
2  * Svjatoslav Commons - shared library of common functionality. Author: Svjatoslav Agejenko.
3  * This project is released under Creative Commons Zero (CC0) license.
4  */
5 package eu.svjatoslav.commons.data;
6
7 import java.io.DataInputStream;
8 import java.io.IOException;
9 import java.io.InputStream;
10 import java.util.ArrayList;
11 import java.util.List;
12
13 public class EnhancedDataInputStream extends DataInputStream {
14
15     public EnhancedDataInputStream(final InputStream in) {
16         super(in);
17     }
18
19     public List<Integer> readIntegerList() throws IOException {
20         final int length = readInt();
21
22         final List<Integer> result = new ArrayList<>();
23
24         for (int i = 0; i < length; i++)
25             result.add(readInt());
26
27         return result;
28     }
29
30     public String readString() throws IOException {
31
32         final int length = readInt();
33         if (length == -1)
34             return null;
35
36         final byte[] bytes = new byte[length];
37         readFully(bytes);
38
39         return new String(bytes, "UTF-8");
40     }
41
42 }