Java File Save saveToInputStream(ByteArrayInputStream in, OutputStream out)

Here you can find the source of saveToInputStream(ByteArrayInputStream in, OutputStream out)

Description

save To Input Stream

License

MIT License

Declaration

public static void saveToInputStream(ByteArrayInputStream in, OutputStream out) 

Method Source Code


//package com.java2s;
/*/*w  ww .j  av a  2 s .  c  o  m*/
 * Protorabbit
 *
 * Copyright (c) 2009 Greg Murray (protorabbit.org)
 * 
 * Licensed under the MIT License:
 * 
 *  http://www.opensource.org/licenses/mit-license.php
 *
 */

import java.io.ByteArrayInputStream;

import java.io.OutputStream;

public class Main {
    public static void saveToInputStream(ByteArrayInputStream in, OutputStream out) {
        try {

            byte[] buffer = new byte[1024];
            int read = 0;
            while (true) {
                read = in.read(buffer);
                if (read <= 0)
                    break;
                out.write(buffer, 0, read);
            }
        } catch (Exception e) {
            System.out.println("IOUtil: error saving : " + e);
            e.printStackTrace();
        } finally {
            try {
                if (in != null) {
                    in.close();
                }
                if (out != null) {
                    out.flush();
                    out.close();
                }
            } catch (Exception e) {
            }
        }
    }
}

Related

  1. saveInputToOutput(InputStream is, OutputStream os)
  2. saveIntArray(int[] array, PrintStream out)
  3. SaveIntFile(int[] list, String filename)
  4. saveStreamAsString(InputStream is)
  5. saveStringDoubleMap(Map map, int dim, PrintStream out)
  6. saveTrecOneEntry(BufferedWriter trecFile, String topicId, String docId, int docPos, float score, String runId)