本文整理汇总了Java中cn.nukkit.utils.Utils.readFile方法的典型用法代码示例。如果您正苦于以下问题:Java Utils.readFile方法的具体用法?Java Utils.readFile怎么用?Java Utils.readFile使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类cn.nukkit.utils.Utils
的用法示例。
在下文中一共展示了Utils.readFile方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getPluginDescription
import cn.nukkit.utils.Utils; //导入方法依赖的package包/类
@Override
public PluginDescription getPluginDescription(File file) {
try (JarFile jar = new JarFile(file)) {
JarEntry entry = jar.getJarEntry("nukkit.yml");
if (entry == null) {
entry = jar.getJarEntry("plugin.yml");
if (entry == null) {
return null;
}
}
try (InputStream stream = jar.getInputStream(entry)) {
return new PluginDescription(Utils.readFile(stream));
}
} catch (IOException e) {
return null;
}
}
示例2: getPluginDescription
import cn.nukkit.utils.Utils; //导入方法依赖的package包/类
@Override
public PluginDescription getPluginDescription(File file) {
try {
JarFile jar = new JarFile(file);
JarEntry entry = jar.getJarEntry("nukkit.yml");
if (entry == null) {
entry = jar.getJarEntry("plugin.yml");
if (entry == null) {
return null;
}
}
InputStream stream = jar.getInputStream(entry);
return new PluginDescription(Utils.readFile(stream));
} catch (IOException e) {
return null;
}
}
示例3: loadLang
import cn.nukkit.utils.Utils; //导入方法依赖的package包/类
protected Map<String, String> loadLang(String path) {
try {
String content = Utils.readFile(path);
Map<String, String> d = new HashMap<>();
for (String line : content.split("\n")) {
line = line.trim();
if (line.equals("") || line.charAt(0) == '#') {
continue;
}
String[] t = line.split("=");
if (t.length < 2) {
continue;
}
String key = t[0];
String value = "";
for (int i = 1; i < t.length - 1; i++) {
value += t[i] + "=";
}
value += t[t.length - 1];
if (value.equals("")) {
continue;
}
d.put(key, value);
}
return d;
} catch (IOException e) {
Server.getInstance().getLogger().logException(e);
return null;
}
}
示例4: importLanguages
import cn.nukkit.utils.Utils; //导入方法依赖的package包/类
private void importLanguages(){
this.language = new HashMap<>();
for(String lang : langList){
InputStream is = this.getResource("lang_" + lang + ".json");
try {
JSONObject obj = new JSONObject(Utils.readFile(is));
this.language.put(lang, obj);
} catch (IOException e) {
e.printStackTrace();
}
}
}
示例5: loadLang
import cn.nukkit.utils.Utils; //导入方法依赖的package包/类
private Map<String, String> loadLang(String path) {
try {
String content = Utils.readFile(path);
Map<String, String> d = new HashMap<>();
for (String line : content.split("\n")) {
line = line.trim();
if (line.equals("") || line.charAt(0) == '#') {
continue;
}
String[] t = line.split("=");
if (t.length < 2) {
continue;
}
String key = t[0];
String value = "";
for (int i = 1; i < t.length - 1; i++) {
value += t[i] + "=";
}
value += t[t.length - 1];
if (value.equals("")) {
continue;
}
d.put(key, value);
}
return d;
} catch (IOException e) {
Server.getInstance().getLogger().logException(e);
return null;
}
}
示例6: generate
import cn.nukkit.utils.Utils; //导入方法依赖的package包/类
private String generate() throws IOException {
File reports = new File(Nukkit.DATA_PATH, "logs/bug_reports");
if (!reports.isDirectory()) {
reports.mkdirs();
}
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyyMMddHHmmSS");
String date = simpleDateFormat.format(new Date());
SystemInfo systemInfo = new SystemInfo();
long totalDiskSize = 0;
StringBuilder model = new StringBuilder();
for (HWDiskStore hwDiskStore : systemInfo.getHardware().getDiskStores()) {
totalDiskSize += hwDiskStore.getSize();
if (!model.toString().contains(hwDiskStore.getModel())) {
model.append(hwDiskStore.getModel()).append(" ");
}
}
StringWriter stringWriter = new StringWriter();
throwable.printStackTrace(new PrintWriter(stringWriter));
File mdReport = new File(reports, date + "_" + throwable.getClass().getSimpleName() + ".md");
mdReport.createNewFile();
String content = Utils.readFile(this.getClass().getClassLoader().getResourceAsStream("report_template.md"));
Properties properties = getGitRepositoryState();
System.out.println(properties.getProperty("git.commit.id.abbrev"));
String abbrev = properties.getProperty("git.commit.id.abbrev");
content = content.replace("${NUKKIT_VERSION}", Nukkit.VERSION);
content = content.replace("${GIT_COMMIT_ABBREV}", abbrev);
content = content.replace("${JAVA_VERSION}", System.getProperty("java.vm.name") + " (" + System.getProperty("java.runtime.version") + ")");
content = content.replace("${HOSTOS}", systemInfo.getOperatingSystem().getFamily() + " [" + systemInfo.getOperatingSystem().getVersion().getVersion() + "]");
content = content.replace("${MEMORY}", getCount(systemInfo.getHardware().getMemory().getTotal(), true));
content = content.replace("${STORAGE_SIZE}", getCount(totalDiskSize, true));
content = content.replace("${CPU_TYPE}", systemInfo.getHardware().getProcessor().getName());
content = content.replace("${PHYSICAL_CORE}", String.valueOf(systemInfo.getHardware().getProcessor().getPhysicalProcessorCount()));
content = content.replace("${LOGICAL_CORE}", String.valueOf(systemInfo.getHardware().getProcessor().getLogicalProcessorCount()));
content = content.replace("${STACKTRACE}", stringWriter.toString());
content = content.replace("${PLUGIN_ERROR}", String.valueOf(!throwable.getStackTrace()[0].getClassName().startsWith("cn.nukkit")).toUpperCase());
content = content.replace("${STORAGE_TYPE}", model.toString());
Utils.writeFile(mdReport, content);
return mdReport.getAbsolutePath();
}