473,387 Members | 1,520 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

unbuffered file IO?

Is there a class in the framework that allows me read text from a file
in an unbuffered manner? That is, I'd like to be able to read lines in
the same manner as StreamReader.ReadLine(), but I also need to be able
to accurately get the position in the file of that line. Since
StreamReader and FileStream both buffer data, you can't equate the
BaseStream.Position with the data you're reading from the stream.

Lee Crabtree
Aug 14 '07 #1
19 5340
I don't think there is in framework but you can easily create one.

Extend "TextReader" to create your own reader and use BufferedStream for
buffering the base stream (bufferedstream's Position property returns the
position based on buffers so you can get accurate position.).

"Lee Crabtree" <lc*******@goisi.comwrote in message
news:Ok**************@TK2MSFTNGP02.phx.gbl...
Is there a class in the framework that allows me read text from a file in
an unbuffered manner? That is, I'd like to be able to read lines in the
same manner as StreamReader.ReadLine(), but I also need to be able to
accurately get the position in the file of that line. Since StreamReader
and FileStream both buffer data, you can't equate the BaseStream.Position
with the data you're reading from the stream.

Lee Crabtree
Aug 14 '07 #2
Im Finishing up a class where i store all the line offsets based on some end
of line....been testing it with 1million plus row files works pretty ..you
can prob look and see what im doing and make ur own class

What i do
I have a LONG[] array for storing line offsets, createt before i read the
file... so there is not a lot of resizing (copy) 1 to create the array
and 1 Resize (copy) when done reading the row Offsetts

Im still new to c# so comments on the code are welcome also...
reply and i'll paste the code here
MJ
"Lee Crabtree" <lc*******@goisi.comwrote in message
news:Ok**************@TK2MSFTNGP02.phx.gbl...
Is there a class in the framework that allows me read text from a file in
an unbuffered manner? That is, I'd like to be able to read lines in the
same manner as StreamReader.ReadLine(), but I also need to be able to
accurately get the position in the file of that line. Since StreamReader
and FileStream both buffer data, you can't equate the BaseStream.Position
with the data you're reading from the stream.

Lee Crabtree

Aug 14 '07 #3
Yeah, I'd like to see how you handled that. Could be educational.

Lee Crabtree
Aug 14 '07 #4
Okay, thanks. I wasn't sure if I was just reading over something that
would handle it in my searches of the System.IO namespace.

Lee Crabtree
Aug 14 '07 #5
Lee Crabtree wrote:
Is there a class in the framework that allows me read text from a file
in an unbuffered manner? That is, I'd like to be able to read lines in
the same manner as StreamReader.ReadLine(), but I also need to be able
to accurately get the position in the file of that line. Since
StreamReader and FileStream both buffer data, you can't equate the
BaseStream.Position with the data you're reading from the stream.
That's not true. While they both buffer data, StreamReader and
FileStream don't buffer in a way that is observably identical. In
particular, the Stream.Position property will in fact tell you where you
are with respect to reading the FileStream class. It won't necessarily
tell what data has already read from disk, but it does tell you what
position in the file is the next to be read when you call a method that
reads data.

So, you could use FileStream directly rather than going through a
StreamReader, and that would provide what you want. You'd have to do
your own character encoding stuff, but the Encoding class should make
that relatively simple.

Pete
Aug 14 '07 #6
Wow, I can't believe I didn't catch that. Thanks. I REALLY didn't want
to have to write and debug a whole class just to do this.

Lee Crabtree
Aug 14 '07 #7
make a While loop

ofs = TextFileServer("somefile")
string srow
while (ofs=false)
{
srow=ofs.getRow();
Console.Writeline(srow);
}

below is the actual class have fun just copy and past it should work ok
for ya
its also work in progress
using System;
using System.IO;

using System.Text;
using System.Windows.Forms;
using System.Data;
public class TextFileServer
{

protected object[,] _aStru;
private object[] _aColumns; //text row broke up into columns
private int _ColumnCount=0; // column count
private string _Delimiter; //column delimiter
// private long iReccount;
private String _FileName;

protected string _cEol; //end of line

private long _Fsize; //File size
private FileStream _Fs; //file stream
private long[] _aOffsets; //array of row offsets

private byte[] aBytes; // for Reading Rows uses in
GetRow
protected int nRecordLen; // how long is a record
(line)
private long iRecno; //current Record number
protected string cRecord; //actual Row (columns not
removed)

private bool _RemoveQuotes = true;
private int _FixedRowSize=0; //fixed Bytes to Read

private int CombinedColumnLength;

/// <summary>
/// Base Constructure if used
/// filename and all reqired parameters must be set up by user
/// then call BeginRead()
/// </summary>
public TextFileServer()
{
this._ColumnCount = 0;//this._aStru.GetLength(0);
this.CombinedColumnLength = 0; //78;
}
/// <summary>
///
/// </summary>
/// <param name="FileName"></param>
public TextFileServer(string FileName)
{

this._FileName = FileName;
this._cEol = "\r\n";
this.BeginRead();
}
/// <summary>
/// File name and End of line Marker String
/// </summary>
/// <param name="FileName"></param>
/// <param name="ceol"></param>
public TextFileServer(string FileName,string ceol)
{

this._FileName = FileName;
this._cEol = ceol;
this.BeginRead();

}
/// <summary>
/// Filename and Array of Structure
/// ColumnName, Type, Length, Decimal
/// object[] 2 Dimensional
/// </summary>
/// <param name="FileName"></param>
/// <param name="aStru"></param>
public TextFileServer(string FileName, object[,] aStru)
{

this.Structure= aStru;
this._FileName = FileName;
this.BeginRead();

}
/// <summary>
/// filename
/// Structure for columns object[] 2 dimensional Name,type,length,dec
/// column Delimiter string
/// </summary>
/// <param name="FileName"></param>
/// <param name="aStru"></param>
/// <param name="delimiter"></param>
public TextFileServer(string FileName, object[,] aStru,string delimiter)
{

this._aStru = aStru;
this._Delimiter = delimiter;
this._FileName = FileName;
this.BeginRead();
}
public TextFileServer(string FileName, int FixedRecordLen)
{

this._FixedRowSize=FixedRecordLen;
this.nRecordLen = this._FixedRowSize;
this._cEol = null;

this._FileName = FileName;
this.BeginRead();

}
/// <summary>
/// Call this if you Construct class TextFileServer()
/// the other constructors call this themselves
/// </summary>
public void BeginRead()
{

this.CombinedColumnLength = 0; //78;
this._Fs= new FileStream(this._FileName, FileMode.Open,
FileAccess.Read, FileShare.ReadWrite);
//this._Fs = dvFileIO.FileOpen(this._FileName);
/*
if (! (this._aStru == null))
{
this._ColumnCount = this._aStru.GetLength(0);
this._aColumns = new object[this._ColumnCount];
for (int x = 0; x < this._ColumnCount; x++)
{
this.CombinedColumnLength += (int)this._aStru[x, 2];

}
}
*/
//find end of line markers

if (this._cEol == null) this._cEol = "\r\n";
//get line information
this.FindEol();
//this.FileName = FileName;
// this._cEol = cEol;
// this.nEol = cEol.Length;
//open file
//oFs = new FileStream(this.FileName, FileMode.Open,
FileAccess.Read);
//get filesize
this._Fsize = this._Fs.Seek(0, SeekOrigin.End);
//move back to the top
this._Fs.Seek(0, SeekOrigin.Begin);
this.iRecno = 0;
//this.iBytes2Read = this.nRecordLen;
/*
for (int x = 0; x < aStru.GetLength(0); x++)
{
this.iBytes2Read+= (Int32)aStru[x,2];
}
*/
// add to buffer if not fixed width
/*
if (cEol != "")
{

this.iBytes2Read = this.nRecordLen + 100; // add 100 bytes to
make sure we read enough
}
*/
this.LoadOffSets();
}
//------------------------
/// <summary>
/// Finds End of line Markers in Files and reads a few lines to
determine a possible
/// widest line in file
/// </summary>
public void FindEol()
{
this._Fs.Seek(0, SeekOrigin.Begin);
string cBuffer;
int npos;
byte[] aBytes = new byte[255];
char[] Sep = new Char[] { ' ' };
long iBytesRead;
iBytesRead = this._Fs.Read(aBytes, 0, aBytes.Length);
// we have a buffer with more than 1 line find eol and keep the
longest line
cBuffer = ASCIIEncoding.ASCII.GetString(aBytes);
this._Fs.Seek(0, SeekOrigin.Begin);
//End of line built from constructor or user manual
if ((npos = cBuffer.IndexOf(this._cEol)) 0)
{
//default just get Recordlen
Sep = this._cEol.ToCharArray();
}
//below this point is all known endof line markers based on No
//end of line marker set during constructor

else if ((npos = cBuffer.IndexOf("\r\n")) 0) //13/10
{
this._cEol = "\r\n";

Sep = new char[] { '\r', '\n' };
}
else if ((npos = cBuffer.IndexOf("\r")) 0) //13 only
{

this._cEol = "\r";

Sep = new char[] { '\r' };
}
else if ((npos = cBuffer.IndexOf("\n")) 0) //10 only
{

this._cEol = "\n";

Sep = new char[] { '\n' };
}
else if ((npos = cBuffer.IndexOf("~")) 0) //ansi files
{
this._cEol = "~";

this.nRecordLen = 106;
npos = -1;

}
// no end of line markers found set to a fixed length hope for the
bst
else
{
npos = -1;
this._cEol = "";

this.nRecordLen = 78;
}
//find the longest line from the Buffer we read in
if (npos 0)
{
string[] ainfo = cBuffer.Split(Sep);
this.nRecordLen = 0;
for (int x = 0; x < ainfo.Length; x++)
{
if (ainfo[x].Length this.nRecordLen)
{
this.nRecordLen = ainfo[x].Length;
}
}
}
//check astru (combinded column lengthes vs nrecordlen)
if (this.CombinedColumnLength>=this.nRecordLen)
{
this.nRecordLen=this.CombinedColumnLength;
}

}

/// <summary>
/// this is the workhorse it loads all the end of line byte positions
/// from the file into the _aoffsets long[] array
/// </summary>
public void LoadOffSets()
{
// get filesize

long iSeekBytes;
int iBytes2Read;
long iBytesRead;

int ipos;
int iWidest; // widest row in file
string oBufferIn="";
// this.ctrlz = (char)26; //ctrl_z end of file marker for some files

//this.iBytes2Read=1024;
long nCntr;
long nOffset;
iSeekBytes = 0;
//aproximate how many array elements we need
// i want more than required always, so there is only 2 resizes
//1st = create the long[], 2nd = Resize back to what was needed
//take recordlen and devide by 6 , take that rusult subtract it from
recordlen
int i=0;
int r=0;
long nSize=0;

if (this._FixedRowSize==0)
{
i = (this.nRecordLen / 6); //-50;

r = this.nRecordLen -i ;
nSize = this._Fsize / r;
iBytes2Read = this.nRecordLen + (this.nRecordLen / 2);

}
else
{
this.nRecordLen=this._FixedRowSize;
nSize = this._Fsize / this.nRecordLen;
iBytes2Read = this.nRecordLen;
}
// empty file this just stops crash...oops
if (nSize <= 0)
{
nSize = 1;

}

//long nSize =
this.Fsize/(this.iBytes2Read-Math.Min(this.iBytes2Read,this.iBytes2Read/4));
Console.WriteLine(DateTime.Now.ToString()+" Array Size " +
nSize.ToString()+" Bytes2Read "+iBytes2Read.ToString());

this._aOffsets = new long[nSize];

byte[] aReadBytes =new Byte[iBytes2Read];

nCntr = 0;
iSeekBytes = 0;

this._aOffsets[nCntr] = 0;
iWidest = 0; //holds the widest row in the file;
ipos = 0;
long nCr = 0;

while ((iBytesRead = this._Fs.Read(aReadBytes, 0, iBytes2Read)) 0)
{

if ((nCntr % 5000) == 0)
{
Application.DoEvents();
}
oBufferIn = UTF8Encoding.ASCII.GetString(aReadBytes);

//ALWAYS FIND END OF LINE UNLESS THIS HAS A VALUE GREATER THAN
ZERO

//class Not Constructed with fixed Size rows
if (this._FixedRowSize ==0)
{
ipos = oBufferIn.IndexOf(this._cEol);
//check if embedded chr 10 is in the file as line feeds

if ((ipos 0) && (oBufferIn.IndexOf("\n") == 0))
{
iSeekBytes += 1;
}
else if (ipos 0)
{
nCr++;
// oBufferOut = oBufferIn.Substring(0, ipos - 1);
iSeekBytes += ipos + (this._cEol.Length) ; //nEol);
//get past chr(10)
// Console.ReadKey();
}

else
{
// oBufferOut = oBufferIn;
iSeekBytes += oBufferIn.Length;
ipos = oBufferIn.Length;
}
}
//we have fixed Row Size
else
{

iSeekBytes += oBufferIn.Length;
ipos = oBufferIn.Length;

}
//grab the offset noffset
nOffset = (long)this._Fs.Seek(iSeekBytes, SeekOrigin.Begin);
// *********************************************
// save the widest row ipos is where endof line found
if (ipos>0 && iWidest<ipos) iWidest=ipos;
// *********************************************
// count Rows
nCntr++;
//set the offset to the array element the else part of the if
should never happend
//but somtimes it will we have to add a new element to the
arrary (resize)
if (nCntr < nSize) // use nsize instead of property -Length
this._aOffsets.Length)
{
this._aOffsets[nCntr] = nOffset;
}
else
{
nSize++;
Array.Resize(ref this._aOffsets,this._aOffsets.Length + 1);
this._aOffsets[nCntr] = nOffset;
}


// Console.ReadKey();
}

// resize the Array to actual Size Needed
if (nCntr < this._aOffsets.Length)
{

Array.Resize(ref this._aOffsets, (int)nCntr);

}

Console.WriteLine(DateTime.Now.ToString()+" Alen " +
this._aOffsets.Length.ToString());
//load a 1st row and columns
//set Widest Row base on local variable
if (this._FixedRowSize == 0 && this.CombinedColumnLength < iWidest)
{
this.CombinedColumnLength = iWidest;
}
else
{
this.CombinedColumnLength = this._FixedRowSize;
}
this.iRecno = this._aOffsets.Length - 1;

} // method
/// <summary>
/// Set filename if Constructed with no params
/// </summary>
public string Filename
{
set
{
this._FileName = value;

}
get
{
return this._FileName;
}
}
/// <summary>
/// Set the End of Line marker
/// use when construction witn no params
/// </summary>
public string Crlf
{

set
{
this._cEol = value;
}
}
/// <summary>
/// Delimiter use for Column Delimiter
/// </summary>
public string Delimiter
{

set
{
if (value == "")
{
this._Delimiter = null;
// this.FixedSize = true;
}
else
{
this._Delimiter = value;
}
}
}
/// <summary>
/// Sets up the Properties for a Column Structure based on a object[]
/// Name,type,length,dec
/// 2 dimensional array {{"name","C",20,0},
/// {"Id","N",10,0}}
///
/// </summary>
public object Structure
{
set
{
this._aStru=(object[,])value;
if (!(this._aStru == null))
{
this._ColumnCount = this._aStru.GetLength(0);
this._aColumns = new object[this._ColumnCount];
for (int x = 0; x < this._ColumnCount; x++)
{
this.CombinedColumnLength += (int)this._aStru[x, 2];

}
}
}
get
{
return this._aStru;
}

}
/// <summary>
/// Some Files to be parsed based on colums have or may not have Quoted
Character columns
/// i Default to Remove Quotes true
/// </summary>
public bool StripQuotes
{

set
{

this._RemoveQuotes = value;
}
}
/// <summary>
/// Returns column count based on Array structure
/// </summary>
public int ColumnCount
{
get
{

return this._ColumnCount;
}
set
{
this._ColumnCount = value;
}
}
/// <summary>
/// Set a Fixed Row Size
/// </summary>
public int FixedRowSize
{
set
{
this._FixedRowSize=value;
}
}
/// <summary>
/// Check for End of File should be used external with While loop
/// </summary>
public bool Eof
{
get
{
if (this.iRecno >= (this._aOffsets.Length))
{

return true;
}

return false;
}
}
/// <summary>
/// check for beginning of file
/// </summary>
public bool Bof
{
get
{
if (this.iRecno < 0)
{
this.iRecno = 0;
return true;
}
return false;

}
}
/// <summary>
/// Moves to Next Row in file
/// </summary>
/// <returns></returns>
public long Skip()
{
return this.Skip(1);
}
/// <summary>
/// Moves to Next Row in File use this instead of Skip
/// </summary>
/// <param name="n2Skip"></param>
/// <returns></returns>
public long Skip(int n2Skip)
{

if (n2Skip >= 0)
{
this.iRecno += n2Skip;
}
else
{
long iRec = Math.Abs(n2Skip);
this.iRecno -= iRec;
}

return this.iRecno;

}
public long GoTop()
{

this.iRecno = 0;
return this.iRecno;

}
/// <summary>
/// go to specified row pos in a file
/// </summary>
/// <param name="Recno"></param>
/// <returns></returns>
public long GoTo(long Recno)
{
if (Recno (this._aOffsets.Length - 1))
{
this.iRecno = this._aOffsets.Length - 1;
}
else
{
this.iRecno = (Recno-1);
}
return this.iRecno;
}
/// <summary>
/// get current row position in file
/// </summary>
public long RowNum
{
get
{
return iRecno+1;
}
}
/// <summary>
/// go to last row in file
/// </summary>
/// <returns></returns>
public long GoBottom()
{

this.iRecno = this._aOffsets.Length - 1;
return this.iRecno;
}
/// <summary>
/// total count of rows in file
/// </summary>
/// <returns></returns>
public long RowCount()
{
return this._aOffsets.Length;
}

/// <summary>
/// Getrow does the actually reading of 1 row from the table
/// if columns are set then they will be created also
/// </summary>
/// <returns></returns>
public string GetRow()
{

long nStart=this._aOffsets[iRecno];
//byte[] aReadBytes;

this._Fs.Seek(this._aOffsets[this.iRecno], SeekOrigin.Begin);
int nCnt=0;

//if (this.iRecno==0)
//{
// nCnt = (int)(this._aOffsets[this.iRecno + 1] -
this._aOffsets[this.iRecno]);
// nCnt-=1;
// aReadBytes = new Byte[nCnt];
// this._Fs.Read(aReadBytes, 0, nCnt - 1);
//}
if (this.iRecno>-1 && (this.iRecno<this._aOffsets.Length-1))
{
nCnt = (int)(this._aOffsets[this.iRecno + 1] -
this._aOffsets[this.iRecno]);
nCnt -= 1;
this.aBytes = new Byte[nCnt];
this._Fs.Read(this.aBytes, 0, nCnt - 1);
this.cRecord = UTF8Encoding.ASCII.GetString(this.aBytes);
}
else
{
//last row in file
nCnt = this.CombinedColumnLength; //this.nRecordLen - 1;
//nCnt = this.iBytes2Read-1;
aBytes = new Byte[nCnt];
this._Fs.Read(this.aBytes, 0, nCnt - 1);
this.cRecord = UTF8Encoding.ASCII.GetString(this.aBytes);
this.cRecord = this.cRecord.Substring(0,
this.cRecord.IndexOf(this._cEol) - 1);

}
// byte[] aReadBytes = new Byte[nCnt];
// this._Fs.Read(aReadBytes, 0, nCnt-1);
//this.cRecord = UTF8Encoding.ASCII.GetString(this.aBytes);
//pad the record to meet column specifications if columns Specified
if (this._ColumnCount 0)
{
this.cRecord = this.cRecord.PadRight(this.CombinedColumnLength);
// fill the Columns
//************************************************** *******

int npos = 0;
int x = 0;

if (this._Delimiter == null)
{
for (x = 0; x < this._ColumnCount; x++)
{
this._aColumns[x] = this.cRecord.Substring(npos,
(int)this._aStru[x, 2]);

npos += (int)this._aStru[x, 2];

}

}
else
{
npos = 0;
int nSplit = 0;
string cCol = "";
string cRow;
if (this._RemoveQuotes)
{
cRow = this.cRecord.Replace('"', ' ');
}
else
{
cRow = this.cRecord;
}
for (x = 0; x < this.ColumnCount; x++)
{
nSplit = cRow.IndexOf(this._Delimiter);

if (nSplit == -1) // last column
{
cCol = cRow.Substring(0);
}
else
{
cCol = cRow.Substring(0, nSplit);

cRow = cRow.Replace(cCol + this._Delimiter, "");
}

cCol = cCol.Trim();

this._aColumns[x] = cCol.PadRight((int)this._aStru[x,
2], ' ');

}
}
}
//
************************************************** ***************************

return this.cRecord;
}

/// <summary>
/// Retrieve a Column by Column Position
/// </summary>
/// <param name="nPos"></param>
/// <returns></returns>
public object ColumnGet(int nPos)
{

return (this.ColumnGet(this._aStru[nPos, 0].ToString()));
}
/// <summary>
/// Gets column Position bye column Name
/// </summary>
/// <param name="cName"></param>
/// <returns></returns>
public object ColumnGet(string cName)
{
int x;
object oRet = null;

for (x = 0; x < this.ColumnCount; x++)
{

if (this._aStru[x, 0].ToString() == cName.ToString())
{

oRet = this._aColumns[x];
}
}

return oRet;
}
public void Close()
{
this._aOffsets = null;
this._Fs.Close();
}
} //fileserver
public static class dvConsole
{
public static void Print(object line2Print)
{
Console.WriteLine(line2Print);

}

public static void PrintCR(object line2Print)
{
Console.WriteLine(line2Print);
Console.ReadKey();
}
}
Aug 14 '07 #8
MikeJ <ve***********@sbcglobal.netwrote:
make a While loop

ofs = TextFileServer("somefile")
string srow
while (ofs=false)
{
srow=ofs.getRow();
Console.Writeline(srow);
}
It's still very unclear what your actual question is, and your code
above won't compile (there aren't enough semi-colons).

Could you try again?

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
Aug 14 '07 #9
Joe
Just curious...any reason why you can't use File.ReadAllLines(string
fileName) and just use the index of the line in the resulting string[]
as the position of the line in the file?

Thanks,
~Joe
Aug 14 '07 #10
it Compiles just Fine ..somthing Cut off the Lines on Remarks to cause the
SemiColon Problems

MJ
I'll try Again
example

fserver= new TextFileServer("SomeFile.txt")
fserver.GoTop()
string crow
while (fserver.eof==false)
{
cRow=fserver.getrow()
Console.WriteLine(crow);
}

below is actual class
looks like it pasted correctly this time

using System;
using System.IO;

using System.Text;
using System.Windows.Forms;
using System.Data;
namespace NetTools
{

/// <summary>
/// Malipulates Rows in a textfile stores the row offsets so a text file
/// can be treated like a table methods below, skip,goto,getrow,
columns, etc
/// </summary>

public class TextFileServer
{

protected object[,] _aStru;
private object[] _aColumns; //text row broke up into columns
private int _ColumnCount = 0; // column count
private string _Delimiter; //column delimiter
// private long iReccount;
private String _FileName;

protected string _cEol; //end of line

private long _Fsize; //File size
private FileStream _Fs; //file stream
private long[] _aOffsets; //array of row offsets

private byte[] aBytes; // for Reading Rows
uses in GetRow
protected int nRecordLen; // how long is a record
(line)
private long iRecno; //current Record number
protected string cRecord; //actual Row (columns not
removed)

private bool _RemoveQuotes = true;
private int _FixedRowSize = 0; //fixed Bytes to Read

private int CombinedColumnLength;

/// <summary>
/// Base Constructure if used
/// filename and all reqired parameters must be set up by user
/// then call BeginRead()
/// </summary>
public TextFileServer()
{
this._ColumnCount = 0;//this._aStru.GetLength(0);
this.CombinedColumnLength = 0; //78;
}
/// <summary>
///
/// </summary>
/// <param name="FileName"></param>
public TextFileServer(string FileName)
{

this._FileName = FileName;
this._cEol = "\r\n";
this.BeginRead();
}
/// <summary>
/// File name and End of line Marker String
/// </summary>
/// <param name="FileName"></param>
/// <param name="ceol"></param>
public TextFileServer(string FileName, string ceol)
{

this._FileName = FileName;
this._cEol = ceol;
this.BeginRead();

}
/// <summary>
/// Filename and Array of Structure
/// ColumnName, Type, Length, Decimal
/// object[] 2 Dimensional
/// </summary>
/// <param name="FileName"></param>
/// <param name="aStru"></param>
public TextFileServer(string FileName, object[,] aStru)
{

this.Structure = aStru;
this._FileName = FileName;
this.BeginRead();

}
/// <summary>
/// filename
/// Structure for columns object[] 2 dimensional
Name,type,length,dec
/// column Delimiter string
/// </summary>
/// <param name="FileName"></param>
/// <param name="aStru"></param>
/// <param name="delimiter"></param>
public TextFileServer(string FileName, object[,] aStru, string
delimiter)
{

this._aStru = aStru;
this._Delimiter = delimiter;
this._FileName = FileName;
this.BeginRead();
}
public TextFileServer(string FileName, int FixedRecordLen)
{

this._FixedRowSize = FixedRecordLen;
this.nRecordLen = this._FixedRowSize;
this._cEol = null;

this._FileName = FileName;
this.BeginRead();

}
/// <summary>
/// Call this if you Construct class TextFileServer()
/// the other constructors call this themselves
/// </summary>
public void BeginRead()
{

this.CombinedColumnLength = 0; //78;
this._Fs = new FileStream(this._FileName, FileMode.Open,
FileAccess.Read, FileShare.ReadWrite);
//this._Fs = dvFileIO.FileOpen(this._FileName);
/*
if (! (this._aStru == null))
{
this._ColumnCount = this._aStru.GetLength(0);
this._aColumns = new object[this._ColumnCount];
for (int x = 0; x < this._ColumnCount; x++)
{
this.CombinedColumnLength += (int)this._aStru[x, 2];

}
}
*/
//find end of line markers

if (this._cEol == null) this._cEol = "\r\n";
//get line information
this.FindEol();
//this.FileName = FileName;
// this._cEol = cEol;
// this.nEol = cEol.Length;
//open file
//oFs = new FileStream(this.FileName, FileMode.Open,
FileAccess.Read);
//get filesize
this._Fsize = this._Fs.Seek(0, SeekOrigin.End);
//move back to the top
this._Fs.Seek(0, SeekOrigin.Begin);
this.iRecno = 0;
//this.iBytes2Read = this.nRecordLen;
/*
for (int x = 0; x < aStru.GetLength(0); x++)
{
this.iBytes2Read+= (Int32)aStru[x,2];
}
*/
// add to buffer if not fixed width
/*
if (cEol != "")
{

this.iBytes2Read = this.nRecordLen + 100; // add 100 bytes
to make sure we read enough
}
*/
this.LoadOffSets();
}
//------------------------
/// <summary>
/// Finds End of line Markers in Files and reads a few lines to
determine a possible
/// widest line in file
/// </summary>
public void FindEol()
{
this._Fs.Seek(0, SeekOrigin.Begin);
string cBuffer;
int npos;
byte[] aBytes = new byte[255];
char[] Sep = new Char[] { ' ' };
long iBytesRead;
iBytesRead = this._Fs.Read(aBytes, 0, aBytes.Length);
// we have a buffer with more than 1 line find eol and keep the
longest line
cBuffer = ASCIIEncoding.ASCII.GetString(aBytes);
this._Fs.Seek(0, SeekOrigin.Begin);
//End of line built from constructor or user manual
if ((npos = cBuffer.IndexOf(this._cEol)) 0)
{
//default just get Recordlen
Sep = this._cEol.ToCharArray();
}
//below this point is all known endof line markers based on No
//end of line marker set during constructor

else if ((npos = cBuffer.IndexOf("\r\n")) 0) //13/10
{
this._cEol = "\r\n";

Sep = new char[] { '\r', '\n' };
}
else if ((npos = cBuffer.IndexOf("\r")) 0) //13 only
{

this._cEol = "\r";

Sep = new char[] { '\r' };
}
else if ((npos = cBuffer.IndexOf("\n")) 0) //10 only
{

this._cEol = "\n";

Sep = new char[] { '\n' };
}
else if ((npos = cBuffer.IndexOf("~")) 0) //ansi files
{
this._cEol = "~";

this.nRecordLen = 106;
npos = -1;

}
// no end of line markers found set to a fixed length hope for
the bst
else
{
npos = -1;
this._cEol = "";

this.nRecordLen = 78;
}
//find the longest line from the Buffer we read in
if (npos 0)
{
string[] ainfo = cBuffer.Split(Sep);
this.nRecordLen = 0;
for (int x = 0; x < ainfo.Length; x++)
{
if (ainfo[x].Length this.nRecordLen)
{
this.nRecordLen = ainfo[x].Length;
}
}
}
//check astru (combinded column lengthes vs nrecordlen)
if (this.CombinedColumnLength >= this.nRecordLen)
{
this.nRecordLen = this.CombinedColumnLength;
}

}

/// <summary>
/// this is the workhorse it loads all the end of line byte
positions
/// from the file into the _aoffsets long[] array
/// </summary>
public void LoadOffSets()
{
// get filesize

long iSeekBytes;
int iBytes2Read;
long iBytesRead;

int ipos;
int iWidest; // widest row in file
string oBufferIn = "";
// this.ctrlz = (char)26; //ctrl_z end of file marker for some
files

//this.iBytes2Read=1024;
long nCntr;
long nOffset;
iSeekBytes = 0;
//aproximate how many array elements we need
// i want more than required always, so there is only 2 resizes
//1st = create the long[], 2nd = Resize back to what was needed
//take recordlen and devide by 6 , take that rusult subtract it
from recordlen
int i = 0;
int r = 0;
long nSize = 0;

if (this._FixedRowSize == 0)
{
i = (this.nRecordLen / 6); //-50;

r = this.nRecordLen - i;
nSize = this._Fsize / r;
iBytes2Read = this.nRecordLen + (this.nRecordLen / 2);

}
else
{
this.nRecordLen = this._FixedRowSize;
nSize = this._Fsize / this.nRecordLen;
iBytes2Read = this.nRecordLen;
}
// empty file this just stops crash...oops
if (nSize <= 0)
{
nSize = 1;

}

//long nSize =
this.Fsize/(this.iBytes2Read-Math.Min(this.iBytes2Read,this.iBytes2Read/4));
// Console.WriteLine(DateTime.Now.ToString() + " Array Size " +
nSize.ToString() + " Bytes2Read " + iBytes2Read.ToString());

this._aOffsets = new long[nSize];

byte[] aReadBytes = new Byte[iBytes2Read];

nCntr = 0;
iSeekBytes = 0;

this._aOffsets[nCntr] = 0;
iWidest = 0; //holds the widest row in the file;
ipos = 0;
long nCr = 0;

while ((iBytesRead = this._Fs.Read(aReadBytes, 0, iBytes2Read))
0)
{

if ((nCntr % 5000) == 0)
{
Application.DoEvents();
}
oBufferIn = UTF8Encoding.ASCII.GetString(aReadBytes);

//ALWAYS FIND END OF LINE UNLESS THIS HAS A VALUE GREATER
THAN ZERO

//class Not Constructed with fixed Size rows
if (this._FixedRowSize == 0)
{
ipos = oBufferIn.IndexOf(this._cEol);
//check if embedded chr 10 is in the file as line feeds

if ((ipos 0) && (oBufferIn.IndexOf("\n") == 0))
{
iSeekBytes += 1;
}
else if (ipos 0)
{
nCr++;
// oBufferOut = oBufferIn.Substring(0, ipos - 1);
iSeekBytes += ipos + (this._cEol.Length); //nEol);
//get past chr(10)
// Console.ReadKey();
}

else
{
// oBufferOut = oBufferIn;
iSeekBytes += oBufferIn.Length;
ipos = oBufferIn.Length;
}
}
//we have fixed Row Size
else
{

iSeekBytes += oBufferIn.Length;
ipos = oBufferIn.Length;

}
//grab the offset noffset
nOffset = (long)this._Fs.Seek(iSeekBytes, SeekOrigin.Begin);
// *********************************************
// save the widest row ipos is where endof line found
if (ipos 0 && iWidest < ipos) iWidest = ipos;
// *********************************************
// count Rows
nCntr++;
//set the offset to the array element the else part of the
if should never happend
//but somtimes it will we have to add a new element to the
arrary (resize)
if (nCntr < nSize) // use nsize instead of property ->
Length this._aOffsets.Length)
{
this._aOffsets[nCntr] = nOffset;
}
else
{
nSize++;
Array.Resize(ref this._aOffsets, this._aOffsets.Length +
1);
this._aOffsets[nCntr] = nOffset;
}


// Console.ReadKey();
}

// resize the Array to actual Size Needed
if (nCntr < this._aOffsets.Length)
{

Array.Resize(ref this._aOffsets, (int)nCntr);

}

//Console.WriteLine(DateTime.Now.ToString() + " Alen " +
this._aOffsets.Length.ToString());
//load a 1st row and columns
//set Widest Row base on local variable
if (this._FixedRowSize == 0 && this.CombinedColumnLength <
iWidest)
{
this.CombinedColumnLength = iWidest;
}
else
{
this.CombinedColumnLength = this._FixedRowSize;
}
this.iRecno = this._aOffsets.Length - 1;

} // method
/// <summary>
/// Set filename if Constructed with no params
/// </summary>
public string Filename
{
set
{
this._FileName = value;

}
get
{
return this._FileName;
}
}
/// <summary>
/// Set the End of Line marker
/// use when construction witn no params
/// </summary>
public string Crlf
{

set
{
this._cEol = value;
}
}
/// <summary>
/// Delimiter use for Column Delimiter
/// </summary>
public string Delimiter
{

set
{
if (value == "")
{
this._Delimiter = null;
// this.FixedSize = true;
}
else
{
this._Delimiter = value;
}
}
}
/// <summary>
/// Sets up the Properties for a Column Structure based on a
object[]
/// Name,type,length,dec
/// 2 dimensional array {{"name","C",20,0},
/// {"Id","N",10,0}}
///
/// </summary>
public object Structure
{
set
{
this._aStru = (object[,])value;
if (!(this._aStru == null))
{
this._ColumnCount = this._aStru.GetLength(0);
this._aColumns = new object[this._ColumnCount];
for (int x = 0; x < this._ColumnCount; x++)
{
this.CombinedColumnLength += (int)this._aStru[x, 2];

}
}
}
get
{
return this._aStru;
}

}
/// <summary>
/// Some Files to be parsed based on colums have or may not have
Quoted Character columns
/// i Default to Remove Quotes true
/// </summary>
public bool StripQuotes
{

set
{

this._RemoveQuotes = value;
}
}
/// <summary>
/// Returns column count based on Array structure
/// </summary>
public int ColumnCount
{
get
{

return this._ColumnCount;
}
set
{
this._ColumnCount = value;
}
}
/// <summary>
/// Set a Fixed Row Size
/// </summary>
public int FixedRowSize
{
set
{
this._FixedRowSize = value;
}
}
/// <summary>
/// Check for End of File should be used external with While loop
/// </summary>
public bool Eof
{
get
{
if (this.iRecno >= (this._aOffsets.Length))
{

return true;
}

return false;
}
}
/// <summary>
/// check for beginning of file
/// </summary>
public bool Bof
{
get
{
if (this.iRecno < 0)
{
this.iRecno = 0;
return true;
}
return false;

}
}
/// <summary>
/// Moves to Next Row in file
/// </summary>
/// <returns></returns>
public long Skip()
{
return this.Skip(1);
}
/// <summary>
/// Moves to Next Row in File use this instead of Skip
/// </summary>
/// <param name="n2Skip"></param>
/// <returns></returns>
public long Skip(int n2Skip)
{

if (n2Skip >= 0)
{
this.iRecno += n2Skip;
}
else
{
long iRec = Math.Abs(n2Skip);
this.iRecno -= iRec;
}

return this.iRecno;

}
public long GoTop()
{

this.iRecno = 0;
return this.iRecno;

}
/// <summary>
/// go to specified row pos in a file
/// </summary>
/// <param name="Recno"></param>
/// <returns></returns>
public long GoTo(long Recno)
{
if (Recno (this._aOffsets.Length - 1))
{
this.iRecno = this._aOffsets.Length - 1;
}
else
{
this.iRecno = (Recno - 1);
}
return this.iRecno;
}
/// <summary>
/// get current row position in file
/// </summary>
public long RowNum
{
get
{
return iRecno + 1;
}
}
/// <summary>
/// go to last row in file
/// </summary>
/// <returns></returns>
public long GoBottom()
{

this.iRecno = this._aOffsets.Length - 1;
return this.iRecno;
}
/// <summary>
/// total count of rows in file
/// </summary>
/// <returns></returns>
public long RowCount()
{
return this._aOffsets.Length;
}

/// <summary>
/// Getrow does the actually reading of 1 row from the table
/// if columns are set then they will be created also
/// </summary>
/// <returns></returns>
public string GetRow()
{

long nStart = this._aOffsets[iRecno];
//byte[] aReadBytes;

this._Fs.Seek(this._aOffsets[this.iRecno], SeekOrigin.Begin);
int nCnt = 0;

//if (this.iRecno==0)
//{
// nCnt = (int)(this._aOffsets[this.iRecno + 1] -
this._aOffsets[this.iRecno]);
// nCnt-=1;
// aReadBytes = new Byte[nCnt];
// this._Fs.Read(aReadBytes, 0, nCnt - 1);
//}
if (this.iRecno -1 && (this.iRecno < this._aOffsets.Length -
1))
{
nCnt = (int)(this._aOffsets[this.iRecno + 1] -
this._aOffsets[this.iRecno]);
nCnt -= 1;
this.aBytes = new Byte[nCnt];
this._Fs.Read(this.aBytes, 0, nCnt - 1);
this.cRecord = UTF8Encoding.ASCII.GetString(this.aBytes);
}
else
{
//last row in file
nCnt = this.CombinedColumnLength; //this.nRecordLen - 1;
//nCnt = this.iBytes2Read-1;
aBytes = new Byte[nCnt];
this._Fs.Read(this.aBytes, 0, nCnt - 1);
this.cRecord = UTF8Encoding.ASCII.GetString(this.aBytes);

//this.cRecord = this.cRecord.Substring(0,
this.cRecord.IndexOf(this._cEol) - 1);

}
// byte[] aReadBytes = new Byte[nCnt];
// this._Fs.Read(aReadBytes, 0, nCnt-1);
//this.cRecord = UTF8Encoding.ASCII.GetString(this.aBytes);
//pad the record to meet column specifications if columns
Specified
if (this._ColumnCount 0)
{
this.cRecord =
this.cRecord.PadRight(this.CombinedColumnLength);
// fill the Columns
//************************************************** *******

int npos = 0;
int x = 0;

if (this._Delimiter == null)
{
for (x = 0; x < this._ColumnCount; x++)
{
this._aColumns[x] = this.cRecord.Substring(npos,
(int)this._aStru[x, 2]);

npos += (int)this._aStru[x, 2];

}

}
else
{
npos = 0;
int nSplit = 0;
string cCol = "";
string cRow;
if (this._RemoveQuotes)
{
cRow = this.cRecord.Replace('"', ' ');
}
else
{
cRow = this.cRecord;
}
for (x = 0; x < this.ColumnCount; x++)
{
nSplit = cRow.IndexOf(this._Delimiter);

if (nSplit == -1) // last column
{
cCol = cRow.Substring(0);
}
else
{
cCol = cRow.Substring(0, nSplit);

cRow = cRow.Replace(cCol + this._Delimiter, "");
}

cCol = cCol.Trim();

this._aColumns[x] =
cCol.PadRight((int)this._aStru[x, 2], ' ');

}
}
}
//
************************************************** ***************************

return this.cRecord;
}

/// <summary>
/// Retrieve a Column by Column Position
/// </summary>
/// <param name="nPos"></param>
/// <returns></returns>
public object ColumnGet(int nPos)
{

return (this.ColumnGet(this._aStru[nPos, 0].ToString()));
}
/// <summary>
/// Gets column Position bye column Name
/// </summary>
/// <param name="cName"></param>
/// <returns></returns>
public object ColumnGet(string cName)
{
int x;
object oRet = null;

for (x = 0; x < this.ColumnCount; x++)
{

if (this._aStru[x, 0].ToString() == cName.ToString())
{

oRet = this._aColumns[x];
}
}

return oRet;
}
public void Close()
{
this._aOffsets = null;
this._Fs.Close();
}
} //fileserver
public static class dvConsole
{
public static void Print(object line2Print)
{
Console.WriteLine(line2Print);

}

public static void PrintCR(object line2Print)
{
Console.WriteLine(line2Print);
Console.ReadKey();
}
}
}
Aug 14 '07 #11
MikeJ <ve***********@sbcglobal.netwrote:
it Compiles just Fine ..somthing Cut off the Lines on Remarks to cause the
SemiColon Problems
There's more to it than that, although the semi-colons have been
removed again from the top section.
MJ
I'll try Again
example
fserver= new TextFileServer("SomeFile.txt")
fserver.GoTop()
string crow
while (fserver.eof==false)
That line's very different from the one you posted before, which was

while (ofs=false)

Note the difference between = and ==.

I haven't read the code in detail, but things like:

UTF8Encoding.ASCII

(and the large amount of commented out code, and rather large methods)
raise concerns.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
Aug 14 '07 #12
the top section i typed fast..sorry...but
the bottome section is the class..and it compiles just fine
MJ

"Jon Skeet [C# MVP]" <sk***@pobox.comwrote in message
news:MP*********************@msnews.microsoft.com. ..
MikeJ <ve***********@sbcglobal.netwrote:
>it Compiles just Fine ..somthing Cut off the Lines on Remarks to cause
the
SemiColon Problems

There's more to it than that, although the semi-colons have been
removed again from the top section.
>MJ
I'll try Again
example
>fserver= new TextFileServer("SomeFile.txt")
fserver.GoTop()
string crow
while (fserver.eof==false)

That line's very different from the one you posted before, which was

while (ofs=false)

Note the difference between = and ==.

I haven't read the code in detail, but things like:

UTF8Encoding.ASCII

(and the large amount of commented out code, and rather large methods)
raise concerns.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too

Aug 14 '07 #13
because i have to deal with files in streams also
there is no End of Line Markers....just some other character used as a
segment end
ReadAllLines places the Contents of a file in a Array
i did not want to place 1million rows into a array
i'll be there for 3 and a half years loading the file and taking up server
resources....by loading just the row offsets into a LONG[] Array they load
in like 10 seconds
reg size files 20 30 or less mgs are like a blink of a eye
and i can process the file in under a min...i did a test with 10million rows
and that was under 3 mins....
for me that lots much faster and less resources taken up on the machine,
specially if this is in a Multi threaded services processing many files of
many sizes and many different end of line markers

again this is currently work in progress
MJ

"Joe" <jo********@gmail.comwrote in message
news:11**********************@q75g2000hsh.googlegr oups.com...
Just curious...any reason why you can't use File.ReadAllLines(string
fileName) and just use the index of the line in the resulting string[]
as the position of the line in the file?

Thanks,
~Joe


Aug 14 '07 #14
MikeJ <ve***********@sbcglobal.netwrote:
the top section i typed fast..sorry...but
the bottome section is the class..and it compiles just fine
I dare say it *compiles* fine, but it doesn't look exactly general
purpose to me. ~ as a line ending means a line length of 106?

You've also got a bug (in at least two places) where you allocate a
buffer, read into it, and then convert the *whole* buffer into a
string, which assumes that the buffer will be filled completely.

I'm sorry to say this, but I just wouldn't trust this code without
picking it apart in detail - and I'd advise the OP to write from
scratch rather than trying to understand what this code does and fix
its issues.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
Aug 14 '07 #15
i ran many different files through it..and my orig post was
"work in progress..." and "not completed"...
your thoughts are welcome but i don't know where you are talking about 106
and where im reading contents into the array
since the array is a long[] and therefore strings can't be placed in it
i read into a buffer to find end of line and that could be anything
far as that 106 , the Endof Line Marker is "~" character , so Max Record
Length would Be 106
Since these are files that come in the form of Ansi EDI type files
that method you read was a generic find end of line method and build some
information
if the user of the class specified the end of line..the top (if) statement
is executed , else the constant (if) block below are executed

before you bash...you should read a lil....as i said work in progress....
but i do welcome comments

MJ

"Jon Skeet [C# MVP]" <sk***@pobox.comwrote in message
news:MP*********************@msnews.microsoft.com. ..
MikeJ <ve***********@sbcglobal.netwrote:
>the top section i typed fast..sorry...but
the bottome section is the class..and it compiles just fine

I dare say it *compiles* fine, but it doesn't look exactly general
purpose to me. ~ as a line ending means a line length of 106?

You've also got a bug (in at least two places) where you allocate a
buffer, read into it, and then convert the *whole* buffer into a
string, which assumes that the buffer will be filled completely.

I'm sorry to say this, but I just wouldn't trust this code without
picking it apart in detail - and I'd advise the OP to write from
scratch rather than trying to understand what this code does and fix
its issues.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too

Aug 14 '07 #16
MikeJ <ve***********@sbcglobal.netwrote:
i ran many different files through it..and my orig post was
"work in progress..." and "not completed"...
your thoughts are welcome but i don't know where you are talking about 106
and where im reading contents into the array
since the array is a long[] and therefore strings can't be placed in it
i read into a buffer to find end of line and that could be anything
far as that 106 , the Endof Line Marker is "~" character , so Max Record
Length would Be 106
Since these are files that come in the form of Ansi EDI type files
that method you read was a generic find end of line method and build some
information
And that may be fine for *your* use of it, but you were recommending it
for others to use - and there's no indication from the OP that he's
looking at files which have the special sort of format you're
describing.
if the user of the class specified the end of line..the top (if) statement
is executed , else the constant (if) block below are executed

before you bash...you should read a lil....as i said work in progress....
but i do welcome comments
I'd just be wary of telling people that you're providing code which
will work for *their* case when it's still a work in progress for your
particular use

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
Aug 15 '07 #17

On Aug 14, 11:25 pm, Jon Skeet [C# MVP] <sk...@pobox.comwrote:
I'm sorry to say this, but I just wouldn't trust this code without
picking it apart in detail [...]
Still, iSeekBytes is a pretty cool variable name.

Aug 15 '07 #18
i did not reccomend it to any body , simply put
i posted it here as sample,
nothing less or nothin more
Read my orig Post above

simply put...we all look at others code for examples ...
or a way to solve other problems...

i was only placing this here.. as a sample...if thats
a problem ..i will never post code again ..unless
i am looking for help.....

Sorry for Causing Such a Problem
MJ
"Jon Skeet [C# MVP]" <sk***@pobox.comwrote in message
news:MP*********************@msnews.microsoft.com. ..
MikeJ <ve***********@sbcglobal.netwrote:
>i ran many different files through it..and my orig post was
"work in progress..." and "not completed"...
your thoughts are welcome but i don't know where you are talking about
106
and where im reading contents into the array
since the array is a long[] and therefore strings can't be placed in it
i read into a buffer to find end of line and that could be anything
far as that 106 , the Endof Line Marker is "~" character , so Max Record
Length would Be 106
Since these are files that come in the form of Ansi EDI type files
that method you read was a generic find end of line method and build some
information

And that may be fine for *your* use of it, but you were recommending it
for others to use - and there's no indication from the OP that he's
looking at files which have the special sort of format you're
describing.
>if the user of the class specified the end of line..the top (if)
statement
is executed , else the constant (if) block below are executed

before you bash...you should read a lil....as i said work in progress....
but i do welcome comments

I'd just be wary of telling people that you're providing code which
will work for *their* case when it's still a work in progress for your
particular use

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too

Aug 15 '07 #19
MikeJ <ve***********@sbcglobal.netwrote:
i did not reccomend it to any body , simply put
i posted it here as sample,
nothing less or nothin more
Read my orig Post above
Well, you wrote:

"just copy and past it should work ok for ya"

That sounds like you're claiming it will work.
simply put...we all look at others code for examples ...
or a way to solve other problems...

i was only placing this here.. as a sample...if thats
a problem ..i will never post code again ..unless
i am looking for help.....
I have no problem with people posting code, but I don't think this was
terribly good sample code, and it didn't really do what the OP was
asking for.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
Aug 15 '07 #20

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Seong Jin, Cho | last post by:
Hi. Is there a way to get an unbuffered InputStream from Process? I found out that java.lang.Win32Process and java.lang.UNIXProcess both wraps the stdout with java.io.BufferedInputStream, but...
0
by: Fuzzyman | last post by:
I use a simple python script to monitor downloads from my website. http://www.voidspace.org.uk/python/cgi.shtml#downman It serves the file in a loop using our old friend : ...
5
by: Rich | last post by:
Does anyone know the correct way of opening an unbuffered output file using STL? I attempted: ofstream myfile("fname.txt", ios::binary); myfile.setbuf(NULL, 0); and I was informed that...
1
by: | last post by:
Is this even possible? I've found some references to specific "unbuffered" type methods that exist in older incarnations of basic_streambuf but not in newer ones. Info please. :P
11
by: Lonnie Princehouse | last post by:
>From the cmd shell on both Windows 2k and XP, I'm getting this weird syntax error in conjunction with the unbuffered flag. It works fine without -u. Has anyone else encountered it? This didn't...
4
by: pank7 | last post by:
hi everyone, I have a program here to test the file IO(actually output) with buffer turned on and off. What I want to see is that there will be obvious differece in time. Here I have an input...
0
by: Hamish Allan | last post by:
Hi, The man page for python says: "-u Force stdin, stdout and stderr to be totally unbuffered." However, when I try: $ ssh localhost python -u print 'hello, world'
1
by: Yang Zhang | last post by:
Hi, is there any way to get unbuffered stdout/stderr without relying on the -u flag to python or calling .flush() on each print (including indirect hacks like replacing sys.stdout with a wrapper...
8
by: zeeshan708 | last post by:
what is the difference between the buffered and unbuffered stream ??(e.g we say that cout is buffered and cerr is unbuffered stream) does that mean that the output sent to buffered stream have to go...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.