LCOV - code coverage report
Current view: top level - pgm - Cat.java (source / functions) Hit Total Coverage
Test: _coverage_report.dat Lines: 0 17 0.0 %
Date: 2022-11-19 15:00:39 Functions: 0 3 0.0 %

          Line data    Source code
       1             : // Copyright (C) 2009 The Android Open Source Project
       2             : //
       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             : package com.google.gerrit.pgm;
      16             : 
      17             : import com.google.gerrit.launcher.GerritLauncher;
      18             : import com.google.gerrit.pgm.util.AbstractProgram;
      19             : import java.io.IOException;
      20             : import java.io.InputStream;
      21             : import org.kohsuke.args4j.Argument;
      22             : 
      23             : /** Dump the contents of a file in our archive. */
      24           0 : public class Cat extends AbstractProgram {
      25             :   @Argument(index = 0, required = true, metaVar = "FILE", usage = "file to output")
      26             :   private String fileName;
      27             : 
      28             :   @Override
      29             :   public int run() throws IOException {
      30           0 :     while (fileName.startsWith("/")) {
      31           0 :       fileName = fileName.substring(1);
      32             :     }
      33             : 
      34             :     String name;
      35           0 :     if (fileName.equals("LICENSES.txt")) {
      36           0 :       name = fileName;
      37             :     } else {
      38           0 :       name = "WEB-INF/" + fileName;
      39             :     }
      40             : 
      41           0 :     try (InputStream in = open(name)) {
      42           0 :       if (in == null) {
      43           0 :         System.err.println("error: no such file " + fileName);
      44           0 :         return 1;
      45             :       }
      46             : 
      47             :       try {
      48           0 :         final byte[] buf = new byte[4096];
      49             :         int n;
      50           0 :         while ((n = in.read(buf)) >= 0) {
      51           0 :           System.out.write(buf, 0, n);
      52             :         }
      53             :       } finally {
      54           0 :         System.out.flush();
      55             :       }
      56           0 :     }
      57           0 :     return 0;
      58             :   }
      59             : 
      60             :   private InputStream open(String name) {
      61           0 :     return GerritLauncher.class.getClassLoader().getResourceAsStream(name);
      62             :   }
      63             : }

Generated by: LCOV version 1.16+git.20220603.dfeb750