projects
/
mono.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
2009-10-21 Miguel de Icaza <miguel@novell.com>
[mono.git]
/
mcs
/
class
/
corlib
/
System.IO
/
BinaryReader.cs
diff --git
a/mcs/class/corlib/System.IO/BinaryReader.cs
b/mcs/class/corlib/System.IO/BinaryReader.cs
index f6c481e9bbc780cdf817f7bc341ea41abc6b3207..d6dd9c96afdfd21725721e24589e7f6cec459b45 100644
(file)
--- a/
mcs/class/corlib/System.IO/BinaryReader.cs
+++ b/
mcs/class/corlib/System.IO/BinaryReader.cs
@@
-33,12
+33,13
@@
using System;
using System.Text;
using System.Globalization;
using Mono.Security;
using System.Text;
using System.Globalization;
using Mono.Security;
+using System.Runtime.InteropServices;
namespace System.IO {
namespace System.IO {
+ [ComVisible (true)]
public class BinaryReader : IDisposable {
Stream m_stream;
Encoding m_encoding;
public class BinaryReader : IDisposable {
Stream m_stream;
Encoding m_encoding;
- int m_encoding_max_byte;
byte[] m_buffer;
byte[] m_buffer;
@@
-53,7
+54,7
@@
namespace System.IO {
private bool m_disposed = false;
private bool m_disposed = false;
- public BinaryReader(Stream input) : this(input, Encoding.UTF8Unmarked) {
+ public BinaryReader(Stream input) : this(input, Encoding.UTF8Unmarked
Unsafe
) {
}
public BinaryReader(Stream input, Encoding encoding) {
}
public BinaryReader(Stream input, Encoding encoding) {
@@
-91,25
+92,29
@@
namespace System.IO {
charBuffer = null;
}
charBuffer = null;
}
+#if NET_4_0
+ public void Dispose ()
+#else
void IDisposable.Dispose()
void IDisposable.Dispose()
+#endif
{
Dispose (true);
}
{
Dispose (true);
}
- protected virtual void FillBuffer (int
b
ytes)
+ protected virtual void FillBuffer (int
numB
ytes)
{
if (m_disposed)
throw new ObjectDisposedException ("BinaryReader", "Cannot read from a closed BinaryReader.");
if (m_stream==null)
throw new IOException("Stream is invalid");
{
if (m_disposed)
throw new ObjectDisposedException ("BinaryReader", "Cannot read from a closed BinaryReader.");
if (m_stream==null)
throw new IOException("Stream is invalid");
- CheckBuffer(
b
ytes);
+ CheckBuffer(
numB
ytes);
/* Cope with partial reads */
int pos=0;
/* Cope with partial reads */
int pos=0;
- while(pos<
b
ytes) {
- int n=m_stream.Read(m_buffer, pos,
b
ytes-pos);
+ while(pos<
numB
ytes) {
+ int n=m_stream.Read(m_buffer, pos,
numB
ytes-pos);
if(n==0) {
throw new EndOfStreamException();
}
if(n==0) {
throw new EndOfStreamException();
}
@@
-133,10
+138,9
@@
namespace System.IO {
}
char[] result = new char[1];
}
char[] result = new char[1];
- byte[] bytes;
int bcount;
int bcount;
- int ccount = ReadCharBytes (result, 0, 1, out b
ytes, out b
count);
+ int ccount = ReadCharBytes (result, 0, 1, out bcount);
// Reposition the stream
m_stream.Position -= bcount;
// Reposition the stream
m_stream.Position -= bcount;
@@
-215,54
+219,57
@@
namespace System.IO {
}
int bytes_read;
}
int bytes_read;
- byte[] bytes;
- return ReadCharBytes (buffer, index, count, out bytes, out bytes_read);
+ return ReadCharBytes (buffer, index, count, out bytes_read);
}
}
- private int ReadCharBytes
(char[] buffer, int index, int count, out byte[] bytes, out int bytes_read)
\r
+ private int ReadCharBytes
(char[] buffer, int index, int count, out int bytes_read)
{
{
- int chars_read
=
0;
- bytes_read
=
0;
+ int chars_read
=
0;
+ bytes_read
=
0;
- while(chars_read < count)
- {
- CheckBuffer(bytes_read + 1);
+ while (chars_read < count) {
+ int pos = 0;
+ while (true) {
+ CheckBuffer (pos + 1);
-
int read_byte = m_stream.ReadByte
();
+
int read_byte = m_stream.ReadByte
();
- if(read_byte==-1)
- {
- /* EOF */
- bytes = m_buffer;
- return(chars_read);
- }
+ if (read_byte == -1)
+ /* EOF */
+ return chars_read;
-
m_buffer[bytes_read]=
(byte)read_byte;
-
bytes_read
++;
+
m_buffer [pos ++] =
(byte)read_byte;
+
bytes_read
++;
- chars_read=m_encoding.GetChars(m_buffer, 0,
- bytes_read,
- buffer, index);
-
+ int n = m_encoding.GetChars (m_buffer, 0, pos, buffer, index + chars_read);
+ if (n > 0)
+ break;
+ }
+ chars_read ++;
}
}
- bytes = m_buffer;
- return(chars_read);
+ return chars_read;
}
protected int Read7BitEncodedInt() {
int ret = 0;
int shift = 0;
}
protected int Read7BitEncodedInt() {
int ret = 0;
int shift = 0;
+ int len;
byte b;
byte b;
-
do
{
+
for (len = 0; len < 5; ++len)
{
b = ReadByte();
ret = ret | ((b & 0x7f) << shift);
shift += 7;
b = ReadByte();
ret = ret | ((b & 0x7f) << shift);
shift += 7;
- } while ((b & 0x80) == 0x80);
+ if ((b & 0x80) == 0)
+ break;
+ }
- return ret;
+ if (len < 5)
+ return ret;
+ else
+ throw new FormatException ("Too many bytes in what should have been a 7 bit encoded Int32.");
}
public virtual bool ReadBoolean() {
}
public virtual bool ReadBoolean() {
@@
-306,7
+313,7
@@
namespace System.IO {
byte[] buf = new byte[count];
int pos=0;
byte[] buf = new byte[count];
int pos=0;
- while(pos < count)
\r
+ while(pos < count)
{
int n=m_stream.Read(buf, pos, count-pos);
if(n==0) {
{
int n=m_stream.Read(buf, pos, count-pos);
if(n==0) {