I need to create a byte array with 100 bytes from a string. The length of the string is unknown but it is always less than 100 bytes. So if the string is 65 bytes then i need the array to be 35 zero bytes and then the String bytes to follow.
At the moment i have something like this, that does the job, but maybe something prettier and optimized is possible :)
String string = "asdf";
byte[] stringBytes = string.getBytes();
ByteArrayOutputStream outputStream = outputStream = new ByteArrayOutputStream();
outputStream.write(new byte[100 - stringBytes.length]);
outputStream.write(stringBytes);
byte[] result = outputStream.toByteArray();