Monday, October 30, 2006 10:51 PM
dbottjer
Systems Integration: No Assumptions
There are many sayings about assumptions and I’ll let you fill in your favorite. Regarding Systems Integration, the hard lesson I’ve learned is not to assume the other system will properly filter or handle a specific constraint. For example, Windows systems use a carriage-return-line-feed to mark the end-of-a-line. However, UNIX systems simply use a line-feed to mark the end-of-a-line. This is not to say that UNIX systems can’t handle files containing CRLF’s. It just means that most UNIX Systems just use an LF to mark the end-of-a-line.
When writing code to integrate a Windows based system and a UNIX based system that transfers data through a file based feed, noting and handling this simple end-of-line difference can save much time and yes stress. Having a simple tool like NotePad2 in your arsenal is a great way to inspect your feed at various stages to ensure compatibility between the systems.
NotePad2 (http://www.flos-freeware.ch/notepad2.html) is a small, powerful replacement editor for “NotePad” which comes with Microsoft Windows. This tool is worth a look especially for its ability to show hidden characters such as those marking the end-of-line.
To handle the case described above I would recommend implementing a simple scrubber that removes carriage returns (CR's) from the end of each line before sending the file to the UNIX System. Here is an example scrubber:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
using System.IO; using System.Text.RegularExpressions;
public class UnixStripperActivity { public static void SripCarriageReturn(string filePath) { string output; FileStream fs = File.OpenRead(filePath); StreamReader reader = new StreamReader(fs); string input = reader.ReadToEnd(); reader.Close(); fs.Close(); output = Regex.Replace(input, @"\r", "", RegexOptions.Multiline); FileStream fsw = File.OpenWrite(filePath); StreamWriter sw = new StreamWriter(fsw); sw.Write(output); sw.Close(); fsw.Close(); } } |
Filed under: Architecture, System Integration