com.sap.psr.vulas.shared.util.FileUtil.getCharset()方法的使用及代码示例

x33g5p2x  于2022-01-19 转载在 其他  
字(3.8k)|赞(0)|评价(0)|浏览(98)

本文整理了Java中com.sap.psr.vulas.shared.util.FileUtil.getCharset()方法的一些代码示例,展示了FileUtil.getCharset()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。FileUtil.getCharset()方法的具体详情如下:
包路径:com.sap.psr.vulas.shared.util.FileUtil
类名称:FileUtil
方法名:getCharset

FileUtil.getCharset介绍

[英]Returns the Charset configured via configuration parameter VulasConfiguration#CHARSET.
[中]返回通过配置参数vualConfiguration#Charset配置的字符集。

代码示例

代码示例来源:origin: SAP/vulnerability-assessment-tool

/**
 * Returns the name of the {@link Charset} configured via configuration parameter {@link VulasConfiguration#CHARSET}.
 * 
 * @see {@link #readFile(Path)}, {@link #writeToFile(File, byte[])}, etc.
 * @return
 */
public static String getCharsetName() {
  return FileUtil.getCharset().name();
}

代码示例来源:origin: SAP/vulnerability-assessment-tool

/**
 * Writes a {@link String} to the given {@link File}.
 */
public static final void writeToFile(File _f, String _content) throws IOException {
  FileUtil.writeToFile(_f, _content.getBytes(FileUtil.getCharset()));
}

代码示例来源:origin: SAP/vulnerability-assessment-tool

/**
 * Preserves the line breaks of the original file.
 * As such, it can be used for calculating digests.
 * 
 * @see {@link DigestUtil#getDigestAsString(String,java.nio.charset.Charset, DigestAlgorithm)}
 * 
 * @param _p
 * @return
 * @throws IOException
 */
public static String readFile(Path _p) throws IOException {
  final ByteArrayOutputStream bos = new ByteArrayOutputStream();
  try (final InputStream is = new FileInputStream(_p.toFile())) {
    final byte[] byte_buffer = new byte[1024];
    int len = 0;
    while((len = is.read(byte_buffer)) != -1)
      bos.write(byte_buffer,0,len);
  }
  return new String(bos.toByteArray(), FileUtil.getCharset());
}

代码示例来源:origin: SAP/vulnerability-assessment-tool

/**
 * Writes the given content to a file that is in
 * the temporary directory returned by {@link VulasConfiguration#getTmpDir()}.
 * @return the path of the file
 */
public static final Path writeToTmpFile(String _filename, String _suffix, String _content) throws IOException {
  final Path dir = VulasConfiguration.getGlobal().getTmpDir();
  final String prefix = (_filename!=null ? _filename + "-" : "vulas-tmp-");
  final File f = File.createTempFile(prefix, "." + _suffix, dir.toFile());
  FileUtil.writeToFile(f, _content.getBytes(FileUtil.getCharset()));
  return f.toPath();
}

代码示例来源:origin: SAP/vulnerability-assessment-tool

/**
 * This methods reads a CSV file f containing the results of the BugLibAnalyzer and stores the data into the set this.lids
 * Each line of the csv is an instance of class ArtifactResult2. 
 * 
 * @param f
 * @throws IOException
 */
public void readFile(File f) throws IOException {
   /* for csv scan */
  //BufferedReader br = null;
  String line = "";
  String cvsSplitBy = ";";
  try (BufferedReader br = new BufferedReader( new InputStreamReader(new FileInputStream(f.getAbsolutePath()), FileUtil.getCharset()) )){
    //br = new BufferedReader(new FileReader(f));
    // READ CSV as ArtifactResults2 into a TreeSet to order them by GA, timestamp, version
    while ((line = br.readLine()) != null) {
      String[] splitLine = line.split(cvsSplitBy);
      processLine(splitLine);
      
    }
    if(lids.size()==0){
      BugLibManager.log.warn("File [" + f.getName()+"] is empty!");
    }
    BugLibManager.log.info("Read ["+lids.size()+"] artifactResults from file [" + f.getName()+"]");
    br.close();
  }
}

代码示例来源:origin: SAP/vulnerability-assessment-tool

try (BufferedReader br = new BufferedReader( new InputStreamReader(new FileInputStream(f.getAbsolutePath()), FileUtil.getCharset()) )){
     new OutputStreamWriter(
       new FileOutputStream(f.getAbsolutePath(), true), // true to append
       FileUtil.getCharset()                 // Set encoding

代码示例来源:origin: SAP/vulnerability-assessment-tool

new OutputStreamWriter(
  new FileOutputStream(f.getAbsolutePath(), false), // false to append
  FileUtil.getCharset()                 // Set encoding

代码示例来源:origin: SAP/vulnerability-assessment-tool

String cvsSplitBy = ";";
try (BufferedReader br = new BufferedReader( new InputStreamReader(new FileInputStream(f.getAbsolutePath()), FileUtil.getCharset()) )){
        new OutputStreamWriter(
          new FileOutputStream(f.getAbsolutePath(), false), // false to append
          FileUtil.getCharset()                 // Set encoding

相关文章