Java OutputStream Write Byte Array writeBytesToStream(byte[] bytes, OutputStream outputStream)

Here you can find the source of writeBytesToStream(byte[] bytes, OutputStream outputStream)

Description

Writes given bytes array to given outputStream.

License

Open Source License

Declaration

public static void writeBytesToStream(byte[] bytes, OutputStream outputStream) throws IOException 

Method Source Code

//package com.java2s;
/*******************************************************************************
 * Copyright (c) 2007, 2014 Bruno Medeiros and other Contributors.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors://from w w  w.  j  a  va 2  s. co  m
 *     Bruno Medeiros - initial implementation
 *******************************************************************************/

import java.io.BufferedOutputStream;

import java.io.IOException;

import java.io.OutputStream;

public class Main {
    /** Writes given bytes array to given outputStream. 
     * Closes outputStream afterwards. */
    public static void writeBytesToStream(byte[] bytes, OutputStream outputStream) throws IOException {
        // A BufferedOutputStream is likely not necessary since this is a one-time array write
        BufferedOutputStream bos = new BufferedOutputStream(outputStream);
        try {
            bos.write(bytes);
        } finally {
            bos.close();
        }
    }
}

Related

  1. writeBytes(OutputStream os, byte[] b)
  2. writeBytes(OutputStream out, byte[] data)
  3. writeBytes(OutputStream output, Object value)
  4. writeBytes(OutputStream outputStream, byte[] data)
  5. writeBytesToStream(byte[] bytes, OutputStream os, boolean printStackTraceOnError)
  6. writeBytesToStream(byte[] data, OutputStream os)