In process of converting a variable of Data Type InputStreamReader (stdout) into String (s) I am reading few characters of 'stdout' at a time through 'ca' and appending it to 's'. However since the data to be read is too long, I think after some time the storing variable reaches its limit and stops appending data onto it. So the truncated result is being shown on the CLI.
It's essential for the whole output to be stored together so as to parse it afterwards in the remaining code. Below is the code snippet
def lastRead = System.currentTimeMillis()
def s = ''
def lastStdout = 0
def ca = new char[4096]
while (true)
{
int len
while (stdout.ready() && (len = stdout.read(ca)) > 0)
{
//trace.severe(CliConnection.class, s)
s = s + new String(ca, 0, len)
//trace.severe(CliConnection.class, ca)
lastRead = System.currentTimeMillis()
}
s = config.stdoutFilters.inject(s.normalize()) { t, filter -> filter(t) }
//trace.info(CliConnection.class, "In loop: >>${s}<<")
if (options.stdout && s.length() > lastStdout) {
//trace.info(CliConnection.class, s)
options.stdout(s.substring(lastStdout))
lastStdout = s.length()
}
if (stop(s, lastRead))
break
// wait for certain period to get the date correctly
// default is 100 if it is set under 100
def iodelay = (getIOdelay() > 100) ? getIOdelay() : 100
Thread.sleep(iodelay)
}
In the given code, the variable ca keeps on reading further data but it doesn't append on to the variable s. So it throws no error, just truncates the output data. Is there a way to overcome the problem or some other method that can be tried instead?