Data storage method, data reading method, device, terminal and storage medium
By serializing terminal data and storing it in multi-level directories, the problems of low storage efficiency and difficulty in distinguishing data structures are solved, and efficient data storage and reading are achieved.
Patent Information
- Application Number
- CN202110426433.3
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2021-04-20
- Publication Date
- 2024-10-25
- Estimated Expiration
- 2041-04-20
AI Technical Summary
In the existing technology, when terminals store data, it is easy for the storage efficiency to be low due to over-stratification of directories, and it is difficult to effectively distinguish and store data files with different data structures, resulting in storage space limitations and low data reading efficiency.
By serializing the target data, determine the multi-level directory corresponding to its data structure, and store the data stream in a directory named after the data structure file name to avoid data files with different data structures being stored in the same directory. When reading, query step by step according to multi-level directories to improve efficiency.
It improves data storage and reading efficiency, reduces storage space limitations, supports diversified data structure storage, reduces the number of data file traversals through multi-level directory structures, and improves query speed.
Smart Images

Figure CN113204549B_ABST
Abstract
Description
Technical Field
[0001] The present disclosure relates to the field of computer technology, and in particular to a data processing method, a data reading method, a device, a terminal, and a storage medium. Background Art
[0002] With the continuous update of computer technology and applications, applications have more and more functions and the data generated is becoming more and more diverse. The terminal will store the data generated during the running of the application locally, so that it can be directly used when the application is started next time. In related technologies, the terminal will set a directory corresponding to the application and store the data of the application in the directory, which will result in too much data being stored in the same directory. Summary of the invention
[0003] The present invention provides a data storage method, a data reading method, a device, a terminal and a storage medium, which improve the data reading efficiency.
[0004] According to one aspect of an embodiment of the present disclosure, a data storage method is provided, the data storage method comprising:
[0005] Serializing the target data to be stored to obtain a data stream corresponding to the target data;
[0006] Determine a file directory corresponding to the data structure of the target data, wherein the file directory includes multiple levels of directories, and one level of the directory in the file directory is named after the file name corresponding to the data structure;
[0007] The data stream is stored in a data file corresponding to the file name.
[0008] In the method provided by the embodiment of the present disclosure, since the file directory corresponding to the data structure of the target data is a multi-level directory, and one of the first-level directories is named after the file name corresponding to the data structure, the data file is stored in the directory named after the file name, thereby avoiding storing data files corresponding to different data structures in the same directory. The serializable target data is converted into a data stream, and stored in the form of a data stream in the data file corresponding to the file name. No matter what data structure the target data is, as long as it is serializable, it can be stored, so the data structure that can be stored is more diverse.
[0009] In some embodiments, the serializing the target data to obtain a data stream corresponding to the target data includes:
[0010] In response to the data structure of the target data being associated with the target interface, serializing the target data to obtain the data stream;
[0011] The data corresponding to the data structure associated with the target interface may be serialized.
[0012] In the disclosed embodiment, whether the target data is serializable data is determined based on whether the data structure is associated with the target interface, that is, the target interface is used to indicate whether the data corresponding to the data structure is serializable, which can conveniently determine whether the target data can be stored.
[0013] In some embodiments, the serializing the target data to obtain a data stream corresponding to the target data includes:
[0014] The object output stream is called to serialize the target data to obtain the data stream, and the object output stream is used to convert any data into a corresponding data stream.
[0015] In the disclosed embodiment, the object output stream is called to serialize the target data, converting the target data into a storable data form to facilitate subsequent storage of the data.
[0016] In some embodiments, before determining the file directory corresponding to the data structure of the target data, the data storage method further includes:
[0017] Sending a data storage request to the operating system through the target application;
[0018] The data storage request is received through the operating system, and in response to the data storage request, a primary directory corresponding to the target application is created in the memory space of the operating system.
[0019] In the embodiment of the present disclosure, a first-level directory corresponding to the target application is created in the memory space of the operating system, and the data corresponding to the target application can be subsequently stored in the first-level directory. Compared with the SP storage method in the related art, the limitation of storage space is avoided.
[0020] In some embodiments, determining the file directory corresponding to the data structure of the target data includes:
[0021] Determine a file directory corresponding to a target application to which the target data belongs, wherein the file directory includes at least a first-level directory;
[0022] In response to the first directory not existing under the first-level directory, the first directory is created under the first-level directory, where the first directory is named after the file name corresponding to the data structure of the target data.
[0023] In the disclosed embodiment, in the absence of a directory named with the file name corresponding to the data structure, a directory named with the file name corresponding to the data structure is created under the first-level directory to obtain a multi-level directory. Subsequently, the corresponding data file is indicated based on the created directory named with the file name, which facilitates querying the data file based on the directory. In the case of a multi-level directory, it avoids storing the data file directly under the first-level directory.
[0024] In some embodiments, determining the file directory corresponding to the data structure of the target data includes:
[0025] Determine a file directory corresponding to a target application to which the target data belongs, wherein the file directory includes at least a first-level directory;
[0026] In response to the second directory not existing under the first-level directory, creating the second directory under the first-level directory, wherein the second directory refers to the directory at the previous level of the directory named with the file name corresponding to the data structure;
[0027] A third directory is created under the second directory, and the third directory is named after the file name corresponding to the data structure.
[0028] In the disclosed embodiment, when there is no previous directory of the directory named with the file name corresponding to the data structure, a corresponding next-level directory is created under the first-level directory, and a directory named with the file name is further created under the next-level directory to obtain a multi-level directory. Subsequently, the corresponding data file is indicated based on the created directory named with the file name, which facilitates querying the data file based on the directory.
[0029] In some embodiments, storing the data stream into a data file corresponding to the file name includes:
[0030] In response to the data volume of the data stream not exceeding the maximum data volume of the memory space of the operating system, the data stream is stored in the data file.
[0031] In the embodiment of the present disclosure, as long as the amount of data in the stored data stream does not exceed the maximum data stream of the memory space, the data stream can be stored. Compared with the SP storage method in the related art, a larger amount of data can be stored.
[0032] In some embodiments, determining the file directory corresponding to the data structure of the target data includes:
[0033] A file directory corresponding to the data structure of the target data is queried from a database of the target application to which the target data belongs, wherein the database is used to store a file directory corresponding to at least one data structure of the target application.
[0034] In the disclosed embodiment, it is possible to determine whether a file directory has been created for the data structure of the target data by querying the database. If it has been created, the file directory corresponding to the data structure can be queried from the database, and the target data can be subsequently stored based on the file directory.
[0035] According to another aspect of the embodiments of the present disclosure, a data reading method is provided, the data reading method comprising:
[0036] In response to a data read instruction carrying a data structure, query a target file directory corresponding to the data structure from a database, wherein the target file directory includes multiple levels of directories, and one level of the directories in the target file directory is named after the file name corresponding to the data structure, and the database is used to store a file directory corresponding to at least one data structure;
[0037] From the created directory, query each level of the directory in the target file directory in turn until a directory named with the file name is found;
[0038] Based on the directory named with the file name, read the data file corresponding to the file name.
[0039] The method provided by the embodiment of the present disclosure, during the process of reading data, only needs to find the directory named with the file name according to each level of directory in the target file directory, and the data file corresponding to the file name can be queried without traversing the data files in each level of directory, thereby reducing the number of traversed data files and improving data reading efficiency.
[0040] In some embodiments, the target file directory includes a first directory and a second directory, the second directory is a directory at a lower level than the first directory, and the second directory is named after the file name corresponding to the data structure;
[0041] The step of searching each level of the target file directory in turn from the created directory until a directory named after the file name is found includes:
[0042] Query the first directory from at least one created first-level directory;
[0043] The second directory is queried from at least one secondary directory under the first directory.
[0044] In an embodiment of the present disclosure, a query method for a secondary directory is provided. According to each level of directory in the target file directory, a directory named by the file name is queried by searching level by level. There is no need to directly traverse multiple data files stored in the first directory, which reduces the number of traversed data files and improves the query efficiency of data files.
[0045] In some embodiments, the target file directory includes a third directory, a fourth directory and a fifth directory, the fourth directory is a directory at a level below the third directory, the fifth directory is a directory at a level below the fourth directory, and the fifth directory is named after the file name corresponding to the data structure;
[0046] The step of searching each level of the target file directory in turn from the created directory until a directory named after the file name is found includes:
[0047] Querying the third directory from at least one created first-level directory;
[0048] querying the fourth directory from at least one secondary directory under the third directory;
[0049] The fifth directory is queried from at least one third-level directory under the fourth directory.
[0050] In an embodiment of the present disclosure, a query method for three-level directories is provided. According to each level of directory in the target file directory, a directory named by the file name is queried by searching level by level. There is no need to directly traverse multiple data files stored in the first directory, which reduces the number of traversed data files and improves the query efficiency of data files.
[0051] In some embodiments, the step of reading a data file corresponding to the file name based on a directory named by the file name includes:
[0052] Reading a data stream from the data file based on a directory named by the file name;
[0053] Deserialize the data stream to obtain data corresponding to the data stream.
[0054] In the disclosed embodiment, a data stream is first read from a data file, and the data stream is restored to data of an original data structure to implement data reading.
[0055] In some embodiments, the deserializing the data stream to obtain data corresponding to the data stream includes:
[0056] The object input stream is called to deserialize the data stream to obtain the data, and the object output stream is used to convert any data stream into corresponding data.
[0057] In the disclosed embodiment, since data of various data structures can be serialized, during the deserialization process, the object input stream is called to restore the data stream to realize the reading of the data.
[0058] According to another aspect of the embodiments of the present disclosure, there is provided a data storage device, the data storage device comprising:
[0059] A serialization unit is configured to perform serialization processing on the target data to be stored to obtain a data stream corresponding to the target data;
[0060] A directory determining unit is configured to determine a file directory corresponding to the data structure of the target data, wherein the file directory includes multiple levels of directories, and one level of the directory in the file directory is named after the file name corresponding to the data structure;
[0061] The data storage unit is configured to store the data stream into a data file corresponding to the file name.
[0062] In some embodiments, the serialization unit is configured to perform:
[0063] In response to the data structure of the target data being associated with the target interface, serializing the target data to obtain the data stream;
[0064] The data corresponding to the data structure associated with the target interface may be serialized.
[0065] In some embodiments, the serialization unit is configured to execute a call to an object output stream, perform serialization processing on the target data, and obtain the data stream, and the object output stream is used to convert any data into a corresponding data stream.
[0066] In some embodiments, the data storage device further comprises:
[0067] A request sending unit is configured to execute, through a target application, sending a data storage request to the operating system;
[0068] The directory creation unit is configured to receive the data storage request through the operating system, and create a primary directory corresponding to the target application in the memory space of the operating system in response to the data storage request.
[0069] In some embodiments, the directory determination unit is configured to perform:
[0070] Determine a file directory corresponding to a target application to which the target data belongs, wherein the file directory includes at least a first-level directory;
[0071] In response to the first directory not existing under the first-level directory, the first directory is created under the first-level directory, where the first directory is named after the file name corresponding to the data structure of the target data.
[0072] In some embodiments, the directory determination unit is configured to perform:
[0073] Determine a file directory corresponding to a target application to which the target data belongs, wherein the file directory includes at least a first-level directory;
[0074] In response to the second directory not existing under the first-level directory, creating the second directory under the first-level directory, wherein the second directory refers to the directory at the previous level of the directory named with the file name corresponding to the data structure;
[0075] A third directory is created under the second directory, and the third directory is named after the file name corresponding to the data structure.
[0076] In some embodiments, the data storage unit is configured to store the data stream into the data file in response to the data volume of the data stream not exceeding the maximum data volume of the memory space of the operating system.
[0077] In some embodiments, the directory determination unit is configured to query a file directory corresponding to a data structure of the target data from a database of a target application to which the target data belongs, wherein the database is used to store a file directory corresponding to at least one data structure of the target application.
[0078] According to another aspect of the embodiments of the present disclosure, a data reading device is provided, the data reading device comprising:
[0079] a first directory acquisition unit, configured to execute a data read instruction in response to a data structure, query a target file directory corresponding to the data structure from a database, wherein the target file directory includes multiple levels of directories, and one of the first-level directories in the target file directory is named after the file name corresponding to the data structure, and the database is used to store a file directory corresponding to at least one data structure;
[0080] The directory query unit is configured to query each level of the directory in the target file directory in sequence from the created directory until a directory named with the file name is found;
[0081] The data reading unit is configured to read the data file corresponding to the file name based on the directory named by the file name.
[0082] In some embodiments, the target file directory includes a first directory and a second directory, the second directory is a directory at a lower level than the first directory, and the second directory is named after the file name corresponding to the data structure; the directory query unit is configured to execute:
[0083] Query the first directory from at least one created first-level directory;
[0084] The second directory is queried from at least one secondary directory under the first directory.
[0085] In some embodiments, the target file directory includes a third directory, a fourth directory, and a fifth directory, the fourth directory is a directory at a level below the third directory, the fifth directory is a directory at a level below the fourth directory, and the fifth directory is named after the file name corresponding to the data structure; the directory query unit is configured to execute:
[0086] Querying the third directory from at least one created first-level directory;
[0087] querying the fourth directory from at least one secondary directory under the third directory;
[0088] The fifth directory is queried from at least one third-level directory under the fourth directory.
[0089] In some embodiments, the data reading unit includes:
[0090] A data stream reading subunit is configured to read a data stream from the data file based on a directory named by the file name;
[0091] The deserialization subunit is configured to perform deserialization processing on the data stream to obtain data corresponding to the data stream.
[0092] In some embodiments, the deserialization subunit is configured to execute a call to an object input stream, perform deserialization processing on the data stream, and obtain the data, and the object output stream is used to convert any data stream into corresponding data.
[0093] According to another aspect of an embodiment of the present disclosure, a terminal is provided, the terminal comprising:
[0094] one or more processors;
[0095] a memory for storing the one or more processor-executable instructions;
[0096] The one or more processors are configured to execute the data storage method described in the above aspects, or are configured to execute the data reading method described in the above aspects.
[0097] According to another aspect of an embodiment of the present disclosure, a computer-readable storage medium is provided. When instructions in the storage medium are executed by a processor of a terminal, the terminal is enabled to execute the data storage method described in the above aspects, or the terminal is enabled to execute the data reading method described in the above aspects.
[0098] According to another aspect of the embodiments of the present disclosure, a computer program product is provided, which includes a computer program, and the computer program is executed by a processor to implement the data storage method described in the above aspects, or to implement the data reading method described in the above aspects.
[0099] It is to be understood that the foregoing general description and the following detailed description are exemplary and explanatory only and are not restrictive of the present disclosure. BRIEF DESCRIPTION OF THE DRAWINGS
[0100] The accompanying drawings, which are incorporated in and constitute a part of this specification, illustrate embodiments consistent with the present disclosure and, together with the description, serve to explain the principles of the present disclosure.
[0101] Figure 1 The invention is a flow chart showing a data storage method according to an exemplary embodiment.
[0102] Figure 2 The figure is a flow chart of a data reading method according to an exemplary embodiment.
[0103] Figure 3 The figure is a flow chart showing another data storage method according to an exemplary embodiment.
[0104] Figure 4 The figure is a flow chart showing another data storage method according to an exemplary embodiment.
[0105] Figure 5 is a flow chart showing another data reading method according to an exemplary embodiment.
[0106] Figure 6 is a flow chart showing another data reading method according to an exemplary embodiment.
[0107] Figure 7 is a block diagram of a data storage device according to an exemplary embodiment.
[0108] Figure 8 is a block diagram of another data storage device according to an exemplary embodiment.
[0109] Fig. 9 is a block diagram of a data reading device according to an exemplary embodiment.
[0110] Fig.10 It is a structural block diagram of a terminal according to an exemplary embodiment. DETAILED DESCRIPTION
[0111] In order to enable ordinary persons in the art to better understand the technical solutions of the present disclosure, the technical solutions in the embodiments of the present disclosure will be clearly and completely described below in conjunction with the accompanying drawings.
[0112] It should be noted that the terms "first", "second", etc. in the specification and claims of the present disclosure and the above-mentioned figure descriptions are used to distinguish similar objects, and are not necessarily used to describe a specific order or sequence. It should be understood that the data used in this way can be interchangeable where appropriate, so that the embodiments of the present disclosure described herein can be implemented in an order other than those illustrated or described herein. The embodiments described in the following exemplary embodiments do not represent all embodiments consistent with the present disclosure. Instead, they are merely examples of devices and methods consistent with some aspects of the present disclosure as detailed in the appended claims.
[0113] It should be noted that the user information involved in this disclosure (including but not limited to user device information, user personal information, etc.) is all information authorized by the user or fully authorized by all parties.
[0114] In order to facilitate understanding of the data storage method and data reading method provided by the embodiments of the present disclosure, the keywords involved in the embodiments of the present disclosure are explained as follows:
[0115] SharedPreference (SP, a lightweight storage class): SP is a lightweight storage class used to store data of data structures such as Long, Int, and String.
[0116] Serializable interface: an interface used to identify data that can be serialized. The data structure associated with the Serializable interface can convert between data streams based on ObjectOutputStream (object output stream) and ObjectInputStream (object input stream).
[0117] The data storage method and data reading method provided by the embodiments of the present disclosure can be applied to any application installed in a terminal.
[0118] For example, a user fills in an application form based on a target application, but after filling in a part, he needs to exit the target application before continuing to fill in the form. At this time, the data storage method provided by the embodiment of the present disclosure can be used. When the filled-in data is serializable data, the filled-in data is converted into a corresponding data stream, and a multi-level directory is created in the memory space, and the name of the last-level directory is "baomingbiao". A data file named "baomingbiao" is created under the last-level directory, and the data stream is stored in the data file. Afterwards, when the target application is started again and the application form is continued to be filled in, the data reading method provided by the embodiment of the present disclosure can be used to query the multi-level directory corresponding to the data structure, and query each level of the multi-level directory in the memory space in turn until the directory named "baomingbiao" is queried, and the data file corresponding to "baomingbiao" is read to obtain the filled-in data.
[0119] For another example, when a terminal opens a page in a target application, if the data in the page is serializable data, the data storage method provided by the embodiment of the present disclosure is used to store the data in the page. Later, when the page is displayed again, the data reading method provided by the embodiment of the present disclosure can be used to find the data to be displayed in the page from the locally stored data and display it without having to obtain the page through the network, thereby improving the display speed of the web page.
[0120] Figure 1 is a flowchart of a data storage method according to an exemplary embodiment. Figure 1 The method is applied in a terminal and comprises the following steps:
[0121] 101. Serialize the target data to be stored to obtain a data stream corresponding to the target data.
[0122] The target data is any serializable data, and serialization processing refers to converting the data from the original data structure into a data stream form, and the data stream is a data form that can be stored by the terminal.
[0123] 102. Determine a file directory corresponding to the data structure of the target data, where the file directory includes multiple levels of directories, and one of the levels of directories in the file directory is named after the file name corresponding to the data structure.
[0124] The data structure of the target data refers to the structure of the target data, such as an array, a queue, a number, a linked list, and other data structures. Each data structure has a corresponding file name, which is preset. One of the first-level directories in the file directory refers to any first-level directory except the first-level directory.
[0125] 103. Store the data stream into a data file corresponding to the file name.
[0126] Before storing a data stream, you need to create a data file to store the data stream. If the data file has not been created, create a data file based on the directory and file name named after the file name, and store the data stream in the newly created data file; if a data file corresponding to the reference file name has been created, directly store the data stream in the data file without creating it again.
[0127] The method provided by the embodiment of the present disclosure stores data files in a directory named after the file name corresponding to the data structure of the target data, because the file directory corresponding to the data structure of the target data is a multi-level directory, and one of the first-level directories in the file directory is named after the file name corresponding to the data structure, thereby avoiding storing data files corresponding to different data structures in the same directory. The serializable target data is converted into a data stream, and stored in the form of a data stream in a data file corresponding to the file name. No matter what data structure the target data is, as long as it is serializable, it can be stored, so the data structure that can be stored is more diverse.
[0128] In some embodiments, serializing the target data to obtain a data stream corresponding to the target data includes:
[0129] In response to the data structure of the target data being associated with the target interface, the target data is serialized to obtain a data stream;
[0130] Among them, data corresponding to the data structure associated with the target interface can be serialized.
[0131] In some embodiments, serializing the target data to obtain a data stream corresponding to the target data includes:
[0132] Call the object output stream to serialize the target data to obtain a data stream. The object output stream is used to convert any data into a corresponding data stream.
[0133] In some embodiments, before determining the file directory corresponding to the data structure of the target data, the data storage method further includes:
[0134] Sending a data storage request to the operating system through the target application;
[0135] A data storage request is received through the operating system, and in response to the data storage request, a first-level directory corresponding to the target application is created in the memory space of the operating system.
[0136] In some embodiments, determining a file directory corresponding to a data structure of target data includes:
[0137] Determine a file directory corresponding to a target application to which the target data belongs, where the file directory includes at least one level directory;
[0138] In response to the first directory not existing under the first-level directory, a first directory is created under the first-level directory, and the first directory is named with a file name corresponding to a data structure of the target data.
[0139] In some embodiments, determining a file directory corresponding to a data structure of target data includes:
[0140] Determine a file directory corresponding to a target application to which the target data belongs, where the file directory includes at least one level directory;
[0141] In response to the second directory not existing under the first-level directory, creating the second directory under the first-level directory, the second directory being the directory at the previous level of the directory named with the file name corresponding to the data structure;
[0142] Create a third directory under the second directory. The third directory is named after the file name corresponding to the data structure.
[0143] In some embodiments, storing the data stream into a data file corresponding to the file name includes:
[0144] In response to the data amount of the data stream not exceeding the maximum data amount of the memory space of the operating system, the data stream is stored in the data file.
[0145] In some embodiments, determining a file directory corresponding to a data structure of target data includes:
[0146] A file directory corresponding to the data structure of the target data is queried from a database of the target application to which the target data belongs, where the database is used to store a file directory corresponding to at least one data structure of the target application.
[0147] Figure 2 is a flowchart of another data storage method according to an exemplary embodiment. Figure 2 The method is applied to a terminal, which is a portable, pocket-sized, handheld or other type of terminal, such as a mobile phone, a computer, a tablet computer, etc. The method comprises the following steps:
[0148] 201. The terminal obtains target data to be stored.
[0149] The embodiments of the present disclosure are described by taking a target application installed in a terminal as an example, where the target application is an instant messaging application, a video application, a short video application, a game application or other applications.
[0150] Among them, the target data is the data entered by the user in the target application based on the terminal, for example, the target data is the user name, password and other data entered by the user; or, the target data is the data sent by other electronic devices to the current terminal, for example, the target data is the chat information sent by other terminals to the current terminal, or the target data is the page content sent to the terminal by the server corresponding to the target application.
[0151] After the terminal obtains the target data in the target application, it determines whether the target data is serializable data. If the target data is serializable data, the subsequent steps of storing the target data are executed. If the target data is not serializable data, the subsequent steps of storing the target data are not executed. Among them, serializable data refers to data that can be represented by a sequence. For example, if the target data is a string of numbers "12345", each number can be converted into a corresponding sequence, then this string of numbers can be serialized.
[0152] Furthermore, the data structure of the target data has a corresponding file name, and the data structure refers to the structure of the target data, for example, an array, a queue, a linked list, and other data structures. In some embodiments, the target application has a corresponding database, and the database is used to store the file name corresponding to at least one data structure of the target application. After the corresponding file directory is subsequently created for the data structure, the database is also used to store the file directory corresponding to the at least one data structure.
[0153] In some embodiments, a serializable data structure is associated with a target interface, that is, whether the data is serializable is determined based on whether the data structure is associated with the target interface, so that it is convenient to determine whether the target data can be stored. If the data structure is associated with the target interface, it means that the data corresponding to the data structure is serializable. If the data structure is not associated with the target interface, it means that the data corresponding to the data structure is not serializable. Among them, the target interface is used to indicate that the data corresponding to the associated data structure is serializable.
[0154] 202. In response to the target data being serializable data, the terminal performs serialization processing on the target data to obtain a data stream corresponding to the target data.
[0155] When the target data is serializable data, the terminal performs serialization processing on the target data to obtain a data stream corresponding to the target data. Serialization processing on the target data means converting the target data into a storable form, and the data stream includes a sequence corresponding to the target data, and the data stream is composed of "0" and "1", for example, the data stream is a binary data stream.
[0156] In some embodiments, the terminal determines that the target data is serializable in response to the data structure of the target data being associated with the target interface, and performs serialization processing on the target data to obtain a data stream.
[0157] Regarding the method of generating data streams, in some embodiments, the terminal calls the object output stream to serialize the target data to obtain a data stream, which is convenient for subsequent data storage. Among them, the object output stream is used to convert any data into a corresponding data stream. Furthermore, for different data structures, the object output stream is called and serialization is performed using different serialization methods.
[0158] In some embodiments, the terminal serializes the target data, and the acquired data stream includes not only the original target data, but also a structure identifier corresponding to the data structure of the target data. The structure identifier is used to indicate the original data structure of the data stream, so as to facilitate the subsequent recovery of the data stream according to the structure identifier.
[0159] In some embodiments, after obtaining the data stream through the target application, the terminal generates a data storage instruction, which carries the data stream and instructs to store the data stream. The subsequent operating system responds to the data storage instruction to store the data stream.
[0160] In some embodiments, in response to the target data being serializable data, the terminal directly serializes the target data and executes subsequent storage steps; or, the terminal detects that the target data is serializable data and detects a storage operation performed on the target data, and then serializes the target data and executes subsequent storage steps. In other words, the terminal can automatically store serializable data, or it can store serializable data in response to a storage operation triggered by the user. For example, the target data to be stored is the registration information entered by the user in the registration form. In one case, after the terminal detects the registration information entered by the user, it determines that the registration information is serializable data and automatically executes subsequent storage steps; in another case, a save control is displayed below the registration form, and the terminal determines that the registration information is serializable data, and after detecting the user's triggering operation on the save control, it executes subsequent storage steps.
[0161] 203. The terminal determines a file directory corresponding to the data structure of the target data.
[0162] For the target application, after the terminal installs the target application, it sends a data storage request to the operating system through the target application, receives the data storage request through the operating system, and creates a first-level directory corresponding to the target application in the memory space of the operating system in response to the data storage request. Afterwards, the data generated by the target application can create a second-level directory, a third-level directory or more directories under the first-level directory, and create a data file for storing data based on one of the created first-level directories. Among them, one of the first-level directories in the file directory is any first-level directory except the first-level directory. For example, if the file directory includes a fourth-level directory, then one of the first-level directories is any first-level directory in the second-level directory, the third-level directory or the fourth-level directory in the file directory.
[0163] Creating a primary directory in the memory space of the operating system can avoid the limitation of the maximum storage capacity of the storage space on the amount of stored data. The amount of data to be stored can be stored as long as it does not exceed the maximum data capacity of the memory space of the operating system. Compared with the SP storage method in the related art, the problem of storage space limitation is solved. The related art can only store lightweight data, while the embodiment of the present disclosure can store both lightweight data and non-lightweight data.
[0164] In the disclosed embodiment, the terminal determines that the file directory corresponding to the data structure includes two situations. One is that the terminal stores the data corresponding to the data structure for the first time, and the file directory corresponding to the data structure has not been created in the terminal; the other is that the terminal does not store the data corresponding to the data structure for the first time, and the file directory corresponding to the data structure has been created in the terminal.
[0165] For the above two situations, the terminal needs to first determine whether the data corresponding to the data structure is stored for the first time. In some embodiments, the terminal queries the file directory corresponding to the data structure from the database of the target application to which the target data belongs. If the file directory corresponding to the data structure does not exist in the database, it means that the file directory corresponding to the data structure has not been created before. If the file directory corresponding to the data structure exists in the database, it means that the file directory corresponding to the data structure has been created before.
[0166] The first type: the terminal stores the target data corresponding to the data structure for the first time.
[0167] In this case, in some embodiments, the terminal creates a file directory including a primary directory and a secondary directory. The terminal determines the file directory corresponding to the target application to which the target data belongs, that is, determines the primary directory corresponding to the target application, and in response to the first directory not existing under the primary directory, creates a first directory under the primary directory. The first directory is the next level directory of the primary directory, that is, the secondary directory under the primary directory, and the first directory is named after the file name corresponding to the data structure of the target data.
[0168] In some embodiments, the terminal creates a file directory including a first-level directory, a second-level directory, and a third-level directory. The terminal determines the file directory corresponding to the target application to which the target data belongs, that is, determines the first-level directory corresponding to the target application, and in response to the second directory not existing under the first-level directory, creates a second directory under the first-level directory, and creates a third directory under the second directory. Among them, the second directory is the next-level directory of the first-level directory, that is, the second-level directory under the first-level directory, and the second directory refers to the upper-level directory of the directory named with the file name corresponding to the data structure, and the third directory is the next-level directory of the second directory, that is, the third-level directory under the second-level directory, and the third directory is named with the file name corresponding to the data structure.
[0169] In the case where there is no directory named with the file name corresponding to the data structure, a directory named with the file name corresponding to the data structure is created under the first-level directory to obtain a multi-level directory. Subsequently, the corresponding data file is indicated based on the created directory named with the file name, which facilitates querying the data file based on the directory. In the case of a multi-level directory, it avoids storing the data file directly under the first-level directory.
[0170] In the case where the file directory includes three levels of directories, when there are multiple third directories named with file names corresponding to multiple data structures under the second directory, although the target data is stored for the first time, the data of other data structures under the second directory have been stored, and the second directory has been created. At this time, the terminal determines the first-level directory and the second directory corresponding to the data structure, and creates a third-level directory under the second directory, without the need to repeatedly create the second directory.
[0171] In some embodiments, the terminal queries the database of the target application for a file name corresponding to the data structure of the target data, and uses the file name as the name of the first directory.
[0172] The second type: the terminal does not store the target data corresponding to the data structure for the first time.
[0173] In this case, the terminal can directly query the file directory corresponding to the data structure of the target data from the database, and directly search for the file directory with the same name as the file directory from the memory space of the operating system according to the file directory, without creating a directory. For example, the target data to be stored is the registration information entered by the user in the registration form. The registration information filled in by the user has been stored before. This time the user modifies part of the information, and the previously stored registration information needs to be updated. At this time, the registration information is not stored for the first time. The terminal can query the file directory corresponding to the last stored registration information from the database, and store the modified registration information in the last data file according to the queried file directory.
[0174] It should be noted that the above embodiment is only described by taking the case where the file directory includes two levels of directories or three levels of directories as an example. In another embodiment, the file directory may include four levels of directories, five levels of directories, or more levels of directories. Regardless of the number of levels of directories, the last level of directories is named after the file name corresponding to the data structure.
[0175] In the above embodiment, only one of the first-level directories in the file directory is used as an example for explanation. In another embodiment, when the first-level directory is not the last-level directory in the file directory, in addition to storing target data based on the directory, a next-level directory can be created under the first-level directory to store other data based on the next-level directory.
[0176] For the file directory, in some embodiments, the application identifier of the target application is used as the name of the first-level directory, and the file name is used as the name of the second-level directory. For example, the application identifier is APP, and the file name is KEY1, then the file directory "APP\KEY1" is obtained. Alternatively, the name of the reference directory corresponding to the data structure is used as the name of the second-level directory, and the file name is used as the name of the third-level directory. For example, the application identifier is APP, the reference directory name is KEY2, and the file name is KEY1, then the file directory "APP\KEY2\KEY1" is obtained.
[0177] 204. The terminal stores the data stream into a data file corresponding to the file name.
[0178] After the terminal determines the file directory corresponding to the data structure, if it is the first time to store the target data corresponding to the data structure, it creates a data file corresponding to the file name based on the file directory and the file name, and stores the data stream in the data file; if it is not the first time to store the target data corresponding to the data structure, it queries the data file corresponding to the file name based on the file directory, and stores the data stream in the data file.
[0179] By adopting the above data storage method, the stored target data can be stored for a long time, or in order to save storage space, after the target data is stored for a reference time, the terminal automatically deletes the stored target data and the data file storing the target data, and then when the target data is stored again, the operation is performed according to the data structure of the first storage of the target data. The reference time is one day, one week, one month, etc.
[0180] The data storage process in the embodiment of the present disclosure is shown in Figure 3As shown in the flowchart, after the terminal responds to the target data, it determines that the data structure of the target data is serializable, then calls the object output stream to convert the target data into a corresponding data stream, and then determines the corresponding file directory based on the file name corresponding to the data structure, writes the data stream into the data file corresponding to the file name, and completes the storage of the target data.
[0181] In addition, after the terminal stores the data stream in the data file, it can also read the stored data stream from the data file to obtain the stored target data. For example, the terminal displays a page based on the target application and stores the data in the page using the above storage method. After that, the user closes the page and opens the page again, the terminal reads the data in the page from the memory space and displays the page. For the detailed process of the terminal reading data, see the following Figure 5 The embodiment shown.
[0182] It should be noted that the embodiments of the present disclosure are only described by taking any target application as an example. In another embodiment, when other applications are installed in the terminal, the storage method of the data of other applications is the same as the storage method of the data of the target application. The difference is that the data belonging to different applications are stored in different first-level directories. For example, the data of application A is stored in the first-level directory "A", and the data of application B is stored in the first-level directory "B".
[0183] The method provided by the embodiment of the present disclosure stores data files in directories named after the file names, thus avoiding storing data files corresponding to different data structures in the same directory, because the file directory corresponding to the data structure of the target data is a multi-level directory, and one of the first-level directories in the file directory is named after the file name corresponding to the data structure. The serializable target data is converted into a data stream, and stored in the data file corresponding to the file name in the form of a data stream. No matter which data structure the target data is, it can be stored as long as it is serializable, so the data structures that can be stored are more diverse.
[0184] Furthermore, whether the target data is serializable data is determined based on whether the data structure is associated with the target interface, that is, the target interface is used to indicate whether the data corresponding to the data structure is serializable, which can conveniently determine whether the target data can be stored.
[0185] In addition, a first-level directory corresponding to the target application is created in the memory space of the operating system, and the data corresponding to the target application can be stored in the first-level directory subsequently. Compared with the SP storage method in the related art, the limitation of storage space is avoided.
[0186] In the embodiment of the present disclosure, the above Figure 3After storing data using the data storage method shown in the figure, the corresponding data reading method can also be used to read the stored data from the data file, through the following Figure 5 The illustrated embodiment illustrates the data reading process.
[0187] Figure 4 is a flow chart of a data reading method according to an exemplary embodiment. Figure 2 The method is applied in a terminal and comprises the following steps:
[0188] 401. In response to a data read instruction carrying a data structure, query a target file directory corresponding to the data structure from a database.
[0189] The data read instruction is used to instruct to read the data in the data file corresponding to the data structure, and the database is used to store the file directory corresponding to at least one data structure. According to the data structure carried by the data read instruction, the corresponding target file name is queried from the database, and the target file directory includes multiple directories, and one of the first-level directories in the target file directory is named after the file name corresponding to the data structure.
[0190] 402. From the created directory, search each level of the target file directory in turn until a directory named with the file name is found.
[0191] The created directory includes not only the target file directory, but also the file directories corresponding to other data structures. Therefore, it is necessary to query each level of the target file directory layer by layer until the directory named by the file name is found. For example, if the target file directory includes a first-level directory and a second-level directory, the first-level directory is queried first, and then the second-level directory is queried under the queried first-level directory.
[0192] 403. Based on the directory named by the file name, read the data file corresponding to the file name.
[0193] Since one of the first-level directories in the file directory is named after the file name corresponding to the data structure, and the name of the directory is the same as the file name corresponding to the data file, the directory can indicate that the corresponding data file has been queried, and data can be read from the queried data file to realize data reading.
[0194] The method provided by the embodiment of the present disclosure, during the process of reading data, only needs to find the directory named with the file name according to each level of directory in the target file directory, and the data file corresponding to the file name can be queried without traversing the data files in each level of directory, thereby reducing the number of traversed data files and improving data reading efficiency.
[0195] In some embodiments, the target file directory includes a first directory and a second directory, the second directory is a directory at a lower level than the first directory, and the second directory is named after the file name corresponding to the data structure;
[0196] From the created directory, query each level of the target file directory in turn until the directory named after the file is found, including:
[0197] Querying a first directory from at least one first-level directory that has been created;
[0198] A second directory is queried from at least one secondary directory under the first directory.
[0199] In some embodiments, the target file directory includes a third directory, a fourth directory, and a fifth directory, the fourth directory is a directory one level below the third directory, the fifth directory is a directory one level below the fourth directory, and the fifth directory is named after the file name corresponding to the data structure;
[0200] From the created directory, query each level of the target file directory in turn until the directory named after the file is found, including:
[0201] Query the third directory from at least one first-level directory that has been created;
[0202] Searching a fourth directory from at least one secondary directory under the third directory;
[0203] The fifth directory is searched from at least one third-level directory under the fourth directory.
[0204] In some embodiments, based on a directory named by the file name, reading a data file corresponding to the file name includes:
[0205] Read data stream from data file based on directory named by file name;
[0206] Deserialize the data stream to obtain the data corresponding to the data stream.
[0207] In some embodiments, deserializing the data stream to obtain data corresponding to the data stream includes:
[0208] Call the object input stream to deserialize the data stream to obtain data. The object output stream is used to convert any data stream into corresponding data.
[0209] Figure 5 is a flow chart of a data reading method according to an exemplary embodiment. Figure 5 The execution subject of the method is a terminal, and includes the following steps:
[0210] 501. In response to a data read instruction carrying a data structure, the terminal queries a database for a target file directory corresponding to the data structure.
[0211] The data read instruction is used to instruct to read the data of the carried data structure. The target file directory includes multiple directories, for example, the target file directory includes two levels of directories, that is, the target file directory includes a first directory and a second directory, and the second directory is a directory under the first directory, or the target file directory includes three levels of directories, that is, the target file directory includes a third directory, a fourth directory and a fifth directory, the fourth directory is a directory under the third directory, and the fifth directory is a directory under the fourth directory.
[0212] The database is used to store a file directory corresponding to at least one data structure, and the database is a database in the terminal. In some embodiments, for multiple applications installed in the terminal, different applications can set corresponding databases respectively, or different applications share a database. In the case of sharing a database, the data structure, application identifier and file directory need to be stored correspondingly to distinguish the data structures corresponding to different applications.
[0213] In some embodiments, when the terminal fails to query the target file directory corresponding to the data structure from the database, it means that the data of the data structure is not stored, or the data of the data structure has been deleted.
[0214] The disclosed embodiments are described using the target application as an example. In some embodiments, after the terminal starts the target application, when a page of the target application is displayed, a data read instruction is generated, and the data read instruction carries a data structure determined based on the page. In response to the data read instruction, the terminal queries the file directory corresponding to the data structure from the database.
[0215] 502. The terminal sequentially searches each level of the directory in the target file directory from the created directory until a directory named with the file name corresponding to the data structure is found.
[0216] The target file directory queried by the terminal from the database includes multiple levels of directories. During the query process, the terminal starts from the first-level directory and queries the second-level directory, the third-level directory, etc. in sequence according to the multiple levels of directories in the target file directory until a directory named with the file name corresponding to the data structure is queried.
[0217] In some embodiments, when the target file directory includes a first directory and a second directory, the terminal queries the first directory from at least one first-level directory that has been created; and queries the second directory from at least one second-level directory under the first directory, where the second-level directory is a directory named after the file name.
[0218] Each directory has a corresponding name. The terminal queries for a first-level directory with the same name as the first directory from at least one first-level directory that has been created, and then queries for a second-level directory with the same name as the second directory from at least one second-level directory under the queried first-level directory.
[0219] In some embodiments, when the target file directory includes a third directory, a fourth directory, and a fifth directory, the terminal queries the third directory from at least one first-level directory that has been created, queries the fourth directory from at least one second-level directory under the third directory, and queries the fifth directory from at least one third-level directory under the fourth directory, and the fifth directory is the directory named after the file name.
[0220] Each directory has a corresponding name. The terminal queries for a first-level directory whose name is the same as that of the third directory from at least one first-level directory that has been created, and then queries for a second-level directory whose name is the same as that of the fourth directory from at least one second-level directory under the queried first-level directory, and then queries for a third-level directory whose name is the same as that of the fifth directory from at least one third-level directory under the queried second-level directory.
[0221] In the case where multiple data files are stored in a file directory, according to each level of directory in the target file directory, the third directory is first queried, and then the fourth directory is queried under the queried third directory, and then the fifth directory is queried under the queried fourth directory. By searching level by level, the last level of directory is queried, and there is no need to directly traverse the multiple data files stored in the first directory, which reduces the number of traversed data files and improves the query efficiency of data files.
[0222] 503. The terminal reads a data stream from a data file corresponding to the file name based on the directory named by the file name.
[0223] After the terminal queries the directory named by the file name, it queries the data file corresponding to the directory, and then determines whether the data file includes a data stream. If the data stream is included, the data stream is read from the data file. If the data stream is not included, it means that the data stream is not stored in the data file, or the stored data stream has been deleted.
[0224] 504. The terminal deserializes the data stream to obtain data corresponding to the data stream.
[0225] Since the data stream is the data format used when storing data, if you need to display the data to the user, you also need to deserialize the data stream and restore it to its original data structure so that the terminal can use the read data. For example, the number "1" is stored as "00000001", so you need to convert "00000001" to "1" so that the terminal can display the number "1" to the user.
[0226] In some embodiments, the terminal calls the object input stream to deserialize the data stream to obtain the corresponding data. The object output stream is used to convert any data stream into the corresponding data, that is, to restore the data stream to the data corresponding to the original data structure. In addition, since data of various data structures can be serialized, during the deserialization process, the object input stream is called to restore the data stream, thereby ensuring that the data stream is restored to the original data structure, avoiding the data structure of the data obtained by the deserialization process is not the required structure.
[0227] In some embodiments, the data stream includes a structure identifier corresponding to the data structure, and the terminal converts the data stream into data corresponding to the original data structure according to the structure identifier.
[0228] Furthermore, for the target application, after the terminal reads the data, the terminal displays the read data based on the target application. If the read data is data that the user has input before, the user does not need to input it again, simplifying the user operation; if the read data is data obtained from the server, it does not need to be obtained from the server again, improving the display speed.
[0229] For the data reading process in the disclosed embodiment, see Figure 6 The flowchart shown in the figure searches for the corresponding data file in the file system based on the target file directory corresponding to the data structure, calls the object input stream, reads the data file, and restores the read data stream to the required data structure. The file system is a system composed of multiple data files after storing multiple data files in the memory space.
[0230] For example, the name of the first-level directory is APP, the names of the two second-level directories under the first-level directory are KEY1 and KEY2, the names of the three third-level directories under the second-level directory KEY1 are KEY3, KEY4 and KEY5, and the names of the three third-level directories under the second-level directory KEY2 are KEY6, KEY7 and KEY8, and each third-level directory has a corresponding data file. The terminal queries from the database that the target file directory corresponding to the data structure is "APP\KEY1\KEY5". When querying the data file, the first-level directory APP is first queried, and then the two second-level directories are traversed to the second-level directory KEY1, and then the three third-level directories under the second-level directory KEY1 are traversed to the third-level directory KEY5, so as to read the data file under the third-level directory KEY5. In the related art, the data files are stored in the first-level directory APP, and when reading the data, all the data files need to be traversed.
[0231] The structure of the multi-level directory in the embodiment of the present disclosure has a similar data reading efficiency when there are fewer data files than the method of storing data files in the same directory in the related art. However, when there are too many data files, it takes a long time to traverse all the data files in the related art, and it will affect the operating efficiency of the terminal. For example, if there are 1,000 data files, if they are all stored in the same directory, at most 1,000 data files need to be traversed to find the required data files. The multi-level directory in the present disclosure sets two secondary directories under the primary directory, and 500 data files are stored in each secondary directory. At this time, it is only necessary to traverse the two secondary directories to determine the secondary directory to be searched, and then traverse at most 500 data files to find the required data files.
[0232] The method provided by the embodiment of the present disclosure, for the case where multiple data files are stored in a file directory, compared with the related art of traversing multiple data files in the same directory to read data, the present disclosure only needs to find the directory named with the file name according to each level of directory in the target file directory, and can query the data file corresponding to the file name, thereby reducing the number of traversed data files and improving data reading efficiency.
[0233] Furthermore, by searching each level of the directory in the target file directory, the directory named by the file name is found without traversing the data files in each level of the directory, thus reducing the number of traversed data files and improving the query efficiency of data files.
[0234] Furthermore, since data of various data structures can be serialized, during deserialization, the object input stream is called to restore the data stream, which can ensure that the data stream is restored to the original data structure and avoid the data structure of the deserialized data not being the required structure.
[0235] Figure 7 is a block diagram of a data storage device according to an exemplary embodiment. Figure 7 , the device comprises:
[0236] The serialization unit 701 is configured to perform serialization processing on the target data to be stored to obtain a data stream corresponding to the target data;
[0237] A directory determining unit 702 is configured to determine a file directory corresponding to a data structure of target data, wherein the file directory includes multiple levels of directories, and one level of the directory in the file directory is named after the file name corresponding to the data structure;
[0238] The data storage unit 703 is configured to store the data stream into a data file corresponding to the file name.
[0239] In the device provided by the embodiment of the present disclosure, since the file directory corresponding to the data structure of the target data is a multi-level directory, and one of the first-level directories in the file directory is named after the file name corresponding to the data structure, the data file is stored in the directory named after the file name, thereby avoiding storing data files corresponding to different data structures in the same directory. The serializable target data is converted into a data stream, and stored in the form of a data stream in the data file corresponding to the file name. No matter what data structure the target data is, as long as it is serializable, it can be stored, so the data structure that can be stored is more diverse.
[0240] In some embodiments, the serialization unit 701 is configured to perform:
[0241] In response to the data structure of the target data being associated with the target interface, the target data is serialized to obtain a data stream;
[0242] Among them, data corresponding to the data structure associated with the target interface can be serialized.
[0243] In some embodiments, the serialization unit 701 is configured to execute a call to an object output stream, perform serialization processing on target data, and obtain a data stream. The object output stream is used to convert any data into a corresponding data stream.
[0244] In some embodiments, see Figure 8 , the data storage device further comprises:
[0245] The request sending unit 704 is configured to send a data storage request to the operating system through the target application;
[0246] The directory creation unit 705 is configured to receive a data storage request through the operating system, and create a primary directory corresponding to the target application in the memory space of the operating system in response to the data storage request.
[0247] In some embodiments, the directory determination unit 702 is configured to perform:
[0248] Determine a file directory corresponding to a target application to which the target data belongs, where the file directory includes at least one level directory;
[0249] In response to the first directory not existing under the first-level directory, a first directory is created under the first-level directory, and the first directory is named with a file name corresponding to a data structure of the target data.
[0250] In some embodiments, the directory determination unit 702 is configured to perform:
[0251] Determine a file directory corresponding to a target application to which the target data belongs, where the file directory includes at least one level directory;
[0252] In response to the second directory not existing under the first-level directory, creating the second directory under the first-level directory, the second directory being the directory at the previous level of the directory named with the file name corresponding to the data structure;
[0253] Create a third directory under the second directory. The third directory is named after the file name corresponding to the data structure.
[0254] In some embodiments, the data storage unit 703 is configured to store the data stream into a data file in response to the data volume of the data stream not exceeding the maximum data volume of the memory space of the operating system.
[0255] In some embodiments, the directory determination unit 702 is configured to query a file directory corresponding to a data structure of the target data from a database of a target application to which the target data belongs, where the database is used to store a file directory corresponding to at least one data structure of the target application.
[0256] Regarding the device in the above embodiment, the specific manner in which each unit performs the operation has been described in detail in the embodiment of the method, and will not be elaborated here.
[0257] Fig. 9 is a block diagram of a data reading device according to an exemplary embodiment. Fig. 9 , the device comprises:
[0258] A first directory acquisition unit 901 is configured to execute a data read instruction in response to the data structure, query a target file directory corresponding to the data structure from a database, the target file directory includes multiple directories, and one of the first-level directories in the target file directory is named after the file name corresponding to the data structure, and the database is used to store a file directory corresponding to at least one data structure;
[0259] The directory query unit 902 is configured to query each level of the directory in the target file directory in sequence from the created directory until a directory named by the file name is found;
[0260] The data reading unit 903 is configured to execute, based on a directory named with the file name, reading a data file corresponding to the file name.
[0261] The device provided by the embodiment of the present disclosure, during the process of reading data, only needs to find the directory named with the file name according to each level of directory in the target file directory, and can query the data file corresponding to the file name without traversing the data files in each level of directory, thereby reducing the number of traversed data files and improving data reading efficiency.
[0262] In some embodiments, the target file directory includes a first directory and a second directory, the second directory is a directory at a lower level than the first directory, and the second directory is named after the file name corresponding to the data structure; the directory query unit 902 is configured to execute:
[0263] Querying a first directory from at least one first-level directory that has been created;
[0264] A second directory is queried from at least one secondary directory under the first directory.
[0265] In some embodiments, the target file directory includes a third directory, a fourth directory, and a fifth directory, the fourth directory is a directory at a level below the third directory, the fifth directory is a directory at a level below the fourth directory, and the fifth directory is named after the file name corresponding to the data structure; the directory query unit 902 is configured to execute:
[0266] Query the third directory from at least one first-level directory that has been created;
[0267] Searching a fourth directory from at least one secondary directory under the third directory;
[0268] The fifth directory is searched from at least one third-level directory under the fourth directory.
[0269] In some embodiments, the data reading unit 903 includes:
[0270] The data stream reading subunit is configured to execute reading of the data stream from the data file based on the directory named by the file name;
[0271] The deserialization subunit is configured to perform deserialization processing on the data stream to obtain data corresponding to the data stream.
[0272] In some embodiments, the deserialization subunit is configured to execute a call to an object input stream, perform deserialization processing on a data stream, and obtain data, and the object output stream is used to convert any data stream into corresponding data.
[0273] Regarding the device in the above embodiment, the specific manner in which each unit performs the operation has been described in detail in the embodiment of the method, and will not be elaborated here.
[0274] In an exemplary embodiment, an electronic device is provided, which includes one or more processors and a memory for storing executable instructions of the one or more processors; wherein the one or more processors are configured to execute the data storage method or the data reading method in the above-mentioned embodiment.
[0275] In some embodiments, the electronic device is provided as a terminal. Fig.101 is a block diagram of a terminal 1000 according to an exemplary embodiment. The terminal 1000 may be a portable mobile terminal, such as a smart phone, a tablet computer, an MP3 player (Moving Picture Experts Group Audio Layer III), an MP4 player (Moving Picture Experts Group Audio Layer IV), a laptop computer or a desktop computer. The terminal 1000 may also be referred to as a user device, a portable terminal, a laptop terminal, a desktop terminal or other names.
[0276] The terminal 1000 includes: a processor 1001 and a memory 1002 .
[0277] The processor 1001 may include one or more processing cores, such as a 4-core processor, an 8-core processor, etc. The processor 1001 may be implemented in at least one hardware form of DSP (Digital Signal Processing), FPGA (Field-Programmable Gate Array), and PLA (Programmable Logic Array). The processor 1001 may also include a main processor and a coprocessor. The main processor is a processor for processing data in the awake state, also known as a CPU (Central Processing Unit); the coprocessor is a low-power processor for processing data in the standby state. In some embodiments, the processor 1001 may be integrated with a GPU (Graphics Processing Unit), which is responsible for rendering and drawing the content to be displayed on the display screen. In some embodiments, the processor 1001 may also include an AI (Artificial Intelligence) processor, which is used to process computing operations related to machine learning.
[0278] The memory 1002 may include one or more computer-readable storage media, which may be non-transitory. The memory 1002 may also include a high-speed random access memory, and a non-volatile memory, such as one or more disk storage devices, flash memory storage devices. In some embodiments, the non-transitory computer-readable storage medium in the memory 1002 is used to store at least one program code, which is used to be executed by the processor 1001 to implement the data storage method or data reading method provided in the method embodiment of the present disclosure.
[0279] In some embodiments, the terminal 1000 may also optionally include: a peripheral device interface 1003 and at least one peripheral device. The processor 1001, the memory 1002 and the peripheral device interface 1003 may be connected via a bus or a signal line. Each peripheral device may be connected to the peripheral device interface 1003 via a bus, a signal line or a circuit board. Specifically, the peripheral device includes: at least one of a radio frequency circuit 1004, a display screen 1005, a camera assembly 1006, an audio circuit 1007, a positioning assembly 1008 and a power supply 1009.
[0280] The peripheral device interface 1003 may be used to connect at least one peripheral device related to I / O (Input / Output) to the processor 1001 and the memory 1002. In some embodiments, the processor 1001, the memory 1002, and the peripheral device interface 1003 are integrated on the same chip or circuit board; in some other embodiments, any one or two of the processor 1001, the memory 1002, and the peripheral device interface 1003 may be implemented on a separate chip or circuit board, which is not limited in this embodiment.
[0281] The radio frequency circuit 1004 is used to receive and transmit RF (Radio Frequency) signals, also known as electromagnetic signals. The radio frequency circuit 1004 communicates with the communication network and other communication devices through electromagnetic signals. The radio frequency circuit 1004 converts electrical signals into electromagnetic signals for transmission, or converts received electromagnetic signals into electrical signals. In some embodiments, the radio frequency circuit 1004 includes: an antenna system, an RF transceiver, one or more amplifiers, a tuner, an oscillator, a digital signal processor, a codec chipset, a user identity module card, and the like. The radio frequency circuit 1004 can communicate with other terminals through at least one wireless communication protocol. The wireless communication protocol includes, but is not limited to: the World Wide Web, a metropolitan area network, an intranet, various generations of mobile communication networks (2G, 3G, 4G and 5G), a wireless local area network and / or a WiFi (Wireless Fidelity) network. In some embodiments, the radio frequency circuit 1004 may also include circuits related to NFC (Near Field Communication), which is not limited in the present disclosure.
[0282] The display screen 1005 is used to display a UI (User Interface). The UI may include graphics, text, icons, videos, and any combination thereof. When the display screen 1005 is a touch display screen, the display screen 1005 also has the ability to collect touch signals on the surface or above the surface of the display screen 1005. The touch signal can be input to the processor 1001 as a control signal for processing. At this time, the display screen 1005 can also be used to provide virtual buttons and / or virtual keyboards, also known as soft buttons and / or soft keyboards. In some embodiments, the display screen 1005 can be one, arranged on the front panel of the terminal 1000; in other embodiments, the display screen 1005 can be at least two, respectively arranged on different surfaces of the terminal 1000 or in a folding design; in other embodiments, the display screen 1005 can be a flexible display screen, arranged on a curved surface or a folding surface of the terminal 1000. Even, the display screen 1005 can also be arranged as a non-rectangular irregular figure, that is, a special-shaped screen. The display screen 1005 can be made of materials such as LCD (Liquid Crystal Display) and OLED (Organic Light-Emitting Diode).
[0283] The camera assembly 1006 is used to capture images or videos. In some embodiments, the camera assembly 1006 includes a front camera and a rear camera. The front camera is arranged on the front panel of the terminal, and the rear camera is arranged on the back of the terminal. In some embodiments, there are at least two rear cameras, which are any one of a main camera, a depth of field camera, a wide-angle camera, and a telephoto camera, so as to realize the fusion of the main camera and the depth of field camera to realize the background blur function, the fusion of the main camera and the wide-angle camera to realize panoramic shooting and VR (Virtual Reality) shooting function or other fusion shooting functions. In some embodiments, the camera assembly 1006 may also include a flash. The flash can be a monochrome temperature flash or a dual-color temperature flash. The dual-color temperature flash refers to a combination of a warm light flash and a cold light flash, which can be used for light compensation at different color temperatures.
[0284] The audio circuit 1007 may include a microphone and a speaker. The microphone is used to collect sound waves from the user and the environment, and convert the sound waves into electrical signals and input them into the processor 1001 for processing, or input them into the radio frequency circuit 1004 to achieve voice communication. For the purpose of stereo acquisition or noise reduction, there may be multiple microphones, which are respectively arranged at different parts of the terminal 1000. The microphone may also be an array microphone or an omnidirectional acquisition microphone. The speaker is used to convert the electrical signal from the processor 1001 or the radio frequency circuit 1004 into sound waves. The speaker may be a traditional film speaker or a piezoelectric ceramic speaker. When the speaker is a piezoelectric ceramic speaker, it can not only convert the electrical signal into sound waves audible to humans, but also convert the electrical signal into sound waves inaudible to humans for purposes such as ranging. In some embodiments, the audio circuit 1007 may also include a headphone jack.
[0285] The positioning component 1008 is used to locate the current geographical location of the terminal 1000 to implement navigation or LBS (Location Based Service). The positioning component 1008 can be a positioning component based on the US GPS (Global Positioning System), China's Beidou system, Russia's Grenas positioning system, or the European Union's Galileo positioning system.
[0286] The power supply 1009 is used to power various components in the terminal 1000. The power supply 1009 can be an alternating current, a direct current, a disposable battery, or a rechargeable battery. When the power supply 1009 includes a rechargeable battery, the rechargeable battery can be a wired rechargeable battery or a wireless rechargeable battery. A wired rechargeable battery is a battery charged through a wired line, and a wireless rechargeable battery is a battery charged through a wireless coil. The rechargeable battery can also be used to support fast charging technology.
[0287] In some embodiments, the terminal 1000 further includes one or more sensors 1010 , including but not limited to: an acceleration sensor 1011 , a gyroscope sensor 1012 , a pressure sensor 1013 , a fingerprint sensor 1014 , an optical sensor 1015 , and a proximity sensor 1016 .
[0288] The acceleration sensor 1011 can detect the magnitude of acceleration on the three coordinate axes of the coordinate system established by the terminal 1000. For example, the acceleration sensor 1011 can be used to detect the components of gravity acceleration on the three coordinate axes. The processor 1001 can control the display screen 1005 to display the user interface in a horizontal view or a vertical view according to the gravity acceleration signal collected by the acceleration sensor 1011. The acceleration sensor 1011 can also be used to collect motion data of games or users.
[0289] The gyro sensor 1012 can detect the body direction and rotation angle of the terminal 1000, and the gyro sensor 1012 can cooperate with the acceleration sensor 1011 to collect the user's 3D actions on the terminal 1000. The processor 1001 can implement the following functions based on the data collected by the gyro sensor 1012: motion sensing (such as changing the UI according to the user's tilt operation), image stabilization during shooting, game control, and inertial navigation.
[0290] The pressure sensor 1013 can be set on the side frame of the terminal 1000 and / or the lower layer of the display screen 1005. When the pressure sensor 1013 is set on the side frame of the terminal 1000, it can detect the user's holding signal of the terminal 1000, and the processor 1001 performs left and right hand recognition or shortcut operation according to the holding signal collected by the pressure sensor 1013. When the pressure sensor 1013 is set on the lower layer of the display screen 1005, the processor 1001 controls the operability controls on the UI interface according to the user's pressure operation on the display screen 1005. The operability controls include at least one of a button control, a scroll bar control, an icon control, and a menu control.
[0291] The fingerprint sensor 1014 is used to collect the user's fingerprint, and the processor 1001 identifies the user's identity based on the fingerprint collected by the fingerprint sensor 1014, or the fingerprint sensor 1014 identifies the user's identity based on the collected fingerprint. When the user's identity is identified as a trusted identity, the processor 1001 authorizes the user to perform relevant sensitive operations, including unlocking the screen, viewing encrypted information, downloading software, paying, and changing settings. The fingerprint sensor 1014 can be set on the front, back, or side of the terminal 1000. When a physical button or a manufacturer logo is set on the terminal 1000, the fingerprint sensor 1014 can be integrated with the physical button or the manufacturer logo.
[0292] The optical sensor 1015 is used to collect the ambient light intensity. In one embodiment, the processor 1001 can control the display brightness of the display screen 1005 according to the ambient light intensity collected by the optical sensor 1015. Specifically, when the ambient light intensity is high, the display brightness of the display screen 1005 is increased; when the ambient light intensity is low, the display brightness of the display screen 1005 is reduced. In another embodiment, the processor 1001 can also dynamically adjust the shooting parameters of the camera assembly 1006 according to the ambient light intensity collected by the optical sensor 1015.
[0293] The proximity sensor 1016, also called a distance sensor, is disposed on the front panel of the terminal 1000. The proximity sensor 1016 is used to collect the distance between the user and the front of the terminal 1000. In one embodiment, when the proximity sensor 1016 detects that the distance between the user and the front of the terminal 1000 is gradually decreasing, the processor 1001 controls the display screen 1005 to switch from the screen-on state to the screen-off state; when the proximity sensor 1016 detects that the distance between the user and the front of the terminal 1000 is gradually increasing, the processor 1001 controls the display screen 1005 to switch from the screen-off state to the screen-on state.
[0294] Those skilled in the art will understand that Fig.10 The structure shown in the figure does not constitute a limitation on the terminal 1000, and the terminal 1000 may include more or less components than those shown in the figure, or combine some components, or adopt a different component arrangement.
[0295] In an exemplary embodiment, a computer-readable storage medium is also provided, and when the instructions in the storage medium are executed by the processor of the terminal, the terminal is enabled to perform the steps performed by the terminal in the above-mentioned data storage method or data reading method. In some embodiments, the computer-readable storage medium can be a ROM (Read Only Memory), a RAM (Random Access Memory), a CD-ROM (Compact Disc Read-Only Memory), a magnetic tape, a floppy disk, an optical data storage device, etc.
[0296] In an exemplary embodiment, a computer program product is also provided. The computer program product includes a computer program. The computer program is executed by a processor to implement the above data storage method or data reading method.
[0297] Those skilled in the art will readily appreciate other embodiments of the present disclosure after considering the specification and practicing the disclosure herein. The present disclosure is intended to cover any variations, uses or adaptations of the present disclosure that follow the general principles of the present disclosure and include common knowledge or customary techniques in the art that are not disclosed in the present disclosure. The description and examples are to be considered exemplary only, and the true scope and spirit of the present disclosure are indicated by the following claims.
[0298] It should be understood that the present disclosure is not limited to the exact structures that have been described above and shown in the drawings, and that various modifications and changes may be made without departing from the scope thereof. The scope of the present disclosure is limited only by the appended claims.
Claims
1. A data storage method, characterized in that: The data storage method comprises: Serializing the target data to be stored to obtain a data stream corresponding to the target data, wherein the target data is data input in the target application and is serializable data; Sending a data storage request to an operating system through the target application; Receiving the data storage request through the operating system, and in response to the data storage request, creating a first-level directory corresponding to the target application in the memory space of the operating system, with the application identifier of the target application serving as the name of the first-level directory; querying a file directory corresponding to a data structure of the target data from a database of a target application to which the target data belongs, wherein the target application has a corresponding database, the database being used to store a file name corresponding to at least one data structure of the target application, and the database being further used to store a file directory corresponding to at least one data structure of the target application; If the database does not contain a file directory corresponding to the data structure of the target data, determine a file directory corresponding to the target application to which the target data belongs, wherein the file directory includes at least the first-level directory; In response to the first directory not existing under the first-level directory, creating the first directory under the first-level directory, wherein the first directory is named after the file name corresponding to the data structure of the target data; In response to the second directory not existing under the first-level directory, creating the second directory under the first-level directory, wherein the second directory refers to the parent directory of the directory named with the file name corresponding to the data structure of the target data, and the name of the second directory is the name of the reference directory corresponding to the data structure; Creating a third directory under the second directory, wherein the third directory is named after the file name corresponding to the data structure of the target data; The data stream is stored in a data file corresponding to the file name.
2. The data storage method according to claim 1, characterized in that: The serializing the target data to be stored to obtain a data stream corresponding to the target data includes: In response to the data structure of the target data being associated with the target interface, serializing the target data to obtain the data stream; The data corresponding to the data structure associated with the target interface may be serialized.
3. The data storage method according to claim 1, characterized in that: The serializing the target data to be stored to obtain a data stream corresponding to the target data includes: The object output stream is called to serialize the target data to obtain the data stream, and the object output stream is used to convert any data into a corresponding data stream.
4. The data storage method according to claim 1, characterized in that: The storing the data stream into a data file corresponding to the file name includes: In response to the data volume of the data stream not exceeding the maximum data volume of the memory space of the operating system, the data stream is stored in the data file.
5. A data reading method, characterized in that: The data reading method comprises: In response to a data read instruction carrying a data structure, query a target file directory corresponding to the data structure from a database, the data corresponding to the data structure is data input in a target application, the data is serializable data, the target application has a corresponding database, the database is used to store a file name corresponding to at least one data structure of the target application, and the database is also used to store a file directory corresponding to at least one data structure; In response to the target file directory including a third directory, a fourth directory and a fifth directory, the fourth directory is a directory at a level below the third directory, the fifth directory is a directory at a level below the fourth directory, and the fifth directory is named after the file name corresponding to the data structure, the name of the third directory is an application identifier of the target application, the name of the fourth directory is a reference directory name corresponding to the data structure, and the name of the fifth directory is a file name corresponding to the data structure, the third directory is created in the memory space of the operating system after the operating system receives a data storage request sent by the target application; the third directory is queried from at least one created first-level directory; the fourth directory is queried from at least one second-level directory under the third directory; the fifth directory is queried from at least one third-level directory under the fourth directory; In response to the target file directory including a first directory and a second directory, the second directory is a directory at a level below the first directory, and the second directory is named after the file name corresponding to the data structure; query the first directory from at least one created first-level directory; query the second directory from at least one second-level directory under the first directory; Based on the directory named with the file name, read the data file corresponding to the file name.
6. The data reading method according to claim 5, characterized in that: The step of reading a data file corresponding to the file name based on a directory named by the file name includes: Reading a data stream from the data file based on a directory named by the file name; Deserialize the data stream to obtain data corresponding to the data stream.
7. The data reading method according to claim 6, characterized in that: The deserializing the data stream to obtain data corresponding to the data stream includes: The object input stream is called to deserialize the data stream to obtain the data, and the object output stream is used to convert any data stream into corresponding data.
8. A data storage device, characterized in that: The data storage device comprises: A serialization unit is configured to perform serialization processing on target data to be stored to obtain a data stream corresponding to the target data, wherein the target data is data input in a target application and the target data is serializable data; A request sending unit, configured to execute, through the target application, sending a data storage request to the operating system; a directory creation unit configured to receive the data storage request through the operating system, and create a first-level directory corresponding to the target application in the memory space of the operating system in response to the data storage request, using the application identifier of the target application as the name of the first-level directory; a directory determination unit configured to execute querying a file directory corresponding to a data structure of the target data from a database of a target application to which the target data belongs, the target application having a corresponding database, the database being used to store a file name corresponding to at least one data structure of the target application, and the database being further used to store a file directory corresponding to at least one data structure of the target application; if the database does not contain a file directory corresponding to the data structure of the target data, determining a file directory corresponding to the target application to which the target data belongs, the file directory including at least the first-level directory; in response to the absence of a first directory under the first-level directory, creating the first directory under the first-level directory, the first directory being named after the file name corresponding to the data structure of the target data; in response to the absence of a second directory under the first-level directory, creating the second directory under the first-level directory, the second directory being the parent directory of a directory named after the file name corresponding to the data structure of the target data, the name of the second directory being the name of a reference directory corresponding to the data structure; creating a third directory under the second directory, the third directory being named after the file name corresponding to the data structure of the target data; The data storage unit is configured to store the data stream into a data file corresponding to the file name.
9. The data storage device according to claim 8, characterized in that: The serialization unit is configured to perform: In response to the data structure of the target data being associated with the target interface, serializing the target data to obtain the data stream; The data corresponding to the data structure associated with the target interface may be serialized.
10. The data storage device according to claim 8, characterized in that: The serialization unit is configured to execute the call object output stream, perform serialization processing on the target data, and obtain the data stream. The object output stream is used to convert any data into a corresponding data stream.
11. The data storage device according to claim 8, characterized in that: The data storage unit is configured to execute, in response to the data amount of the data stream not exceeding the maximum data amount of the memory space of the operating system, storing the data stream into the data file.
12. A data reading device, characterized in that: The data reading device comprises: a first directory acquisition unit, configured to execute a data read instruction in response to a data structure, query a target file directory corresponding to the data structure from a database, the data corresponding to the data structure is data input in a target application, the data is serializable data, the target application has a corresponding database, the database is used to store a file name corresponding to at least one data structure of the target application, and the database is also used to store a file directory corresponding to at least one data structure; The directory query unit is configured to execute, in response to the target file directory including a third directory, a fourth directory and a fifth directory, the fourth directory is a directory at a lower level of the third directory, the fifth directory is a directory at a lower level of the fourth directory, and the fifth directory is named after the file name corresponding to the data structure, the name of the third directory is the application identifier of the target application, the name of the fourth directory is a preset reference directory name corresponding to the data structure, the name of the fifth directory is the file name corresponding to the data structure, and the third directory is created in the memory space of the operating system after the operating system receives the data storage request sent by the target application; query the third directory from at least one created first-level directory; query the fourth directory from at least one second-level directory under the third directory; query the fifth directory from at least one third-level directory under the fourth directory; and further configured to execute, in response to the target file directory including a first directory and a second directory, the second directory is a directory at a lower level of the first directory, and the second directory is named after the file name corresponding to the data structure; query the first directory from at least one created first-level directory; query the second directory from at least one second-level directory under the first directory; The data reading unit is configured to read the data file corresponding to the file name based on the directory named by the file name.
13. The data reading device according to claim 12, characterized in that: The data reading unit comprises: A data stream reading subunit is configured to read a data stream from the data file based on a directory named by the file name; The deserialization subunit is configured to perform deserialization processing on the data stream to obtain data corresponding to the data stream.
14. The data reading device according to claim 13, characterized in that: The deserialization subunit is configured to execute the call object input stream, perform deserialization processing on the data stream, and obtain the data. The object output stream is used to convert any data stream into corresponding data.
15. A terminal, characterized in that: The terminal comprises: one or more processors; a memory for storing the one or more processor-executable instructions; The one or more processors are configured to execute the data storage method according to any one of claims 1 to 4, or are configured to execute the data storage method according to any one of claims 5 to 7.
16. A computer-readable storage medium, characterized in that: When the instructions in the computer-readable storage medium are executed by a processor of a terminal, the terminal is enabled to execute the data storage method according to any one of claims 1 to 4, or the terminal is enabled to execute the data reading method according to any one of claims 5 to 7.
