本文整理了Java中com.sap.psr.vulas.shared.util.FileUtil
类的一些代码示例,展示了FileUtil
类的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。FileUtil
类的具体详情如下:
包路径:com.sap.psr.vulas.shared.util.FileUtil
类名称:FileUtil
[英]Helper methods for checking the presence of files and directories, and for dealing with Java class path. See VULAS-204 in case we run into problems related to special characters in paths.
[中]用于检查文件和目录是否存在以及处理Java类路径的帮助器方法。如果我们遇到与路径中的特殊字符相关的问题,请参阅VULAS-204。
代码示例来源:origin: SAP/vulnerability-assessment-tool
@Override
public boolean canAnalyze(File _file) {
final String ext = FileUtil.getFileExtension(_file);
if(ext == null || ext.equals(""))
return false;
for(String supported_ext: this.getSupportedFileExtensions()) {
if(supported_ext.equalsIgnoreCase(ext))
return true;
}
return false;
}
代码示例来源:origin: SAP/vulnerability-assessment-tool
public void setInclPath(Path _p) throws IllegalArgumentException {
if(FileUtil.isAccessibleDirectory(_p) || FileUtil.isAccessibleFile(_p))
this.inclPath = _p;
}
代码示例来源:origin: SAP/vulnerability-assessment-tool
@SuppressWarnings("unchecked")
public T read(Path _path) {
T object = null;
if(FileUtil.isAccessibleFile(_path)) {
try {
final String json = FileUtil.readFile(_path);
object = (T)JacksonUtil.asObject(json, this.clazz);
} catch (IOException e) {
log.error("Error reading from file [" + _path + "]: " + e.getMessage(), e);
} catch (ClassCastException e) {
log.error("Error reading from file [" + _path + "]: " + e.getMessage(), e);
} catch (Exception e) {
log.error("Error reading from file [" + _path + "]: " + e.getMessage(), e);
}
}
return object;
}
}
代码示例来源: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
public void setFile(File _file) throws IllegalArgumentException {
final String ext = FileUtil.getFileExtension(_file);
if(!ext.equals("class"))
throw new IllegalArgumentException("Expected a class file but got [" + _file + "]");
if(!FileUtil.isAccessibleFile(_file.toPath()))
throw new IllegalArgumentException("Cannot open file [" + _file + "]");
this.file = _file;
}
代码示例来源:origin: SAP/vulnerability-assessment-tool
public static Path getPath(String _path, boolean _create) {
if(_path==null || _path.equals(""))
return null;
else {
final Path p = Paths.get(_path).toAbsolutePath();
if(FileUtil.isAccessibleFile(p) || FileUtil.isAccessibleDirectory(p)) {
return p;
} else if(!p.toFile().exists() && _create) {
FileUtil.createDirectory(p);
return p;
} else {
FileUtil.log.warn("Path [" + _path + "] is neither an accessible file nor an accessible directory, hence, will be ignored");
return null;
}
}
}
代码示例来源:origin: SAP/vulnerability-assessment-tool
public static String readFile(String _p) throws IOException {
return FileUtil.readFile(Paths.get(_p));
}
代码示例来源:origin: SAP/vulnerability-assessment-tool
try {
p = Paths.get(VulasConfiguration.getGlobal().getTmpDir().toString(), this.javaId.getJavaPackageId().getQualifiedName().replace('.','/'), this.javaId.getName().replace('<', '_').replace('>','_') + ".class");
FileUtil.createDirectory(p.getParent());
FileUtil.writeToFile(p.toFile(), this.bytes);
} catch(IOException e) {
ClassVisitor.getLog().warn("Cannot write bytecode of " + this.javaId+ " to file [" + p + "]: " + e.getMessage());
代码示例来源:origin: SAP/vulnerability-assessment-tool
@Override
public void analyze(final File _file) throws FileAnalysisException {
if(!FileUtil.isAccessibleDirectory(_file))
throw new IllegalArgumentException("Expected a directory but got [" + _file + "]");
this.dir = _file;
final String ext = FileUtil.getFileExtension(file.toFile());
代码示例来源:origin: SAP/vulnerability-assessment-tool
@Override
public boolean canAnalyze(File _file) {
return FileUtil.isAccessibleDirectory(_file);
}
代码示例来源:origin: SAP/vulnerability-assessment-tool
@Override
public void analyze(final File _file) throws FileAnalysisException {
if(!FileUtil.isAccessibleFile(_file.toPath()))
throw new IllegalArgumentException("[" + _file + "] does not exist or is not readable");
this.file = _file;
}
代码示例来源:origin: SAP/vulnerability-assessment-tool
FileUtil.createDirectory(download_dir);
this.searchDownloadInfo(packages, FileUtil.readFile(download_info));
代码示例来源:origin: SAP/vulnerability-assessment-tool
public boolean write(T _object, Path _path) {
boolean success = false;
if(_object!=null && _path!=null) {
// Serialize
final String json = JacksonUtil.asJsonString(_object);
// Write
try {
FileUtil.writeToFile(_path.toFile(), json);
success = true;
} catch (IOException e) {
log.error("Error writing to file [" + _path + "]: " + e.getMessage(), e);
}
}
return success;
}
}
代码示例来源:origin: SAP/vulnerability-assessment-tool
public PythonConstructDigest(Path _path, DigestAlgorithm _alg) throws IllegalArgumentException {
if(!FileUtil.isAccessibleFile(_path))
throw new IllegalArgumentException("Path argument [" + _path + "] is not a valid file");
this.digest = FileUtil.getDigest(_path.toFile(), _alg);
this.digestAlgorithm = _alg;
this.computedFrom = _path.getFileName().toString();
this.computedFromType = ComputedFromType.FILE;
}
代码示例来源:origin: SAP/vulnerability-assessment-tool
if(!FileUtil.isAccessibleDirectory(_path_to_python_project))
throw new IllegalArgumentException("Project path [" + _path_to_python_project + "] does not point to an accessible directory");
if(!DirUtil.containsFile(_path_to_python_project.toFile(), SETUP_PY))
this.pathToVirtualenv = FileUtil.createTmpDir("vulas-virtualenv-" + this.projectName + "-").toAbsolutePath();
} catch (IOException e) {
throw new ProcessWrapperException("Cannot create tmp directory: " + e.getMessage());
代码示例来源:origin: SAP/vulnerability-assessment-tool
public PipInstalledPackage call() throws ProcessWrapperException, IOException {
// Make download dir
//final Path download_dir = Paths.get(logDir.toString(), "pip-download");
final Path download_dir = FileUtil.createTmpDir(this.pack.getName() + "-");
// Download all deps
ProcessWrapper pw = new ProcessWrapper();
pw.setCommand(pathToPip, "download", "-d", download_dir.toString(), "--no-cache-dir", this.pack.getName()+"=="+this.pack.getVersion());
pw.setPath(logDir);
pw.run();
final Path download_info = pw.getOutFile();
// Enrich with download info
searchDownloadInfo(this.pack, FileUtil.readFile(download_info));
return this.pack;
}
}
代码示例来源:origin: SAP/vulnerability-assessment-tool
this.setLibPath(FileUtil.getPath(VulasConfiguration.getGlobal().getConfiguration().getString(CoreConfiguration.INSTR_LIB_DIR, null)));
this.setInclPath(FileUtil.getPath(VulasConfiguration.getGlobal().getConfiguration().getString(CoreConfiguration.INSTR_INCLUDE_DIR, null)));
this.setTargetPath(FileUtil.getPath(VulasConfiguration.getGlobal().getConfiguration().getString(CoreConfiguration.INSTR_TARGET_DIR, null), true));
this.setTargetPath(FileUtil.createTmpDir("instr"));
log.warn("No target path specified, using [" + this.getTargetPath() + "]");
this.addInstrPaths(FileUtil.getPaths(VulasConfiguration.getGlobal().getStringArray(CoreConfiguration.INSTR_SRC_DIR, null)));
代码示例来源:origin: SAP/vulnerability-assessment-tool
try {
if(FileUtil.isAccessibleDirectory(p) || FileUtil.hasFileExtension(p, EXT_FILTER)) {
log.info("Searching for Python constructs in search path [" + p + "] with filter [" + StringUtil.join(EXT_FILTER, ", ") + "]");
final FileAnalyzer da = FileAnalyzerFactory.buildFileAnalyzer(p.toFile(), EXT_FILTER);
代码示例来源:origin: SAP/vulnerability-assessment-tool
if(!FileUtil.isAccessibleDirectory(_dir))
Files.createDirectories(_dir);
pw = new PrintWriter(file, FileUtil.getCharsetName());
template.merge(context, pw);
代码示例来源:origin: SAP/vulnerability-assessment-tool
private void writeToDisk(String _file, Graph<ConstructId> _g) {
try {
// Create all parent dirs
final Path p = Paths.get(_file);
FileUtil.createDirectory(p.getParent());
// Write object
final File f = new File(_file);
try (final ObjectOutputStream oos = new ObjectOutputStream(new FileOutputStream(f))) {
oos.writeObject(_g);
log.info("Wrote call graph with [" + _g.getNumberOfNodes() + "] nodes to [" + _file + "]");
}
} catch (IOException ioe) {
log.error("I/O error when writing object to [" + _file + "]: " + ioe.getMessage(), ioe);
}
}
内容来源于网络,如有侵权,请联系作者删除!