本文整理汇总了C#中LumiSoft.Net.IO.SmartStream.ReadLine方法的典型用法代码示例。如果您正苦于以下问题:C# SmartStream.ReadLine方法的具体用法?C# SmartStream.ReadLine怎么用?C# SmartStream.ReadLine使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类LumiSoft.Net.IO.SmartStream
的用法示例。
在下文中一共展示了SmartStream.ReadLine方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Parse
/// <summary>
/// Parses MIME header from the specified stream.
/// </summary>
/// <param name="stream">MIME header stream.</param>
/// <param name="encoding">Headers fields reading encoding. If not sure, UTF-8 is recommended.</param>
/// <exception cref="ArgumentNullException">Is raised when <b>stream</b> or <b>encoding</b> is null.</exception>
public void Parse(SmartStream stream,Encoding encoding)
{
if(stream == null){
throw new ArgumentNullException("stream");
}
if(encoding == null){
throw new ArgumentNullException("encoding");
}
StringBuilder currentHeader = new StringBuilder();
SmartStream.ReadLineAsyncOP readLineOP = new SmartStream.ReadLineAsyncOP(new byte[4*1024*1024],SizeExceededAction.ThrowException);
while(true){
stream.ReadLine(readLineOP,false);
if(readLineOP.Error != null){
throw readLineOP.Error;
}
// We reached end of stream.
else if(readLineOP.BytesInBuffer == 0){
if(currentHeader.Length > 0){
Add(currentHeader.ToString());
}
m_IsModified = false;
return;
}
// We got blank header terminator line.
else if(readLineOP.LineBytesInBuffer == 0){
if(currentHeader.Length > 0){
Add(currentHeader.ToString());
}
m_IsModified = false;
return;
}
else{
string line = encoding.GetString(readLineOP.Buffer,0,readLineOP.BytesInBuffer);
// New header field starts.
if(currentHeader.Length == 0){
currentHeader.Append(line);
}
// Header field continues.
else if(char.IsWhiteSpace(line[0])){
currentHeader.Append(line);
}
// Current header field closed, new starts.
else{
Add(currentHeader.ToString());
currentHeader = new StringBuilder();
currentHeader.Append(line);
}
}
}
}
示例2: Parse
/// <summary>
/// Parses mime entity from stream.
/// </summary>
/// <param name="stream">Data stream from where to read data.</param>
/// <param name="toBoundary">Entity data is readed to specified boundary.</param>
/// <returns>Returns false if last entity. Returns true for mulipart entity, if there are more entities.</returns>
internal bool Parse(SmartStream stream,string toBoundary)
{
// Clear header fields
m_pHeader.Clear();
m_pHeaderFieldCache.Clear();
// Parse header
m_pHeader.Parse(stream);
// Parse entity and child entities if any (Conent-Type: multipart/xxx...)
// Multipart entity
if((this.ContentType & MediaType_enum.Multipart) != 0){
// There must be be boundary ID (rfc 1341 7.2.1 The Content-Type field for multipart entities requires one parameter,
// "boundary", which is used to specify the encapsulation boundary.)
string boundaryID = this.ContentType_Boundary;
if(boundaryID == null){
// This is invalid message, just skip this mime entity
}
else{
// There is one or more mime entities
// Find first boundary start position
SmartStream.ReadLineAsyncOP args = new SmartStream.ReadLineAsyncOP(new byte[8000],SizeExceededAction.JunkAndThrowException);
stream.ReadLine(args,false);
if(args.Error != null){
throw args.Error;
}
string lineString = args.LineUtf8;
while(lineString != null){
if(lineString.StartsWith("--" + boundaryID)){
break;
}
stream.ReadLine(args,false);
if(args.Error != null){
throw args.Error;
}
lineString = args.LineUtf8;
}
// This is invalid entity, boundary start not found. Skip that entity.
if(string.IsNullOrEmpty(lineString)){
return false;
}
// Start parsing child entities of this entity
while(true){
// Parse and add child entity
MimeEntity childEntity = new MimeEntity();
this.ChildEntities.Add(childEntity);
// This is last entity, stop parsing
if(childEntity.Parse(stream,boundaryID) == false){
break;
}
// else{
// There are more entities, parse them
}
// This entity is child of mulipart entity.
// All this entity child entities are parsed,
// we need to move stream position to next entity start.
if(!string.IsNullOrEmpty(toBoundary)){
stream.ReadLine(args,false);
if(args.Error != null){
throw args.Error;
}
lineString = args.LineUtf8;
while(lineString != null){
if(lineString.StartsWith("--" + toBoundary)){
break;
}
stream.ReadLine(args,false);
if(args.Error != null){
throw args.Error;
}
lineString = args.LineUtf8;
}
// Invalid boundary end, there can't be more entities
if(string.IsNullOrEmpty(lineString)){
return false;
}
// See if last boundary or there is more. Last boundary ends with --
if(lineString.EndsWith(toBoundary + "--")){
return false;
}
// else{
// There are more entities
return true;
//.........这里部分代码省略.........
示例3: WritePeriodTerminated
/// <summary>
/// Reads all data from the source <b>stream</b> and writes it to stream. Period handling and period terminator is added as required.
/// </summary>
/// <param name="stream">Source stream which data to write to stream.</param>
/// <returns>Returns number of bytes written to source stream.</returns>
/// <exception cref="ObjectDisposedException">Is raised when this object is disposed and this method is accessed.</exception>
/// <exception cref="ArgumentNullException">Is raised when <b>stream</b> is null.</exception>
/// <exception cref="LineSizeExceededException">Is raised when <b>stream</b> has too big line.</exception>
public long WritePeriodTerminated(Stream stream)
{
if(m_IsDisposed){
throw new ObjectDisposedException(this.GetType().Name);
}
if(stream == null){
throw new ArgumentNullException("stream");
}
// We need to read lines, do period handling and write them to stream.
long totalWritten = 0;
byte[] buffer = new byte[m_BufferSize];
ReadLineAsyncOP readLineOP = new ReadLineAsyncOP(buffer,SizeExceededAction.ThrowException);
SmartStream reader = new SmartStream(stream,false);
while(true){
reader.ReadLine(readLineOP,false);
if(readLineOP.Error != null){
throw readLineOP.Error;
}
// We reached end of stream, no more data.
if(readLineOP.BytesInBuffer == 0){
break;
}
// Period handling. If line starts with period(.), additional period is added.
if(readLineOP.LineBytesInBuffer > 0 && buffer[0] == '.'){
// Add additional period.
Write(new byte[]{(byte)'.'},0,1);
totalWritten++;
}
// Write line to source stream.
Write(buffer,0,readLineOP.BytesInBuffer);
totalWritten += readLineOP.BytesInBuffer;
}
// Write period terminator.
WriteLine(".");
Flush();
return totalWritten;
}
示例4: Parse
/// <summary>
/// Parses header fields from stream. Stream position stays where header reading ends.
/// </summary>
/// <param name="stream">Stream from where to parse.</param>
public void Parse(SmartStream stream)
{
/* Rfc 2822 2.2 Header Fields
Header fields are lines composed of a field name, followed by a colon
(":"), followed by a field body, and terminated by CRLF. A field
name MUST be composed of printable US-ASCII characters (i.e.,
characters that have values between 33 and 126, inclusive), except
colon. A field body may be composed of any US-ASCII characters,
except for CR and LF. However, a field body may contain CRLF when
used in header "folding" and "unfolding" as described in section
2.2.3. All field bodies MUST conform to the syntax described in
sections 3 and 4 of this standard.
Rfc 2822 2.2.3 Long Header Fields
The process of moving from this folded multiple-line representation
of a header field to its single line representation is called
"unfolding". Unfolding is accomplished by simply removing any CRLF
that is immediately followed by WSP. Each header field should be
treated in its unfolded form for further syntactic and semantic
evaluation.
Example:
Subject: aaaaa<CRLF>
<TAB or SP>aaaaa<CRLF>
*/
m_pHeaderFields.Clear();
SmartStream.ReadLineAsyncOP args = new SmartStream.ReadLineAsyncOP(new byte[32000],SizeExceededAction.JunkAndThrowException);
stream.ReadLine(args,false);
if(args.Error != null){
throw args.Error;
}
string line = args.LineUtf8;
while(line != null){
// End of header reached
if(line == ""){
break;
}
// Store current header line and read next. We need to read 1 header line to ahead,
// because of multiline header fields.
string headerField = line;
stream.ReadLine(args,false);
if(args.Error != null){
throw args.Error;
}
line = args.LineUtf8;
// See if header field is multiline. See comment above.
while(line != null && (line.StartsWith("\t") || line.StartsWith(" "))){
headerField += line;
stream.ReadLine(args,false);
if(args.Error != null){
throw args.Error;
}
line = args.LineUtf8;
}
string[] name_value = headerField.Split(new char[]{':'},2);
// There must be header field name and value, otherwise invalid header field
if(name_value.Length == 2){
Add(name_value[0] + ":",name_value[1].Trim());
}
}
}
示例5: GetList
/// <summary>
/// Gets files and directories in the current server directory.
/// </summary>
/// <param name="path">Directory or file name which listing to get. Value null means current directory will be listed.</param>
/// <returns>Returns current working directory listing.</returns>
/// <exception cref="ObjectDisposedException">Is raised when this object is disposed and this method is accessed.</exception>
/// <exception cref="InvalidOperationException">Is raised when FTP client is not connected or FTP data connection has active read/write operation.</exception>
/// <exception cref="FTP_ClientException">Is raised when FTP server returns error.</exception>
public FTP_ListItem[] GetList(string path)
{
if(this.IsDisposed){
throw new ObjectDisposedException(this.GetType().Name);
}
if(!this.IsConnected){
throw new InvalidOperationException("You must connect first.");
}
if(m_pDataConnection.IsActive){
throw new InvalidOperationException("There is already active read/write operation on data connection.");
}
List<FTP_ListItem> retVal = new List<FTP_ListItem>();
// Set transfer mode
SetTransferType(TransferType.Binary);
if(m_TransferMode == FTP_TransferMode.Passive){
Pasv();
}
else{
Port();
}
// If FTP server supports MLSD command, use it to get directory listing.
// MLSD is standard way to get dir listing, while LIST command isn't any strict standard.
bool mlsdSupported = false;
foreach(string feature in m_pExtCapabilities){
if(feature.ToLower().StartsWith("mlsd")){
mlsdSupported = true;
break;
}
}
#region MLSD
if(mlsdSupported){
if(string.IsNullOrEmpty(path)){
WriteLine("MLSD");
}
else{
WriteLine("MLSD " + path);
}
string[] response = ReadResponse();
if(!response[0].StartsWith("1")){
throw new FTP_ClientException(response[0]);
}
MemoryStream ms = new MemoryStream();
m_pDataConnection.ReadAll(ms);
response = ReadResponse();
if(!response[0].StartsWith("2")){
throw new FTP_ClientException(response[0]);
}
byte[] lineBuffer = new byte[8000];
ms.Position = 0;
SmartStream mlsdStream = new SmartStream(ms,true);
while(true){
SmartStream.ReadLineAsyncOP args = new SmartStream.ReadLineAsyncOP(lineBuffer,SizeExceededAction.JunkAndThrowException);
mlsdStream.ReadLine(args,false);
if(args.Error != null){
throw args.Error;
}
string line = args.LineUtf8;
// We reached end of stream, we readed whole list sucessfully.
if(line == null){
break;
}
else{
string[] parameters = line.Substring(0,line.LastIndexOf(';')).Split(';');
string name = line.Substring(line.LastIndexOf(';') + 1).Trim();
string type = "";
long size = 0;
DateTime modified = DateTime.MinValue;
foreach(string parameter in parameters){
string[] name_value = parameter.Split('=');
if(name_value[0].ToLower() == "type"){
type = name_value[1].ToLower();
}
else if(name_value[0].ToLower() == "size"){
size = Convert.ToInt32(name_value[1]);
}
else if(name_value[0].ToLower() == "modify"){
modified = DateTime.ParseExact(name_value[1],"yyyyMMddHHmmss",System.Globalization.DateTimeFormatInfo.InvariantInfo);
}
else{
// Other options won't interest us, skip them.
//.........这里部分代码省略.........