Beispiel #1
0
        /*
        ** Name: setCharacterStream
        **
        ** Description:
        **	Set parameter to a character stream.
        **
        ** Input:
        **	paramIndex	Parameter index.
        **	reader		Character stream.
        **	length		Length of stream in bytes.
        **
        ** Output:
        **	None.
        **
        ** Returns:
        **	void.
        **
        ** History:
        **	 2-Nov-00 (gordy)
        **	    Created.
        **	 8-Jan-01 (gordy)
        **	    Stream classes moved to ParamSet.
        **	 1-Jun-01 (gordy)
        **	    No longer need wrapper class for 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 setCharacterStream( int paramIndex, Reader reader, int length )
        {
            if ( trace.enabled() )  trace.log( title + ".setCharacterStream( " +
                                        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
                {
                int	len = reader.read( chars );

                if ( len != length )
                {
                    /*
                    ** Character array limits read so any difference
                    ** must be a truncation.
                    */
                    if ( trace.enabled( 1 ) )
                    trace.write( tr_id + ".setCharacterStream: 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.setCharacterStream( paramIndex, reader );
            }

            return;
        }
Beispiel #2
0
        /*
        ** Name: strm2str
        **
        ** Description:
        **	Read a character input stream and convert to a string object.
        **	The stream is closed.
        **
        ** Input:
        **	in	Character input stream.
        **	limit	Maximum size of result, negative for no limit
        **
        ** Output:
        **	None.
        **
        ** Returns:
        **	String	The stream as a string.
        **
        ** History:
        **	12-Sep-03 (gordy)
        **	    Created.
        */
        private static String strm2str( Reader inReader, int limit )
        {
            char[]           cb = new char[ 8192 ];
            StringBuilder    sb = new StringBuilder();
            int              len;

            try
            {
                while( (limit < 0  ||  sb.Length < limit)  &&
                    (len = inReader.read( cb, 0, cb.Length )) >= 0 )
                {
                    if ( limit >= 0 )  len = Math.Min( len, limit - sb.Length );
                    if ( len > 0 )  sb.Append( cb, 0, len );
                }
            }
            catch( IOException )
            {
                throw SqlEx.get( ERR_GC4007_BLOB_IO );
            }
            finally
            {
                try { inReader.close(); }
                catch( IOException ) {}
            }

            return( sb.ToString() );
        }
Beispiel #3
0
        /*
        ** Name: coyRdr2Wtr
        **
        ** Description:
        **	Writes the contents of a Reader stream to a Writer stream.
        **	The Reader stream is closed.  The Writer stream is flushed
        **	but not closed.
        **
        ** Input:
        **	rdr	Reader stream.
        **	wtr	Writer stream.
        **
        ** Output:
        **	None.
        **
        ** Returns:
        **	void.
        **
        ** History:
        **	 1-Dec-03 (gordy)
        **	    Created.
        */
        protected void copyRdr2Wtr(Reader rdr, Writer wtr)
        {
            if (cbuff == null)
                lock (this)
                {
                    { if (cbuff == null)  cbuff = new char[4096]; }
                }

            try
            {
                lock (cbuff)
                {
                    for (int len = rdr.read(cbuff); len >= 0; len = rdr.read(cbuff))
                        wtr.write(cbuff, 0, len);
                }

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

            return;
        }