コード例 #1
0
ファイル: DxfFile.cs プロジェクト: UgaitzEtxebarria/dxf
        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);
            }
        }
コード例 #2
0
ファイル: DxfFile.cs プロジェクト: stephensmitchell-forks/Dxf
        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);
            }
        }
コード例 #3
0
ファイル: DxfFile.cs プロジェクト: yangkf1985/Dxf
        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;
            }
        }
コード例 #4
0
ファイル: DxfFile.cs プロジェクト: atph/Dxf
        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;
        }