예제 #1
0
        public InputStreamReader(
			InputStream stream)
        {
            inStream = new System.IO.StreamReader(stream);
        }
예제 #2
0
파일: iobuff.cs 프로젝트: JordanChin/Ingres
        /*
        ** Name: close
        **
        ** Description:
        **	Close the associated I/O stream.
        **
        ** Input:
        **	None.
        **
        ** Output:
        **	None.
        **
        ** Returns:
        **	void
        **
        ** History:
        **	 9-Jun-99 (gordy)
        **	    Created.
        **	29-Sep-99 (gordy)
        **	    A recursive loop can occur if a flush fails, which
        **	    calls close() which calls flush(), etc.  Made sure
        **	    close() won't recurse by setting the closed flag
        **	    prior to calling flush().*/
        /// <summary>
        /// Close the associated I/O stream.
        /// </summary>
        public virtual void close()
        {
            lock(this)
            {
                if (!closed)
                {
                    closed = true;

                    if (inputStream != null)
                        try
                        {
                            inputStream.Close();
                        }
                        catch (Exception /* ignore */)
                        {
                        }

                    if (outputStream != null)
                    {
                        try
                        {
                            setSegSize();
                            flushBuffer(true);
                        }
                        catch (Exception /* ignore */)
                        {
                        }
                        try
                        {
                            outputStream.Close();
                        }
                        catch (Exception /* ignore */)
                        {
                        }
                    }

                    clearBuffer();
                    inputStream  = null;
                    outputStream = null;
                    if (trace.enabled(3))
                        trace.write(title + ": closed");
                }

                return ;
            }
        }
예제 #3
0
 /*
 ** Name: setBinaryStream
 **
 ** Description:
 **	Assign a byte stream as the data value.
 **	The data value will be NULL if the input
 **	value is null, otherwise non-NULL.
 **
 ** Input:
 **	value	Byte stream (may be null).
 **
 ** Output:
 **	None.
 **
 ** Returns:
 **	void.
 **
 ** History:
 **	 1-Dec-03 (gordy)
 **	    Created.
 */
 public override void setBinaryStream(InputStream value)
 {
     setStream(value);
     return;
 }
예제 #4
0
 /*
 ** Name: set
 **
 ** Description:
 **	Assign a new non-NULL data value.
 **
 ** Input:
 **	stream		The new data value.
 **
 ** Output:
 **	None.
 **
 ** Returns:
 **	void.
 **
 ** History:
 **	12-Sep-03 (gordy)
 **	    Created.
 */
 public void set( InputStream stream )
 {
     setStream(stream);
     return;
 }
예제 #5
0
파일: inbuff.cs 프로젝트: JordanChin/Ingres
        protected internal new ITrace trace; // DAM-TL tracing (overrides IoBuff)

        #endregion Fields

        #region Constructors

        /*
        ** Name: InBuff
        **
        ** Description:
        **	Class constructor.
        **
        ** Input:
        **	in	Associated input stream.
        **	id	Connection ID.
        **	size	Length of input buffer.
        **
        ** Output:
        **	None.
        **
        ** History:
        **	16-Jun-99 (gordy)
        **	    Created.
        */
        /// <summary>
        /// Allocate an input stream and its buffer.
        /// </summary>
        /// <param name="inputStream">Associated input stream.</param>
        /// <param name="id">Connection ID.</param>
        /// <param name="size">Length of input buffer.</param>
        public InBuff(InputStream inputStream, int id, int size)
            : base(inputStream)
        {
            title = "InBuff[" + id + "]";
            trace = new Tracing(DAM_TL_TRACE_ID);
            BuffSize = size;
        }
예제 #6
0
 /*
 ** Name: cnvtUnicode
 **
 ** Description:
 **	Helper method to convert Unicode stream into
 **	character stream.
 **
 ** Input:
 **	stream	Unicode stream to be converted.
 **
 ** Output:
 **	None.
 **
 ** Returns:
 **	Reader	Character stream.
 **
 ** History:
 **	 1-Dec-03 (gordy)
 **	    Created.
 */
 public static Reader cnvtUnicode(InputStream stream)
 {
     try { return (new InputStreamReader(stream, "UTF-8")); }
     catch (Exception)
     { throw SqlEx.get(ERR_GC401E_CHAR_ENCODE); }	// Should not happen!
 }
예제 #7
0
 /*
 ** Name: cnvtIS2Rdr
 **
 ** Description:
 **	Converts the byte string input stream into a Reader stream.
 **
 **	This class uses Reader streams, so implemented as stub.
 **
 ** Input:
 **	stream	    Input stream.
 **
 ** Output:
 **	None.
 **
 ** Returns:
 **	Reader		Converted Reader stream.
 **
 ** History:
 **	12-Sep-03 (gordy)
 */
 protected override Reader cnvtIS2Rdr( InputStream stream )
 {
     return( (Reader)null );	// Stub, should not be called.
 }
예제 #8
0
        /*
        ** Name: getISR
        **
        ** Description:
        **	Returns an InputStreamReader for input from provided stream
        **	and conversion using the associated encoding .
        **
        ** Input:
        **	stream		    InputStream to be converted.
        **
        ** Output:
        **	None.
        **
        ** Returns:
        **	InputStreamReader   Reader for encoding conversion of stream.
        **
        ** History:
        **	 6-Sep-02 (gordy)
        **	    Created.
        **	11-Nov-02 (thoda04)
        **	    Ported to .NET Provider.
        */
        public virtual InputStreamReader getISR(InputStream stream)
        {
            InputStreamReader isr;

            if (encoding == null)
                isr = new InputStreamReader(stream);
            else
                isr = new InputStreamReader(stream, encoding);

            return (isr);
        }
예제 #9
0
        /*
        ** Name: setUnicodeStream
        **
        ** Description:
        **	Set parameter to a Unicode character stream.
        **
        ** Input:
        **	paramIndex	Parameter index.
        **	stream		Unicode stream.
        **	length		Length of stream in bytes.
        **
        ** Output:
        **	None.
        **
        ** Returns:
        **	void
        **
        ** History:
        **	19-May-99 (gordy)
        **	    Created.
        **	 2-Feb-00 (gordy)
        **	    Send short streams as VARCHAR or VARBINARY.
        **	13-Jun-00 (gordy)
        **	    Map parameter index.
        **	 8-Jan-01 (gordy)
        **	    Stream classes moved to ParamSet.
        **	13-Jun-01 (gordy)
        **	    2.1 spec requires UTF-8 encoding for unicode streams.
        **	19-Feb-03 (gordy)
        **	    Check for alternate storage format.
        **	 1-Nov-03 (gordy)
        **	    ParamSet functionality extended.
        */
        public void setUnicodeStream( int paramIndex, InputStream stream, int length )
        {
            if ( trace.enabled() )  trace.log( title + ".setUnicodeStream( " +
                                        paramIndex + ", " + length + " )" );

            paramIndex = paramMap( paramIndex );
            paramSet.init(paramIndex, ProviderType.LongVarChar);
            paramSet.setUnicodeStream(paramIndex, stream);
            return;
        }
예제 #10
0
 /*
 ** Abstract Methods
 */
 protected virtual Reader cnvtIS2Rdr( InputStream stream )
 {
     throw new NotImplementedException("SqlStream.cnvtIS2Rdr impl missing.");
 }
예제 #11
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;
        }
예제 #12
0
 /*
 ** Name: BinIS2HexRdr
 **
 ** Description:
 **	Class constructor.
 **
 ** Input:
 **	stream		Input stream.
 **
 ** Output:
 **	None.
 **
 ** Returns:
 **	None.
 **
 ** History:
 **	12-Sep-03 (gordy)
 **	    Created.
 */
 public BinIS2HexRdr( InputStream stream )
     : base()
 {
     this.stream = stream;
 }
예제 #13
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 );
        }
예제 #14
0
 /*
 ** Name: cnvtIS2Rdr
 **
 ** Description:
 **	Converts the binary input stream into a Reader
 **	stream by converting to hex characters.
 **
 ** Input:
 **	stream	    Input stream.
 **
 ** Output:
 **	None.
 **
 ** Returns:
 **	Reader		Converted Reader stream.
 **
 ** History:
 **	12-Sep-03 (gordy)
 */
 protected override Reader cnvtIS2Rdr( InputStream stream )
 {
     return( new BinIS2HexRdr( stream ) );
 }
예제 #15
0
        public InputStreamReader(
			InputStream stream, System.Text.Encoding encoding)
        {
            inStream = new System.IO.StreamReader(stream, encoding);
        }
예제 #16
0
        /*
        ** Name: setAsciiStream
        **
        ** Description:
        **	Set parameter to an ASCII character stream.
        **
        ** Input:
        **	paramIndex	Parameter index.
        **	stream		ASCII stream.
        **	length		Length of stream in bytes.
        **
        ** Output:
        **	None.
        **
        ** Returns:
        **	void.
        **
        ** History:
        **	19-May-99 (gordy)
        **	    Created.
        **	 2-Feb-00 (gordy)
        **	    Send short streams as VARCHAR or VARBINARY.
        **	13-Jun-00 (gordy)
        **	    Map parameter index.
        **	 8-Jan-01 (gordy)
        **	    Stream classes moved to ParamSet.
        **	 1-Jun-01 (gordy)
        **	    No longer need wrapper class for Reader, so use
        **	    wrapper class to convert InputStream to Reader.
        **	19-Feb-03 (gordy)
        **	    Check for alternate storage format.
        **	 1-Nov-03 (gordy)
        **	    ParamSet functionality extended.
        **	14-Sep-05 (gordy)
        **	    If stream is short enough, save as VARCHAR.
        */
        public void setAsciiStream( int paramIndex, InputStream stream, int length )
        {
            if ( trace.enabled() )  trace.log( title + ".setAsciiStream( " +
                                        paramIndex + ", " + length + " )" );

            /*
            ** Check length to see if can be sent as VARCHAR.
            ** Ingres won't coerce CLOB to VARCHAR, but will
            ** coerce VARCHAR to CLOB, so VARCHAR is preferred.
            */
            if ( length >= 0  &&  length <= (conn.ucs2_supported ? conn.max_nvch_len
                                     : conn.max_vchr_len) )
            {
            char[]  chars = new char[ length ];

            if ( length > 0 )
                try
                {
                Reader	rdr = new InputStreamReader( stream, "US-ASCII" );
                int	len = rdr.read( chars );

                if ( len != length )
                {
                    /*
                    ** Character array limits read so any difference
                    ** must be a truncation.
                    */
                    if ( trace.enabled( 1 ) )
                    trace.write( tr_id + ".setAsciiStream: read only " +
                             len + " of " + length + " characters!" );
                    setWarning( DataTruncation( paramIndex, true,
                                    false, length, len ) );
                }
                }
                catch( IOException )
                { throw SqlEx.get( ERR_GC4007_BLOB_IO ); }

            paramIndex = paramMap( paramIndex );
            paramSet.init( paramIndex, ProviderType.VarChar );
            paramSet.setString( paramIndex, new String( chars ) );
            }
            else
            {
            paramIndex = paramMap( paramIndex );
            paramSet.init( paramIndex, ProviderType.LongVarChar );
            paramSet.setAsciiStream( paramIndex, stream );
            }

            return;
        }
예제 #17
0
        public InputStreamReader(
			InputStream stream, String charSetName)
        {
            System.Text.Encoding encoding;
            if (charSetName == "UTF-8")
                encoding = System.Text.Encoding.UTF8;
            else if (charSetName == "ASCII"  ||  charSetName == "US-ASCII" )
                encoding = System.Text.Encoding.ASCII;
            else throw new ArgumentOutOfRangeException(
                "charSetName", "Must be \"UTF-8\" or \"ASCII\".");

            inStream = new System.IO.StreamReader(stream, encoding);
        }
예제 #18
0
        /*
        ** Name: setBinaryStream
        **
        ** Description:
        **	Set parameter to a binary stream.
        **
        ** Input:
        **	paramIndex	Parameter index.
        **	stream		Binary stream.
        **	length		Length of stream in bytes.
        **
        ** Output:
        **	None.
        **
        ** Returns:
        **	void.
        **
        ** History:
        **	19-May-99 (gordy)
        **	    Created.
        **	 2-Feb-00 (gordy)
        **	    Send short streams as VARCHAR or VARBINARY.
        **	13-Jun-00 (gordy)
        **	    Map parameter index.
        **	 8-Jan-01 (gordy)
        **	    Stream classes moved to ParamSet.
        **	 1-Jun-01 (gordy)
        **	    No longer need wrapper class for binary InputStream.
        **	 1-Nov-03 (gordy)
        **	    ParamSet functionality extended.
        **	14-Sep-05 (gordy)
        **	    If stream is short enough, save as VARBINARY.
        */
        public void setBinaryStream( int paramIndex, InputStream stream, int length )
        {
            if ( trace.enabled() )  trace.log( title + ".setBinaryStream( " +
                                        paramIndex + ", " + length + " )" );

            /*
            ** Check length to see if can be sent as VARBINARY.
            ** Ingres won't coerce BLOB to VARBINARY, but will
            ** coerce VARBINARY to BLOB, so VARBINARY is preferred.
            */
            if ( length >= 0  &&  length <= conn.max_vbyt_len )
            {
            byte[]	bytes = new byte[ length ];

            if ( length > 0 )
                try
                {
                int len = stream.read( bytes );

                if ( len != length )
                {
                    /*
                    ** Byte array limits read so any difference
                    ** must be a truncation.
                    */
                    if ( trace.enabled( 1 ) )
                    trace.write( tr_id + ".setBinaryStream: read only " +
                             len + " of " + length + " bytes!" );
                    setWarning( DataTruncation( paramIndex, true,
                                    false, length, len ) );
                }
                }
                catch( IOException )
                { throw SqlEx.get( ERR_GC4007_BLOB_IO ); }

            paramIndex = paramMap( paramIndex );
            paramSet.init(paramIndex, ProviderType.VarBinary);
            paramSet.setBytes( paramIndex, bytes );
            }
            else
            {
            paramIndex = paramMap( paramIndex );
            paramSet.init(paramIndex, ProviderType.LongVarBinary);
            paramSet.setBinaryStream( paramIndex, stream );
            }

            return;
        }
예제 #19
0
 /*
 ** Name: setUnicodeStream
 **
 ** Description:
 **	Assign a Unicode stream as the data value.
 **	The data value will be NULL if the input
 **	value is null, otherwise non-NULL.
 **
 ** Input:
 **	value	Unicode stream (may be null).
 **
 ** Output:
 **	None.
 **
 ** Returns:
 **	void.
 **
 ** History:
 **	 1-Dec-03 (gordy)
 **	    Created.
 */
 public override void setUnicodeStream(InputStream value)
 {
     if (value == null)
         setNull();
     else
         setStream(cnvtUnicode(value));
     return;
 }
예제 #20
0
        /*
        ** Name: setUnicodeStream
        **
        ** Description:
        **	Set parameter to a Unicode stream.  If the parameter has not
        **	been initialized for a specific SQL type, the LONGVARCHAR type
        **	will be used.
        **
        ** Input:
        **	index	Parameter index.
        **	value	Unicode stream.
        **
        ** Output:
        **	None.
        **
        ** Returns:
        **	void.
        **
        ** History:
        **	 1-Dec-03 (gordy)
        **	    Created.
        */
        public void setUnicodeStream( int index, InputStream value )
        {
            Param param = check( index );

            lock( param )
            {
                if (param.value == null) set(param, ProviderType.LongVarChar,
                    useAltStorage( ProviderType .LongVarChar ) );

            param.value.setUnicodeStream( value );
            param.flags |= (ushort)(PS_FLG_SET | dflt_flags);
            }

            return;
        }
예제 #21
0
 /*
 ** Name: setAsciiStream
 **
 ** Description:
 **	Assign a ASCII stream as the data value.
 **	The data value will be NULL if the input
 **	value is null, otherwise non-NULL.
 **
 ** Input:
 **	value	ASCII stream (may be null).
 **
 ** Output:
 **	None.
 **
 ** Returns:
 **	void.
 **
 ** History:
 **	 1-Dec-03 (gordy)
 **	    Created.
 */
 public override void setAsciiStream(InputStream value)
 {
     if (value == null)
         setNull();
     else
         setStream(cnvtAscii(value));
     return;
 }
예제 #22
0
 public void updateBinaryStream( int index, InputStream inStream, int length )
 {
     if ( trace.enabled() )  trace.log( title + ".updateBinaryStream(" +
                                 index + "," + length + ")" );
 }
예제 #23
0
 /*
 ** Name: cnvtIS2Rdr
 **
 ** Description:
 **	Converts the byte string input stream into a Reader
 **	stream using the associated character-set.
 **
 ** Input:
 **	stream	    Input stream.
 **
 ** Output:
 **	None.
 **
 ** Returns:
 **	Reader		Converted Reader stream.
 **
 ** History:
 **	12-Sep-03 (gordy)
 */
 protected override Reader cnvtIS2Rdr( InputStream stream )
 {
     try
     {
         return( charSet.getISR( stream ) );
     }
     catch( Exception ex)			// Should not happen!
     {
         throw SqlEx.get( ERR_GC401E_CHAR_ENCODE, ex );
     }
 }
예제 #24
0
 public void updateBinaryStream( String name, InputStream inStream, int length )
 {
     updateBinaryStream( columnByName( name ), inStream, length );
 }
예제 #25
0
파일: iobuff.cs 프로젝트: JordanChin/Ingres
        private int seg_end; // End of current segment.

        #endregion Fields

        #region Constructors

        /*
        ** Name: IoBuff
        **
        ** Description:
        **	Class constructor for input buffers.  Sub-class must set
        **	buffer size to initialize the input buffer.
        **
        ** Input:
        **	ioStream  	The associated input/output stream.
        **	fileAccess	Read or Write to indicate direction of stream
        **
        ** Output:
        **	None.
        **
        ** History:
        **	 9-Jun-99 (gordy)
        **	    Created.
        **	28-Mar-01 (gordy)
        **	    Separated tracing interface and implementation.*/
        /// <summary>
        /// Class constructor for input buffers.  Sub-class must set
        /// buffer size to initialize the input buffer.
        /// </summary>
        /// <param name="inStream"></param>
        protected internal IoBuff(InputStream  inStream)
        {
            trace = new Tracing(DAM_NL_TRACE_ID);

                title = "IoBuff[in]";
                this.inputStream = inStream;
        }
예제 #26
0
 public virtual void setUnicodeStream(InputStream value)
 {
     throw SqlEx.get(ERR_GC401A_CONVERSION_ERR);
 }
예제 #27
0
파일: msgin.cs 프로젝트: JordanChin/Ingres
        /*
        ** Name: connect
        **
        ** Description:
        **	Establish connection with target server.  Initializes
        **	the input buffer.
        **
        ** Input:
        **	host	Host name or address.
        **	portID	Symbolic or numeric port ID.
        **
        ** Output:
        **	None.
        **
        ** Returns:
        **	void.
        **
        ** History:
        **	 7-Jun-99 (gordy)
        **	    Created.
        **	17-Nov-99 (gordy)
        **	    Extracted input functionality from DbConn.
        **	 3-Nov-08 (gordy, ported by thoda04)
        **	    Extracted from constructor.
        */
        protected internal override void connect(String host, String portID)
        {
            base.connect( host, portID );

            try
            {
                InputStream inputStream = new InputStream(socket.getInputStream());
                inBuff = new InBuff(inputStream, ConnID, 1 << DAM_TL_PKT_MIN);
            }
            catch (Exception ex)
            {
                if (trace.enabled(1))
                    trace.write(title + ": error creating input buffer: " +
                         ex.Message);
                disconnect();
                throw SqlEx.get(ERR_GC4001_CONNECT_ERR, ex);
            }

            return;
        }
예제 #28
0
        /*
        ** Name: write (inputStream)
        **
        ** Description:
        **	Append input stream to the output buffer.  This
        **	routine does not split buffers, the input stream
        **	is read until the buffer is filled or the stream
        **	is exhausted.  The number of bytes read from the
        **	input stream is returned.  It is the callers
        **	responsibility to assure that there is space
        **	available in the output buffer.
        **
        ** Input:
        **	inputStream	InputStream
        **
        ** Output:
        **	None.
        **
        ** Returns:
        **	short	Number of bytes written.
        **
        ** History:
        **	29-Sep-99 (gordy)
        **	    Created.
        */
        /// <summary>
        /// Append input stream to the output buffer.  This
        /// routine does not split buffers, the input stream
        /// is read until the buffer is filled or the stream
        /// is exhausted.  The number of bytes read from the
        /// input stream is returned.  It is the callers
        /// responsibility to assure that there is space
        /// available in the output buffer.
        /// </summary>
        /// <param name="inputStream"></param>
        /// <returns></returns>
        public virtual short write(InputStream inputStream)
        {
            int length = avail();

            try
            {
                length = inputStream.read(buffer, data_ptr, length);
            }
            catch (System.Exception ex)
            {
                throw SqlEx.get( ERR_GC4007_BLOB_IO, ex);
            }

            if (length < 0)
                length = 0;
            data_ptr += length;
            if (trace.enabled(5))
                trace.write(title + ": appending " + length);
            return ((short) length);
        }