BufferedStream.Read 메서드
정의
중요
일부 정보는 릴리스되기 전에 상당 부분 수정될 수 있는 시험판 제품과 관련이 있습니다. Microsoft는 여기에 제공된 정보에 대해 어떠한 명시적이거나 묵시적인 보증도 하지 않습니다.
오버로드
| Name | Description |
|---|---|
| Read(Span<Byte>) |
현재 버퍼링된 스트림에서 바이트 범위로 바이트를 복사하고 버퍼링된 스트림 내의 위치를 읽은 바이트 수만큼 앞으로 이동합니다. |
| Read(Byte[], Int32, Int32) |
현재 버퍼링된 스트림에서 배열로 바이트를 복사합니다. |
Read(Span<Byte>)
- Source:
- BufferedStream.cs
- Source:
- BufferedStream.cs
- Source:
- BufferedStream.cs
- Source:
- BufferedStream.cs
- Source:
- BufferedStream.cs
현재 버퍼링된 스트림에서 바이트 범위로 바이트를 복사하고 버퍼링된 스트림 내의 위치를 읽은 바이트 수만큼 앞으로 이동합니다.
public:
override int Read(Span<System::Byte> destination);
public override int Read(Span<byte> destination);
override this.Read : Span<byte> -> int
Public Overrides Function Read (destination As Span(Of Byte)) As Integer
매개 변수
반환
버퍼에 읽은 총 바이트 수입니다. 현재 많은 바이트를 사용할 수 없는 경우 버퍼에 할당된 바이트 수보다 작거나 스트림의 끝에 도달한 경우 0보다 작을 수 있습니다.
설명
현재 인스턴스에서 CanRead 읽기를 지원하는지 여부를 확인하려면 이 속성을 사용합니다. 메서드를 ReadAsync 사용하여 현재 스트림에서 비동기적으로 읽습니다.
이 메서드의 구현은 현재 스트림에서 최대 buffer.Length 바이트를 읽고 저장 buffer합니다. 스트림 내의 현재 위치는 읽은 바이트 수만큼 고급입니다. 그러나 예외가 발생하면 스트림 내의 현재 위치는 변경되지 않습니다. 구현은 읽은 바이트 수를 반환합니다. 사용 가능한 데이터가 없는 경우 하나 이상의 데이터를 읽을 수 있을 때까지 구현이 차단됩니다.
Read 는 스트림에 더 이상 데이터가 없고 더 이상 필요하지 않은 경우에만 0을 반환합니다(예: 닫힌 소켓 또는 파일 끝). 구현은 스트림의 끝에 도달하지 않은 경우에도 요청된 것보다 적은 바이트를 반환할 수 있습니다.
기본 데이터 형식을 읽는 데 사용합니다 BinaryReader .
적용 대상
Read(Byte[], Int32, Int32)
- Source:
- BufferedStream.cs
- Source:
- BufferedStream.cs
- Source:
- BufferedStream.cs
- Source:
- BufferedStream.cs
- Source:
- BufferedStream.cs
현재 버퍼링된 스트림에서 배열로 바이트를 복사합니다.
public:
override int Read(cli::array <System::Byte> ^ buffer, int offset, int count);
public:
override int Read(cli::array <System::Byte> ^ array, int offset, int count);
public override int Read(byte[] buffer, int offset, int count);
public override int Read(byte[] array, int offset, int count);
override this.Read : byte[] * int * int -> int
override this.Read : byte[] * int * int -> int
Public Overrides Function Read (buffer As Byte(), offset As Integer, count As Integer) As Integer
Public Overrides Function Read (array As Byte(), offset As Integer, count As Integer) As Integer
매개 변수
- bufferarray
- Byte[]
- offset
- Int32
바이트 읽기를 시작할 버퍼의 바이트 오프셋입니다.
- count
- Int32
읽을 바이트 수입니다.
반환
읽은 총 바이트 수입니다 array. 이는 현재 많은 바이트를 사용할 수 없는 경우 요청된 바이트 수보다 작을 수 있으며, 데이터를 읽기 전에 스트림의 끝에 도달한 경우 0이 될 수 있습니다.
예외
빼기 길이 array 가 .보다 count작 offset 습니다.
array은 null입니다.
offset 또는 count 음수입니다.
스트림이 열려 null있지 않거나 .
스트림은 읽기를 지원하지 않습니다.
스트림이 닫힌 후 메서드가 호출되었습니다.
예제
이 코드 예제는 클래스에 제공된 더 큰 예제의 BufferedStream 일부입니다.
// Receive data using the BufferedStream.
Console.WriteLine("Receiving data using BufferedStream.");
bytesReceived = 0;
startTime = DateTime.Now;
int numBytesToRead = receivedData.Length;
while (numBytesToRead > 0)
{
// Read may return anything from 0 to numBytesToRead.
int n = bufStream.Read(receivedData,0, receivedData.Length);
// The end of the file is reached.
if (n == 0)
break;
bytesReceived += n;
numBytesToRead -= n;
}
bufferedTime = (DateTime.Now - startTime).TotalSeconds;
Console.WriteLine("{0} bytes received in {1} seconds.\n",
bytesReceived.ToString(),
bufferedTime.ToString("F1"));
// Receive data using the BufferedStream.
printfn "Receiving data using BufferedStream."
bytesReceived <- 0
let startTime = DateTime.Now
let mutable numBytesToRead = receivedData.Length
let mutable broken = false
while not broken && numBytesToRead > 0 do
// Read may return anything from 0 to numBytesToRead.
let n = bufStream.Read(receivedData,0, receivedData.Length)
// The end of the file is reached.
if n = 0 then
broken <- true
else
bytesReceived <- bytesReceived + n
numBytesToRead <- numBytesToRead - n
let bufferedTime = (DateTime.Now - startTime).TotalSeconds
printfn $"{bytesReceived} bytes received in {bufferedTime:F1} seconds.\n"
' Receive data using the BufferedStream.
Console.WriteLine("Receiving data using BufferedStream.")
bytesReceived = 0
startTime = DateTime.Now
Dim numBytesToRead As Integer = receivedData.Length
Dim n As Integer
Do While numBytesToRead > 0
'Read my return anything from 0 to numBytesToRead
n = bufStream.Read(receivedData, 0, receivedData.Length)
'The end of the file is reached.
If n = 0 Then
Exit Do
End If
bytesReceived += n
numBytesToRead -= n
Loop
bufferedTime = DateTime.Now.Subtract(startTime).TotalSeconds
Console.WriteLine("{0} bytes received in {1} " & _
"seconds." & vbCrLf, _
bytesReceived.ToString(), _
bufferedTime.ToString("F1"))
설명
이 메서드는 Read 스트림의 끝에 도달한 경우에만 0을 반환합니다. 다른 모든 경우에는 Read 반환하기 전에 항상 스트림에서 하나 이상의 바이트를 읽습니다. 정의에 따라 호출 ReadRead 시 스트림에서 사용할 수 있는 데이터가 없는 경우 메서드는 0을 반환합니다(스트림의 끝에 자동으로 도달). 구현은 스트림의 끝에 도달하지 않은 경우에도 요청된 것보다 적은 바이트를 반환할 수 있습니다.
기본 데이터 형식을 읽는 데 사용합니다 BinaryReader .
추가 정보
- BlockCopy(Array, Int32, Array, Int32, Int32)
- CanRead
- Write(Byte[], Int32, Int32)
- 파일 및 스트림 I/O
- 방법: 파일에서 텍스트 읽기
- 방법: 파일에 텍스트 쓰기