• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021-2022 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 package com.ohos.hapsigntoolcmd;
17 
18 import com.ohos.hapsigntool.error.CustomException;
19 import com.ohos.hapsigntool.error.ERROR;
20 import com.ohos.hapsigntool.error.SignToolErrMsg;
21 import com.ohos.hapsigntool.utils.FileUtils;
22 import com.ohos.hapsigntool.utils.LogUtils;
23 
24 import java.io.IOException;
25 import java.io.InputStream;
26 import java.nio.charset.StandardCharsets;
27 
28 /**
29  * HelpDocument.
30  *
31  * @since 2021/12/28
32  */
33 public final class HelpDocument {
HelpDocument()34     private HelpDocument() {
35     }
36 
37     /**
38      * Print help.txt into logger.info.
39      *
40      * @param logger log4j
41      */
printHelp(LogUtils logger)42     public static void printHelp(LogUtils logger) {
43         ClassLoader classLoader = HelpDocument.class.getClassLoader();
44         if (classLoader == null) {
45             return;
46         }
47 
48         String page = "help.txt";
49 
50         try(InputStream inputStream = classLoader.getResourceAsStream(page)) {
51             if (inputStream == null) {
52                 return;
53             }
54             byte[] helpData = FileUtils.read(inputStream);
55             String helpStr = new String(helpData, StandardCharsets.UTF_8);
56             logger.info(helpStr);
57         } catch (IOException ioe) {
58             logger.debug(ioe.getMessage(), ioe);
59             CustomException.throwException(ERROR.READ_FILE_ERROR, SignToolErrMsg.FILE_READ_FAILED.toString(page));
60         }
61     }
62 }
63