Create A Java Variable (String) of a specific size (MB's)
- by Bernie Perez
I am trying to benchmark some code. I am sending a String msg over sockets. I want to send 100KB, 2MB, and 10MB String variables. Is there an easy way to create a variable of these sizes?
Currently I am doing this.
private static String createDataSize(int msgSize) {
String data = "a";
while(data.length() < (msgSize*1024)-6) {
data += "a";
}
return data;
}
But this takes a very long time. Is there a better way?