int numPackets = (line.length()-1)/mtu + 1;
byte[][] packets = new byte[numPackets][mtu];
try {
byte[] data = line.getBytes("UTF-8");
// The last packet will normally not fill a complete MTU
for (int i = 0; i < numPackets-1; i++) {
System.arraycopy(data, i*mtu, packets[i], 0, mtu );
}
System.arraycopy(data, (numPackets-1)*mtu, packets[numPackets-1],
0, data.length - ((numPackets-1)*mtu) );
return packets;
}
catch (UnsupportedEncodingException ex) {
throw new RuntimeException("Broken VM does not support UTF-8");
}