Java Utililty Methods InputStream to File

List of utility methods to do InputStream to File

Description

The list of methods to do InputStream to File are organized into topic(s).

Method

voidwriteStreamToFile(File target, InputStream in)
First reads in all bytes fromt the stream into a byte buffer and then flushes them to file
try {
    byte[] byteArray = streamToByteArray(in);
    FileOutputStream fileOutputStream = new FileOutputStream(target);
    fileOutputStream.write(byteArray);
    fileOutputStream.flush();
    fileOutputStream.close();
} catch (IOException e) {
    throw new RuntimeException(e);
...
voidwriteStreamToFile(InputStream _actual, File _file)
write Stream To File
final OutputStream expected = new BufferedOutputStream(new FileOutputStream(_file));
try {
    int red;
    while ((red = _actual.read()) >= 0)
        expected.write(red);
} finally {
    expected.close();
voidwriteStreamToFile(InputStream in, OutputStream out)
write Stream To File
byte[] buffer = new byte[16384];
while (true) {
    int count = in.read(buffer);
    if (count < 0)
        break;
    out.write(buffer, 0, count);
in.close();
...
voidwriteStreamToFile(InputStream in, String fileName)
Writes a stream out to a file
try {
    FileOutputStream fos = new FileOutputStream(fileName);
    int ch;
    try {
        while (-1 != (ch = in.read())) {
            fos.write(ch);
    } catch (Exception e) {
...
voidwriteStreamToFile(InputStream inputStream, File file)
write Stream To File
FileOutputStream fout = new FileOutputStream(file);
copyStream(inputStream, fout);
fout.close();
voidwriteStreamToFile(InputStream inputStream, File targetFile)
Write a stream to a file
FileOutputStream out = new FileOutputStream(targetFile);
int count;
byte[] buffer = new byte[1024];
while (0 < (count = inputStream.read(buffer))) {
    out.write(buffer, 0, count);
FilewriteStreamToFile(InputStream inputStream, String extension)
write Stream To File
File file = File.createTempFile("file" + UUID.randomUUID(), "." + extension);
return writeStreamToFile(inputStream, extension, file);
voidwriteStreamToFile(InputStream is, File file)
write Stream To File
byte[] buffer = new byte[512];
BufferedOutputStream out = null;
try {
    try {
        out = new BufferedOutputStream(new FileOutputStream(file));
        while (true) {
            int read = is.read(buffer);
            if (read < 0) {
...
voidwriteStreamToFile(InputStream is, File out)
Writes a given InputStream to a file.
byte[] b;
try {
    FileOutputStream fos = new FileOutputStream(out);
    b = new byte[is.available()];
    for (int n; (n = is.read(b)) != -1;) {
        fos.write(b);
    fos.close();
...
voidwriteStreamToFile(InputStream is, File toFile)
Write InputStream to provided class.
OutputStream os = null;
try {
    os = new FileOutputStream(toFile);
    byte[] buffer = new byte[4096];
    for (int n; (n = is.read(buffer)) != -1;) {
        os.write(buffer, 0, n);
} finally {
...