Java OutputStream Write Byte Array writeBytes(byte[] data, OutputStream out)

Here you can find the source of writeBytes(byte[] data, OutputStream out)

Description

Writes a given bytes to a stream.

License

Open Source License

Parameter

Parameter Description
data Bytes.
out Stream.

Exception

Parameter Description
IOException If any I/O error occurs.

Declaration

public static void writeBytes(byte[] data, OutputStream out) throws IOException 

Method Source Code


//package com.java2s;
/* Util.java/*from  www  .  j  av a2s .  c  o m*/
 * 
 * Networking ME
 * Copyright (c) 2013 eMob Tech (http://www.emobtech.com/)
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in
 * all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 * THE SOFTWARE.
 */

import java.io.ByteArrayInputStream;

import java.io.IOException;

import java.io.OutputStream;

public class Main {
    /**
     * <p>
     * Writes a given bytes to a stream.
     * </p>
     * @param data Bytes.
     * @param out Stream.
     * @throws IOException If any I/O error occurs.
     */
    public static void writeBytes(byte[] data, OutputStream out) throws IOException {
        ByteArrayInputStream in = new ByteArrayInputStream(data);
        byte[] buffer = new byte[1024];
        //
        for (int n; (n = in.read(buffer)) > 0;) {
            out.write(buffer, 0, n);
        }
    }
}

Related

  1. writeBytes(byte[] data, OutputStream out)
  2. writeBytes(byte[] data, OutputStream stream)
  3. writeBytes(int[] data, OutputStream out)
  4. writeBytes(OutputStream os, byte[] b)
  5. writeBytes(OutputStream os, byte[] b)