示例#1
0
        copyIs2Os(InputStream inputStream, OutputStream outputStream)
        {
            if (bbuff == null)
            {
                lock (this)
                {
                    { if (bbuff == null)
                      {
                          bbuff = new byte[8192];
                      }
                    }
                }
            }

            try
            {
                lock (bbuff)
                {
                    for (int len = inputStream.read(bbuff); len >= 0;
                         len = inputStream.read(bbuff))
                    {
                        outputStream.write(bbuff, 0, len);
                    }
                }

                inputStream.close();
                outputStream.flush();
            }
            catch (Exception ex)
            {
                try { inputStream.close(); }
                catch (Exception /* ignore */) { }
                try { outputStream.flush(); }
                catch (Exception /* ignore */) { }
                throw SqlEx.get(ERR_GC4007_BLOB_IO, ex);
            }

            return;
        }         // copyIs2Os
示例#2
0
        strm2array(InputStream inStream, int limit)
        {
            byte[] buff = new byte[8192];
            byte[] ba   = new byte[0];
            int    len;

            try
            {
                while ((limit < 0 || ba.Length < limit) &&
                       (len = inStream.read(buff, 0, buff.Length)) >= 0)
                {
                    if (limit >= 0)
                    {
                        len = Math.Min(len, limit - ba.Length);
                    }
                    byte[] tmp = new byte[ba.Length + len];
                    if (ba.Length > 0)
                    {
                        Array.Copy(ba, 0, tmp, 0, ba.Length);
                    }
                    if (len > 0)
                    {
                        Array.Copy(buff, 0, tmp, ba.Length, len);
                    }
                    ba = tmp;
                }
            }
            catch (Exception)
            {
                throw SqlEx.get(ERR_GC4007_BLOB_IO);
            }
            finally
            {
                try { inStream.close(); }
                catch (Exception) {}
            }

            return(ba);
        }         // strm2array
示例#3
0
        /*
        ** Name: copyIs2Os
        **
        ** Description:
        **	Writes the contents of an InputStream to an OutputStream.
        **	The InputStream is closed.  The OutputStream is flushed
        **	but not closed.
        **
        ** Input:
        **	is	InputStream.
        **	os	OutputStream.
        **
        ** Output:
        **	None.
        **
        ** Returns:
        **	void.
        **
        ** History:
        **	 1-Dec-03 (gordy)
        **	    Created.
        */
        protected void copyIs2Os(InputStream inputStream, OutputStream outputStream)
        {
            if (bbuff == null)
                lock (this)
                {
                    { if (bbuff == null)  bbuff = new byte[8192]; }
                }

            try
            {
                lock (bbuff)
                {
                    for (int len = inputStream.read(bbuff); len >= 0;
                        len = inputStream.read(bbuff))
                        outputStream.write(bbuff, 0, len);
                }

                inputStream.close();
                outputStream.flush();
            }
            catch (Exception ex)
            {
                try { inputStream.close(); }
                catch (Exception /* ignore */) { }
                try { outputStream.flush(); }
                catch (Exception /* ignore */) { }
                throw SqlEx.get(ERR_GC4007_BLOB_IO, ex);
            }

            return;
        }
示例#4
0
 close()
 {
     stream.close();
     base.close();
     return;
 } // close
示例#5
0
        /*
        ** Name: strm2array
        **
        ** Description:
        **	Read a binary input stream and convert to a byte array.
        **	The stream is closed.
        **
        ** Input:
        **	in	Binary input stream.
        **	limit	Maximum length of result, negative for no limit.
        **
        ** Output:
        **	None.
        **
        ** Returns:
        **	byte[]	The stream as a byte array.
        **
        ** History:
        **	12-Sep-03 (gordy)
        **	    Created.
        */
        private static byte[] strm2array( InputStream inStream, int limit )
        {
            byte[]	buff = new byte[ 8192 ];
            byte[]	ba   = new byte[ 0 ];
            int		len;

            try
            {
                while( (limit < 0  ||  ba.Length < limit)  &&
                    (len = inStream.read( buff, 0, buff.Length )) >= 0 )
                {
                    if ( limit >= 0 )  len = Math.Min( len, limit - ba.Length );
                    byte[] tmp = new byte[ ba.Length + len ];
                    if ( ba.Length > 0 )  Array.Copy( ba, 0, tmp, 0, ba.Length );
                    if ( len > 0 )  Array.Copy( buff, 0, tmp, ba.Length, len );
                    ba = tmp;
                }
            }
            catch( Exception )
            {
                throw SqlEx.get( ERR_GC4007_BLOB_IO );
            }
            finally
            {
                try { inStream.close(); }
                catch( Exception ) {}
            }

            return( ba );
        }