public InputStreamReader( InputStream stream) { inStream = new System.IO.StreamReader(stream); }
/* ** 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 ; } }
/* ** 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; }
/* ** 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; }
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; }
/* ** 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! }
/* ** 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. }
/* ** 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); }
/* ** 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; }
/* ** Abstract Methods */ protected virtual Reader cnvtIS2Rdr( InputStream stream ) { throw new NotImplementedException("SqlStream.cnvtIS2Rdr impl missing."); }
/* ** 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; }
/* ** 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; }
/* ** 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 ); }
/* ** 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 ) ); }
public InputStreamReader( InputStream stream, System.Text.Encoding encoding) { inStream = new System.IO.StreamReader(stream, encoding); }
/* ** 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; }
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); }
/* ** 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; }
/* ** 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; }
/* ** 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; }
/* ** 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; }
public void updateBinaryStream( int index, InputStream inStream, int length ) { if ( trace.enabled() ) trace.log( title + ".updateBinaryStream(" + index + "," + length + ")" ); }
/* ** 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 ); } }
public void updateBinaryStream( String name, InputStream inStream, int length ) { updateBinaryStream( columnByName( name ), inStream, length ); }
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; }
public virtual void setUnicodeStream(InputStream value) { throw SqlEx.get(ERR_GC401A_CONVERSION_ERR); }
/* ** 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; }
/* ** 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); }