1024 바이트 버퍼가 System.IO.Stream의 표준 구현 중 하나에서 제공되고 있습니까? t가 있다면, 당신은 단지 기본 스트림의 주위에 당신의 XmlTextReader는을 만들 수 있습니다
XmlTextReader tr = XmlTextReader.Create(myStreamInstance) ;
그렇지 않은 경우 - 말하자면, 예를 들어, 당신은 API의 일종에서 버퍼를 "읽기"하고 - 당신이 필요 다음으로 위의 XmlReader를 인스턴스를
public class MyStream : System.IO.Stream
{
public override bool CanRead { get { return true ; } }
public override bool CanSeek { get { return false ; } }
public override bool CanWrite { get { return false ; } }
public override long Length { get { throw new NotImplementedException(); } }
public override long Position {
get { throw new NotImplementedException(); }
set { throw new NotImplementedException(); }
}
public override int Read(byte[] buffer , int offset , int count)
{
int bytesRead = 0 ;
if (!initialized)
{
Initialize() ;
}
for (int bytesRemaining = count ; !atEOF && bytesRemaining > 0 ;)
{
int frameRemaining = frameLength - frameOffset ;
int chunkSize = (bytesRemaining > frameRemaining ? frameRemaining : bytesRemaining) ;
Array.Copy(frame , offset , frame , frameOffset , chunkSize) ;
bytesRemaining -= chunkSize ;
offset += chunkSize ;
bytesRead += chunkSize ;
// read next frame if necessary
if (frameOffset >= frameLength)
{
ReadNextFrame() ;
}
}
return bytesRead ;
}
public override long Seek(long offset , System.IO.SeekOrigin origin) { throw new NotImplementedException(); }
public override void SetLength(long value) { throw new NotImplementedException(); }
public override void Write(byte[] buffer , int offset , int count) { throw new NotImplementedException(); }
public override void Flush() { throw new NotImplementedException(); }
private byte[] frame = null ;
private int frameLength = 0 ;
private int frameOffset = 0 ;
private bool atEOF = false ;
private bool initialized = false ;
private void Initialize()
{
if (initialized) throw new InvalidOperationException() ;
frame = new byte[1024] ;
frameLength = 0 ;
frameOffset = 0 ;
atEOF = false ;
initialized = true ;
ReadNextFrame() ;
return ;
}
private void ReadNextFrame()
{
//TODO: read the next (or first 1024-byte buffer
//TODO: set the frame length to the number of bytes actually returned (might be less than 1024 on the last read, right?
//TODO: set the frame offset to 0
//TODO: set the atEOF flag if we've exhausted the data source ;
return ;
}
}
:이 라인 (당신이 할 필요가해야 모두가 ReadNextFrame 구체화() 메소드이며, 아마도 당신의 생성자를 구현)을 따라 뭔가를 자신의 구체적인 스트림을 구현
System.IO.Stream s = new MyStream() ;
System.Xml.XmlReader xr = XmlTextReader.Create(s) ;
건배!
XmlTextReader가 솔루션이어야합니다. 버퍼를 수동으로 처리하는 대신 관리하도록합니다. – porges