internal static IDxfCodePairReader GetCodePairReader(string firstLine, int readBytes, BinaryReader binaryReader, Encoding defaultTextEncoding) { if (firstLine == DxbReader.BinarySentinel) { throw new DxfReadException("DXB files don't support code pairs. This path should never be hit.", readBytes); } else { Encoding.RegisterProvider(CodePagesEncodingProvider.Instance); IDxfCodePairReader dxfReader; if (firstLine == BinarySentinel) { // swallow next two bytes var sub = binaryReader.ReadByte(); Debug.Assert(sub == 0x1A); var nul = binaryReader.ReadByte(); Debug.Assert(nul == 0x00); dxfReader = new DxfBinaryReader(binaryReader, readBytes + 2); } else { dxfReader = new DxfTextReader(binaryReader.BaseStream, defaultTextEncoding, firstLine); } return(dxfReader); } }
internal static IDxfCodePairReader GetCodePairReader(string firstLine, int readBytes, BinaryReader binaryReader) { if (firstLine == DxbReader.BinarySentinel) { throw new DxfReadException("DXB files don't support code pairs. This path should never be hit.", readBytes); } else { IDxfCodePairReader dxfReader; if (firstLine == BinarySentinel) { dxfReader = new DxfBinaryReader(binaryReader, readBytes); } else { dxfReader = new DxfAsciiReader(binaryReader.BaseStream, firstLine); } return(dxfReader); } }
internal static IDxfCodePairReader GetCodePairReader(string firstLine, int readBytes, BinaryReader binaryReader) { if (firstLine == DxbReader.BinarySentinel) { throw new DxfReadException("DXB files don't support code pairs. This path should never be hit.", readBytes); } else { IDxfCodePairReader dxfReader; if (firstLine == BinarySentinel) { dxfReader = new DxfBinaryReader(binaryReader, readBytes); } else { dxfReader = new DxfAsciiReader(binaryReader.BaseStream, firstLine); } return dxfReader; } }
public static DxfFile Load(Stream stream) { var reader = new BinaryReader(stream); // read first line char-by-char var sb = new StringBuilder(); char c = reader.ReadChar(); while (c != '\n') { sb.Append(c); c = reader.ReadChar(); } // trim BOM var line = sb.ToString().TrimEnd('\r'); if (line.Length > 0 && line[0] == 0xFEFF) { line = line.Substring(1); } // check for binary sentinels DxfFile file; if (line == DxbReader.BinarySentinel) { file = new DxbReader().ReadFile(reader); } else { IDxfCodePairReader dxfReader; if (line == BinarySentinel) { dxfReader = new DxfBinaryReader(reader); } else { dxfReader = new DxfAsciiReader(stream, line); } file = LoadFromReader(dxfReader); } return file; }