mirror of
https://github.com/openharmony/applications_screenlock.git
synced 2026-07-01 10:23:02 -04:00
3968f3dd2f
Signed-off-by: zhuchengfeng <940848916@qq.com>
50 lines
1.7 KiB
Plaintext
50 lines
1.7 KiB
Plaintext
/**
|
|
* Copyright (c) 2021 Huawei Device Co., Ltd.
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
* you may not use this file except in compliance with the License.
|
|
* You may obtain a copy of the License at
|
|
*
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
*
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
* See the License for the specific language governing permissions and
|
|
* limitations under the License.
|
|
*/
|
|
|
|
import Log from './Log.ets';
|
|
import FileIo from '@ohos.fileio';
|
|
|
|
const DFAULT_SIZE = 4096;
|
|
const CHAR_CODE_AT_INDEX = 0;
|
|
const TAG = 'ReadConfigUtil';
|
|
|
|
export class ReadConfigUtil {
|
|
ReadConfigFile(fileName) {
|
|
Log.showInfo(TAG, `readConfigFile fileName:${fileName}`);
|
|
try {
|
|
let stream = FileIo.createStreamSync(fileName, 'r');
|
|
Log.showInfo(TAG, `readConfigFile stream:` + stream);
|
|
let buf = new ArrayBuffer(DFAULT_SIZE);
|
|
let len = stream.readSync(buf);
|
|
Log.showInfo(TAG, `readConfigFile len:` + len);
|
|
let arr = new Uint8Array(buf);
|
|
let charAt = ' '.charCodeAt(CHAR_CODE_AT_INDEX);
|
|
for (let i = len;i < DFAULT_SIZE; i++) {
|
|
arr[i] = charAt;
|
|
}
|
|
let content = String.fromCharCode.apply(null, arr);
|
|
stream.closeSync();
|
|
Log.showInfo(TAG, `readConfigFile content:` + JSON.stringify(content));
|
|
return JSON.parse(content);
|
|
} catch (error) {
|
|
Log.showInfo(TAG, `readConfigFile error:` + JSON.stringify(error));
|
|
}
|
|
}
|
|
}
|
|
|
|
let readConfigUtil = new ReadConfigUtil();
|
|
|
|
export default readConfigUtil as ReadConfigUtil
|