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: ,

Comments

# Systems Integration: No Assumptions

Monday, October 30, 2006 10:52 PM by DotNetKicks.com

You've been kicked (a good thing) - Trackback from DotNetKicks.com

# re: Systems Integration: No Assumptions

Tuesday, October 31, 2006 7:05 AM by royashbrook

       public static void nocr(string f)

       {

           string t;

           using (StreamReader r = new StreamReader(f))

       t = Regex.Replace(r.ReadToEnd(), "\r", "");

           using (StreamWriter w = new StreamWriter(f))

       w.Write(t);

       }

# replacing carriage return

Tuesday, October 31, 2006 5:44 PM by roy ashbrook

nothing fancy here, we're just doing a regex replace on \r and replacing it with nothing. this is a different