Configuration file analysis method, storage medium, electronic device and system

文档序号:1490580 发布日期:2020-02-04 浏览:20次 中文

阅读说明:本技术 一种配置文件的解析方法、存储介质、电子设备及系统 (Configuration file analysis method, storage medium, electronic device and system ) 是由 张磊 于 2018-07-05 设计创作,主要内容包括:本发明公开了一种配置文件的解析方法、存储介质、电子设备及系统,涉及数据解析领域,该方法包括以下步骤:S1:获取需要解析的配置文件,并复制配置文件获得临时文件;S2:获取临时文件的首行位置和尾行位置的标签,若首行位置和尾行位置为无效标签,则删除无效标签,若首行位置和尾行位置为有效标签,则将有效标签对应的配置信息保存至内存加载文件,并删除有效标签及对应的配置信息;S3:重复步骤S2,直至临时文件为空,完成配置文件的解析。本发明对配置文件进行拷贝,获得导入内存进行解析的临时文件,并采用从首尾同时解析并及时删除的方式对临时文件进行解析,获取其中的配置信息,此解析方式能够提高工作效率,减轻内存负担。(The invention discloses a method, a storage medium, electronic equipment and a system for analyzing a configuration file, which relate to the field of data analysis, and comprise the following steps: s1: acquiring a configuration file to be analyzed, and copying the configuration file to obtain a temporary file; s2: acquiring tags of a head line position and a tail line position of the temporary file, deleting the invalid tags if the head line position and the tail line position are invalid tags, storing configuration information corresponding to the valid tags into a memory loading file if the head line position and the tail line position are valid tags, and deleting the valid tags and the corresponding configuration information; s3: and repeating the step S2 until the temporary file is empty, and completing the analysis of the configuration file. The invention copies the configuration file to obtain the temporary file which is imported into the memory for analysis, and analyzes the temporary file by adopting a mode of simultaneously analyzing from head to tail and deleting in time to obtain the configuration information in the temporary file.)

1. A method for parsing a configuration file is characterized by comprising the following steps:

s1: acquiring a configuration file to be analyzed, and copying the configuration file to obtain a temporary file;

s2: acquiring tags of a head line position and a tail line position of the temporary file, deleting the invalid tags if the head line position and the tail line position are invalid tags, storing configuration information corresponding to the valid tags into a memory loading file if the head line position and the tail line position are valid tags, and deleting the valid tags and the corresponding configuration information;

s3: and repeating the step S2 until the temporary file is empty, and completing the analysis of the configuration file.

2. The method of claim 1, wherein obtaining the tags of the head line position and the tail line position of the temporary file comprises the following specific steps:

positioning the head line data of the temporary file, identifying line feed characters in the temporary file line by line, and if the line has no line feed character, determining the tail line data of the temporary file, thereby obtaining the head line position, the tail line position and the total line number of the temporary file;

and reading the head line data and the tail line data of the temporary file to obtain the labels of the head line position and the tail line position of the temporary file.

3. The method of claim 2, wherein obtaining the tags of the head line position and the tail line position of the temporary file comprises the following specific steps:

converting the temporary file into a file stream by calling FileInputStream mFileInputStream (targetFile);

calling an mBufferReader readLine () method to obtain the first line data in the file stream;

calling a targetFile length method to acquire length information of the file stream;

and creating a pointer to point to the head line of the file stream, judging whether a line break character exists forward line by using the pointer until the line break character does not exist, and determining the position of the tail line.

4. The method of claim 1, wherein the operation of saving the configuration information corresponding to the active tag to the memory load file comprises the steps of:

storing the configuration information corresponding to the effective label of the first line position into a first memory loading subfile;

storing the configuration information corresponding to the effective label of the tail line position in a second memory loading subfile;

the memory loading file at least comprises a first memory loading subfile and a second memory loading subfile.

5. The method according to claim 1, wherein the step S1 specifically includes:

s11: acquiring a configuration file to be analyzed, and identifying the size of the configuration file;

s12: setting a cache unit, dividing the configuration file into N file units smaller than the cache unit, and combining the file units into temporary files one by one through the cache unit, wherein N is an integer larger than 0.

6. The method of claim 1, wherein in step S1, the method further comprises:

converting the configuration file into a file object srcmile;

creating a temporary file, and converting the temporary file into a file object targetFile;

converting the file object srcmile into an input stream object srcmeinputstream by calling FileInputStream srcmream new FileInputStream (srcFile);

converting the file object targetFile into an output stream object targetFileOutputStream by calling FileOutputStream targetFileOutputStream (targetFile);

copying the data of the input stream object srcFileInputStream to the output stream object targetFileOutputStream.

7. The method of claim 6, wherein the operation of copying the data of the input stream object srcFileInputStream to the output stream object targetFileOutputStream comprises the steps of:

defining a buffer area unit byteBuffer;

read (byteBuffer) function reads data which is not larger than the size of buffer unit byteBuffer from the content of the input stream object srcfilelnputstream into the buffer unit byteBuffer, then writes the content of the buffer unit byteBuffer into the output stream object targetFileOutputStream by calling targetFileOutputStream.

8. A storage medium having a computer program stored thereon, characterized in that: the computer program, when executed by a processor, implements the method of any one of claims 1 to 7.

9. An electronic device comprising a memory and a processor, the memory having stored thereon a computer program that runs on the processor, characterized in that: the processor, when executing the computer program, implements the method of any of claims 1 to 7.

10. A system for parsing a configuration file, comprising:

the temporary file acquisition unit is used for acquiring the configuration file to be analyzed and copying the configuration file to obtain a temporary file;

the temporary file analysis unit is used for acquiring labels of a head line position and a tail line position of the temporary file, deleting the invalid labels if the head line position and the tail line position are invalid labels, storing configuration information corresponding to the valid labels into the memory loading file if the head line position and the tail line position are valid labels, and deleting the valid labels and the corresponding configuration information;

and the recursion calling unit is used for repeatedly calling the temporary file analysis unit to analyze the temporary file until the temporary file is empty, so as to finish the analysis of the configuration file.

Technical Field

The invention relates to the field of data analysis, in particular to an analysis method, a storage medium, electronic equipment and a system for a configuration file.

Background

In the traditional scheme, the configuration file is usually a file in an XML format, and the configuration file for analyzing the XML is usually obtained by loading the whole XML configuration into a memory and then analyzing the XML configuration;

with the development of live broadcast, more and more people watching the live broadcast, more and more extensive content related to the live broadcast, and gradually complicated data to be processed by a live broadcast platform, so that when the data is continuously processed according to a traditional analysis method, the data of a memory is suddenly increased due to the fact that the whole information is loaded into the memory, when the memory is insufficient, the problems of failure and the like occur due to large memory load, and inconvenience is brought to daily constant data analysis work.

Disclosure of Invention

Aiming at the defects in the prior art, the invention aims to provide an analysis method of a configuration file, which can improve the working efficiency and reduce the memory burden.

In order to achieve the above purposes, the technical scheme adopted by the invention is as follows:

in a first aspect, the present invention provides a method for parsing a configuration file, including the following steps:

s1: acquiring a configuration file to be analyzed, and copying the configuration file to obtain a temporary file;

s2: acquiring tags of a head line position and a tail line position of the temporary file, deleting the invalid tags if the head line position and the tail line position are invalid tags, storing configuration information corresponding to the valid tags into a memory loading file if the head line position and the tail line position are valid tags, and deleting the valid tags and the corresponding configuration information;

s3: and repeating the step S2 until the temporary file is empty, and completing the analysis of the configuration file.

On the basis of the technical scheme, the method for acquiring the labels of the head line position and the tail line position of the temporary file comprises the following specific steps:

positioning the head line data of the temporary file, identifying line feed characters in the temporary file line by line, and if the line has no line feed character, determining the tail line data of the temporary file, thereby obtaining the head line position, the tail line position and the total line number of the temporary file;

and reading the head line data and the tail line data of the temporary file to obtain the labels of the head line position and the tail line position of the temporary file.

On the basis of the technical scheme, the method for acquiring the labels of the head line position and the tail line position of the temporary file comprises the following specific steps:

converting the temporary file into a file stream by calling FileInputStream mFileInputStream ═ new FileInputStream (targetFile);

calling an mBufferReader readLine () method to obtain the first line data in the file stream;

calling a targetFile length method to acquire length information of the file stream;

and creating a pointer to point to the head line of the file stream, judging whether a line break character exists forward line by using the pointer until the line break character does not exist, and determining the position of the tail line.

On the basis of the technical scheme, the operation of storing the configuration information corresponding to the valid tag into the memory loading file comprises the following steps:

storing the configuration information corresponding to the effective label of the first line position into a first memory loading subfile;

storing the configuration information corresponding to the effective label of the tail line position in a second memory loading subfile;

the memory loading file at least comprises a first memory loading subfile and a second memory loading subfile.

On the basis of the above technical solution, the step S1 specifically includes:

s11: acquiring a configuration file to be analyzed, and identifying the size of the configuration file;

s12: setting a cache unit, dividing the configuration file into N file units smaller than the cache unit, and combining the file units into temporary files one by one through the cache unit, wherein N is an integer larger than 0.

On the basis of the above technical solution, in step S1, the method further includes:

converting the configuration file into a file object srcmile;

creating a temporary file, and converting the temporary file into a file object targetFile;

converting the file object srcmifitinstream into an input stream object srcmifitinputstream by calling FileInputStream srcmream new FileInputStream (srcFile);

converting the file object targetFile into an output stream object targetFileOutputStream by calling FileOutputStream targetFileOutputStream ═ new FileOutputStream (targetFile);

copying the data of the input stream object srcFileInputStream to the output stream object targetFileOutputStream.

On the basis of the above technical solution, the operation of copying the data of the input stream object srcFileInputStream to the output stream object targetFileOutputStream includes the following steps:

defining a buffer area unit byteBuffer;

read (byteBuffer) function reads data which is not larger than the size of buffer unit byteBuffer from the content of the input stream object srcfilelnputstream into the buffer unit byteBuffer, then writes the content of the buffer unit byteBuffer into the output stream object targetFileOutputStream by calling targetFileOutputStream.

In a second aspect, the present invention also provides a storage medium having a computer program stored thereon, which, when executed by a processor, implements the method in the embodiments of the first aspect.

In a third aspect, the present invention further provides an electronic device, which includes a memory and a processor, where the memory stores a computer program running on the processor, and the processor executes the computer program to implement the method in the first aspect.

In a fourth aspect, the present invention further discloses a system for parsing a configuration file, which includes:

the temporary file acquisition unit is used for acquiring the configuration file to be analyzed and copying the configuration file to obtain a temporary file;

the temporary file analysis unit is used for acquiring labels of a head line position and a tail line position of the temporary file, deleting the invalid labels if the head line position and the tail line position are invalid labels, storing configuration information corresponding to the valid labels into the memory loading file if the head line position and the tail line position are valid labels, and deleting the valid labels and the corresponding configuration information;

and the recursion calling unit is used for using the temporary file analysis unit for multiple times to analyze the temporary file until the temporary file is empty, so as to finish the analysis of the configuration file.

Compared with the prior art, the invention has the advantages that:

the invention copies the configuration file to obtain the temporary file which is imported into the memory for analysis, and analyzes the temporary file by adopting a mode of simultaneously analyzing from head to tail and deleting in time to obtain the configuration information in the temporary file.

Drawings

FIG. 1 is a flow chart of a method for parsing a configuration file according to the present invention;

FIG. 2 is a flowchart illustrating a step S1 of the method for parsing configuration files according to the present invention;

FIG. 3 is a block diagram of a system for parsing configuration files according to the present invention.

In the figure: 1. a temporary file acquisition unit; 2. a temporary file analysis unit; 3. a recursive call unit;

Detailed Description

Interpretation of terms:

FileInputStream srcFileInputStream ═ new FileInputStream (): creating an input stream object srcFileInputStream;

FileOutputStream targetFileOutputStream ═ new FileOutputStream (): creating an output stream object targetFileOutputStream;

read (): reading data of an input stream object srcFileInputStream;

write (): writing data into an output stream object targetFileOutputStream;

FileInputStream mFileInputStream ═ new FileInputStream (): creating a file stream mFileInputStream;

readline (): reading a text line;

length: the file length of the targetFile is obtained.

Embodiments of the present invention will be described in further detail below with reference to the accompanying drawings.

Referring to fig. 1, an embodiment of the present invention provides a method, a storage medium, an electronic device, and a system for configuring a file, where the method copies the configuration file to obtain a temporary file that is imported into a memory for parsing, and parses the temporary file by parsing from beginning to end and deleting the temporary file in time to obtain configuration information therein, and the parsing method can improve work efficiency and reduce memory burden.

In order to achieve the technical effects, the general idea of the application is as follows:

a method for parsing a configuration file comprises the following steps:

s1: acquiring a configuration file to be analyzed, and copying the configuration file to obtain a temporary file;

s2: acquiring tags of a head line position and a tail line position of the temporary file, deleting the invalid tags if the head line position and the tail line position are invalid tags, storing configuration information corresponding to the valid tags into a memory loading file if the head line position and the tail line position are valid tags, and deleting the valid tags and the corresponding configuration information;

s3: and repeating the step S2 until the temporary file is empty, and completing the analysis of the configuration file.

The invention copies the configuration file to obtain the temporary file which is imported into the memory for analysis, and analyzes the temporary file by adopting a mode of simultaneously analyzing from head to tail and deleting in time to obtain the configuration information in the temporary file.

15页详细技术资料下载
上一篇:一种医用注射器针头装配设备
下一篇:一种文件格式转换方法、装置、计算机设备和存储介质

网友询问留言

已有0条留言

还没有人留言评论。精彩留言会获得点赞!

精彩留言,会给你点赞!