luni, 4 mai 2015

[OmniFaces utilities 2.0] Read the given input stream into a byte array


[OmniFaces utilities] The toByteArray() method read the given input stream into a byte array. The given input stream will implicitly be closed after streaming, regardless of whether an exception is been thrown or not.

Method:
See also: Utils#stream() 
Usage:

import java.io.InputStream;
import org.omnifaces.util.Utils;
...
InputStream inputStream;
try {
    inputStream = new FileInputStream("input_file");
    byte[] allBytes = Utils.toByteArray(inputStream);
    // do something with the byte[]
} catch (IOException ex) {
    //
}

Niciun comentariu:

Trimiteți un comentariu