Changed license to CC0
[svjatoslav_commons.git] / src / main / java / eu / svjatoslav / commons / data / EnhancedDataOutputStream.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.DataOutputStream;
8 import java.io.IOException;
9 import java.io.OutputStream;
10 import java.util.List;
11
12 public class EnhancedDataOutputStream extends DataOutputStream {
13
14     public EnhancedDataOutputStream(final OutputStream out) {
15         super(out);
16     }
17
18     public void writeIntegerList(final List<Integer> list) throws IOException {
19         writeInt(list.size());
20
21         for (final Integer integer : list)
22             writeInt(integer);
23     }
24
25     public void writeString(final String string) throws IOException {
26         if (string == null) {
27             writeInt(-1);
28             return;
29         }
30
31         final byte[] bytes = string.getBytes("UTF-8");
32
33         writeInt(bytes.length);
34         write(bytes);
35     }
36
37 }