Commit 3d142248 authored by David Feliot's avatar David Feliot
Browse files

JORAM-241: allows to write an array with offset and length.

parent 47063da3
......@@ -65,6 +65,15 @@ public class EncodableHelper {
return res;
}
public static final int getNullableByteArrayEncodedSize(byte[] byteArray,
int length) {
int res = Encodable.BYTE_ENCODED_SIZE;
if (byteArray != null) {
res += Encodable.INT_ENCODED_SIZE + length;
}
return res;
}
public static int getEncodedSize(Properties properties) throws Exception {
int res = Encodable.INT_ENCODED_SIZE;
Set<Entry<Object, Object>> entries = properties.entrySet();
......
......@@ -344,6 +344,24 @@ public final class StreamUtil {
os.write(tab);
}
}
/**
* This method allows to write byte array to the output stream.
*
* @param tab the byte array to write
* @param os the stream to write the object to
*/
public static void writeTo(byte[] tab, int offset, int length, OutputStream os)
throws IOException {
if (tab == null) {
writeTo(-1, os);
} else if (length == 0) {
writeTo(0, os);
} else {
writeTo(tab.length, os);
os.write(tab, offset, length);
}
}
/**
* This method allows to restore a byte array from the input stream.
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment