BigEndianBinaryReader.cs 746 B

123456789101112131415161718192021222324252627282930313233
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.IO;
  6. namespace DvdLib
  7. {
  8. public class BigEndianBinaryReader : BinaryReader
  9. {
  10. public BigEndianBinaryReader(Stream input)
  11. : base(input)
  12. {
  13. }
  14. public override ushort ReadUInt16()
  15. {
  16. return BitConverter.ToUInt16(ReadAndReverseBytes(2), 0);
  17. }
  18. public override uint ReadUInt32()
  19. {
  20. return BitConverter.ToUInt32(ReadAndReverseBytes(4), 0);
  21. }
  22. private byte[] ReadAndReverseBytes(int count)
  23. {
  24. byte[] val = base.ReadBytes(count);
  25. Array.Reverse(val, 0, count);
  26. return val;
  27. }
  28. }
  29. }