How to use IOUtils.toString(). [jira-software]

org.apache.commons.io.FileUtils.copyFile(source,dest);     
Runtime rt =  Runtime.getRuntime();
Process proc =rt.exec(append);
BufferedInputStream stdInput = new BufferedInputStream(proc.getInputStream());
int read=0;
byte[] output = new byte[1024];
String strFile = null;
while ((read = stdInput.read(output)) != -1) 
    {
        strFile+=new String(output,0,read);
        System.out.println(output[read]);
    }
String message = org.apache.commons.io.IOUtils.toString(stdInput); ///error

IOUtils.toString() is not working and returning null value. I am using Jira 7.13.0.

That’s likely because you’re manually reading the input stream into the strFile variable until it’s closed AND THEN try to read it with IOUtils.toString. The way that input streams work in Java, you can’t read something again when you’ve already read it.

Please try something like this instead:

Runtime rt =  Runtime.getRuntime();
Process proc =rt.exec(append);
BufferedInputStream stdInput = new BufferedInputStream(proc.getInputStream());
String message = org.apache.commons.io.IOUtils.toString(stdInput);
1 Like

This code is working thank you for help me.

1 Like