• 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.utils.FileUtils;
21 import org.apache.logging.log4j.Logger;
22 
23 import java.io.IOException;
24 import java.io.InputStream;
25 import java.nio.charset.StandardCharsets;
26 
27 /**
28  * HelpDocument.
29  *
30  * @since 2021/12/28
31  */
32 public final class HelpDocument {
HelpDocument()33     private HelpDocument() {
34     }
35 
36     /**
37      * Print help.txt into logger.info.
38      *
39      * @param logger log4j
40      */
printHelp(Logger logger)41     public static void printHelp(Logger logger) {
42         ClassLoader classLoader = HelpDocument.class.getClassLoader();
43         if (classLoader == null) {
44             return;
45         }
46 
47         String page = "help.txt";
48 
49         try(InputStream inputStream = classLoader.getResourceAsStream(page)) {
50             if (inputStream == null) {
51                 return;
52             }
53             byte[] helpData = FileUtils.read(inputStream);
54             String helpStr = new String(helpData, StandardCharsets.UTF_8);
55             logger.info(helpStr);
56         } catch (IOException ioe) {
57             logger.debug(ioe.getMessage(), ioe);
58             CustomException.throwException(ERROR.READ_FILE_ERROR, "Failed to read " + page + " resource");
59         }
60     }
61 }
62