C# Class Azavea.NijPredictivePolicing.Common.Data.CommaSeparatedValueWriter

A basic implementation of the IDataWriter interface, so we can simply export CSV files. Should be compliant with RFC4180 ( http://tools.ietf.org/html/rfc4180 ).
Inheritance: IDataFileWriter
Datei anzeigen Open project: azavea/acs-alchemist Class Usage Examples

Protected Properties

Property Type Description
_filename string
_line StringBuilder
_outputStream System.IO.StreamWriter
_splitChars char[]

Public Methods

Method Description
Close ( ) : bool

closes the underlying stream

CommaSeparatedValueWriter ( ) : System

construct a new blank writer (any writes will throw exceptions if you don't set a stream or a file!)

CommaSeparatedValueWriter ( string filename ) : System

construct a new writer to append to the given file

CreateTable ( string tablename, IEnumerable columns ) : bool

simply appends the column row. call this first! (you would have to call this first anyway.)

Flush ( ) : bool

flushes the stream

QuoteAndEscape ( string input ) : string

If input contains ,s or newlines, escapes all "s and brackets in "s and returns the result, otherwise returns input unmodified

SetTablename ( string tableName ) : void

changes the currently active table, does nothing for this type of file, since it only contains one table.

SetWriteFile ( string filename ) : bool

specify an output file for APPENDing to, and sharing reading. (if you don't like it, send in your own filestream :)

WriteLine ( IEnumerable values ) : bool

Make sure you have a value for every column! This is really intentionally not thread safe, do not share this class across threads. really, don't write one of these files across multiple threads at the same time.

WriteLine ( string line ) : bool

Write a line directly to our output

Method Details

Close() public method

closes the underlying stream
public Close ( ) : bool
return bool

CommaSeparatedValueWriter() public method

construct a new blank writer (any writes will throw exceptions if you don't set a stream or a file!)
public CommaSeparatedValueWriter ( ) : System
return System

CommaSeparatedValueWriter() public method

construct a new writer to append to the given file
public CommaSeparatedValueWriter ( string filename ) : System
filename string
return System

CreateTable() public method

simply appends the column row. call this first! (you would have to call this first anyway.)
public CreateTable ( string tablename, IEnumerable columns ) : bool
tablename string
columns IEnumerable
return bool

Flush() public method

flushes the stream
public Flush ( ) : bool
return bool

QuoteAndEscape() public method

If input contains ,s or newlines, escapes all "s and brackets in "s and returns the result, otherwise returns input unmodified
public QuoteAndEscape ( string input ) : string
input string The string to escape and quote (if necessary)
return string

SetTablename() public method

changes the currently active table, does nothing for this type of file, since it only contains one table.
public SetTablename ( string tableName ) : void
tableName string
return void

SetWriteFile() public method

specify an output file for APPENDing to, and sharing reading. (if you don't like it, send in your own filestream :)
public SetWriteFile ( string filename ) : bool
filename string
return bool

WriteLine() public method

Make sure you have a value for every column! This is really intentionally not thread safe, do not share this class across threads. really, don't write one of these files across multiple threads at the same time.
public WriteLine ( IEnumerable values ) : bool
values IEnumerable
return bool

WriteLine() public method

Write a line directly to our output
public WriteLine ( string line ) : bool
line string
return bool

Property Details

_filename protected_oe property

an internal copy of our filename
protected string _filename
return string

_line protected_oe property

our buffer for constructing lines
protected StringBuilder _line
return StringBuilder

_outputStream protected_oe property

our wrapper around any provided stream
protected StreamWriter,System.IO _outputStream
return System.IO.StreamWriter

_splitChars protected_oe property

the tab, for the tab-separated part
protected char[] _splitChars
return char[]