/// <exception cref="System.IO.IOException"/> private void ThrowExceptionOnError(string tag) { if (stream.CheckError()) { throw new IOException("Error serializing " + tag); } }
/// <summary>Copies from one stream to another.</summary> /// <param name="in">InputStrem to read from</param> /// <param name="out">OutputStream to write to</param> /// <param name="buffSize">the size of the buffer</param> /// <exception cref="System.IO.IOException"/> public static void CopyBytes(InputStream @in, OutputStream @out, int buffSize) { TextWriter ps = @out is TextWriter ? (TextWriter)@out : null; byte[] buf = new byte[buffSize]; int bytesRead = @in.Read(buf); while (bytesRead >= 0) { @out.Write(buf, 0, bytesRead); if ((ps != null) && ps.CheckError()) { throw new IOException("Unable to write to output stream."); } bytesRead = @in.Read(buf); } }