Changeset 13584 for trunk/sources/HeuristicLab.Problems.Instances.DataAnalysis/3.3/TableFileParser.cs
- Timestamp:
- 02/03/16 12:03:11 (8 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.Problems.Instances.DataAnalysis/3.3/TableFileParser.cs
r13526 r13584 28 28 using System.IO; 29 29 using System.Linq; 30 using System.Runtime;31 30 using System.Runtime.Serialization; 32 31 using System.Text; … … 41 40 private int estimatedNumberOfLines = 200; // initial capacity for columns, will be set automatically when data is read from a file 42 41 42 43 private Encoding encoding = Encoding.Default; 44 45 public Encoding Encoding { 46 get { return encoding; } 47 set { 48 if (value == null) throw new ArgumentNullException("Encoding"); 49 encoding = value; 50 } 51 } 52 53 43 54 private int rows; 44 55 public int Rows { … … 104 115 public bool AreColumnNamesInFirstLine(Stream stream, NumberFormatInfo numberFormat, 105 116 DateTimeFormatInfo dateTimeFormatInfo, char separator) { 106 using (StreamReader reader = new StreamReader(stream )) {117 using (StreamReader reader = new StreamReader(stream, Encoding)) { 107 118 tokenizer = new Tokenizer(reader, numberFormat, dateTimeFormatInfo, separator); 108 119 return (tokenizer.PeekType() != TokenTypeEnum.Double); … … 143 154 var len = new System.IO.FileInfo(fileName).Length; 144 155 var buf = new char[1024 * 1024]; 145 using (var reader = new StreamReader(fileName )) {156 using (var reader = new StreamReader(fileName, Encoding)) { 146 157 reader.ReadBlock(buf, 0, buf.Length); 147 158 } … … 187 198 /// <param name="columnNamesInFirstLine"></param> 188 199 public void Parse(Stream stream, NumberFormatInfo numberFormat, DateTimeFormatInfo dateTimeFormatInfo, char separator, bool columnNamesInFirstLine, int lineLimit = -1) { 189 using (StreamReader reader = new StreamReader(stream )) {200 using (StreamReader reader = new StreamReader(stream, Encoding)) { 190 201 tokenizer = new Tokenizer(reader, numberFormat, dateTimeFormatInfo, separator); 191 202 values = new List<IList>(); … … 408 419 .Where(c => OccurrencesOf(charCounts, c) > 10) 409 420 .OrderBy(c => -OccurrencesOf(charCounts, c)) 410 .DefaultIfEmpty(' ') 421 .DefaultIfEmpty(' ') 411 422 .First(); 412 423 } … … 505 516 try { 506 517 BytesRead = reader.BaseStream.Position; 507 } catch (IOException) { 518 } 519 catch (IOException) { 508 520 BytesRead += CurrentLine.Length + 2; // guess 509 } catch (NotSupportedException) { 521 } 522 catch (NotSupportedException) { 510 523 BytesRead += CurrentLine.Length + 2; 511 524 }
Note: See TracChangeset
for help on using the changeset viewer.