Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Output a byte stream to stdout

I have following function, which decrypts a base64 file and writes it to a txt file. However, instead of it writing to a text file, I want it to output to stdout. Can you please suggest how we could do that

CipherOutputStream cos = new CipherOutputStream(os, cipher);
    doCopy(is, cos);

}

public static void doCopy(InputStream is, OutputStream os) throws IOException {
    byte[] bytes = new byte[64];
    int numBytes;
    while ((numBytes = is.read(bytes)) != -1) {
        os.write(bytes, 0, numBytes);
    }

So instead of os.write writing the stream to a txt file, it should write it to stdout.

like image 350
brooding_goat Avatar asked Aug 27 '12 22:08

brooding_goat


1 Answers

PrintStream (class of stdout) has a write method which could be called to write a byte[] to stdout.

like image 189
Alden Avatar answered Sep 22 '22 22:09

Alden