Here you can find the source of writeBytesToStream(byte[] bytes, OutputStream os, boolean printStackTraceOnError)
Parameter | Description |
---|---|
bytes | the byte array to be written to the stream. |
os | the OutputStream to write the byte array to. |
printStackTraceOnError | specifies whether or not a stack trace is to be printed if an i/o error occurs. |
@SuppressWarnings({ "BooleanMethodNameMustStartWithQuestion" }) public static boolean writeBytesToStream(byte[] bytes, OutputStream os, boolean printStackTraceOnError)
//package com.java2s; //License from project: Apache License import java.io.*; public class Main { /**/* w w w . j a va2s. c om*/ * Write the contents of a byte array to an {@link OutputStream} without needing to worry about exceptions. * * @param bytes the byte array to be written to the stream. * @param os the {@link OutputStream} to write the byte array to. * @param printStackTraceOnError specifies whether or not a stack trace is to be printed if an i/o error occurs. * @return true if it worked, false otherwise. */ @SuppressWarnings({ "BooleanMethodNameMustStartWithQuestion" }) public static boolean writeBytesToStream(byte[] bytes, OutputStream os, boolean printStackTraceOnError) { try { os.write(bytes); return true; } catch (IOException e) { if (printStackTraceOnError) { //noinspection CallToPrintStackTrace e.printStackTrace(); } return false; } } }