本文整理汇总了Java中cn.nukkit.utils.Utils.writeFile方法的典型用法代码示例。如果您正苦于以下问题:Java Utils.writeFile方法的具体用法?Java Utils.writeFile怎么用?Java Utils.writeFile使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类cn.nukkit.utils.Utils
的用法示例。
在下文中一共展示了Utils.writeFile方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: save
import cn.nukkit.utils.Utils; //导入方法依赖的package包/类
public void save() {
this.removeExpired();
try {
File file = new File(this.file);
if (!file.exists()) {
file.createNewFile();
}
LinkedList<LinkedHashMap<String, String>> list = new LinkedList<>();
for (BanEntry entry : this.list.values()) {
list.add(entry.getMap());
}
Utils.writeFile(this.file, new ByteArrayInputStream(new GsonBuilder().setPrettyPrinting().create().toJson(list).getBytes(StandardCharsets.UTF_8)));
} catch (IOException e) {
MainLogger.getLogger().error("Could not save ban list ", e);
}
}
示例2: saveResource
import cn.nukkit.utils.Utils; //导入方法依赖的package包/类
@Override
public boolean saveResource(String filename, String outputName, boolean replace) {
Preconditions.checkArgument(filename != null && outputName != null, "Filename can not be null!");
Preconditions.checkArgument(filename.trim().length() != 0 && outputName.trim().length() != 0, "Filename can not be empty!");
File out = new File(dataFolder, outputName);
if (!out.exists() || replace) {
try (InputStream resource = getResource(filename)) {
if (resource != null) {
File outFolder = out.getParentFile();
if (!outFolder.exists()) {
outFolder.mkdirs();
}
Utils.writeFile(out, resource);
return true;
}
} catch (IOException e) {
Server.getInstance().getLogger().logException(e);
}
}
return false;
}
示例3: saveOfflinePlayerData
import cn.nukkit.utils.Utils; //导入方法依赖的package包/类
public void saveOfflinePlayerData(String name, CompoundTag tag, boolean async) {
if (this.shouldSavePlayerData()) {
try {
if (async) {
this.getScheduler().scheduleAsyncTask(new FileWriteTask(FastAppender.get(this.getDataPath() + "players/", name.toLowerCase(), ".dat"), NBTIO.writeGZIPCompressed(tag, ByteOrder.BIG_ENDIAN)));
} else {
Utils.writeFile(FastAppender.get(this.getDataPath(), "players/", name.toLowerCase(), ".dat"), new ByteArrayInputStream(NBTIO.writeGZIPCompressed(tag, ByteOrder.BIG_ENDIAN)));
}
} catch (Exception e) {
this.logger.critical(this.getLanguage().translateString("nukkit.data.saveError", new String[]{name, e.getMessage()}));
if (Nukkit.DEBUG > 1) {
this.logger.logException(e);
}
}
}
}
示例4: onRun
import cn.nukkit.utils.Utils; //导入方法依赖的package包/类
@Override
public void onRun() {
try {
Utils.writeFile(file, contents);
} catch (IOException e) {
Server.getInstance().getLogger().logException(e);
}
}
示例5: saveLevelData
import cn.nukkit.utils.Utils; //导入方法依赖的package包/类
@Override
public void saveLevelData() {
try {
byte[] data = NBTIO.write(levelData, ByteOrder.LITTLE_ENDIAN);
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
outputStream.write(Binary.writeLInt(3));
outputStream.write(Binary.writeLInt(data.length));
outputStream.write(data);
Utils.writeFile(path + "level.dat", new ByteArrayInputStream(outputStream.toByteArray()));
} catch (IOException e) {
throw new RuntimeException(e);
}
}
示例6: generate
import cn.nukkit.utils.Utils; //导入方法依赖的package包/类
public static void generate(String path, String name, long seed, Class<? extends Generator> generator, Map<String, String> options) throws IOException {
if (!new File(path + "/db").exists()) {
new File(path + "/db").mkdirs();
}
CompoundTag levelData = new CompoundTag("")
.putLong("currentTick", 0)
.putInt("DayCycleStopTime", -1)
.putInt("GameType", 0)
.putInt("Generator", Generator.getGeneratorType(generator))
.putBoolean("hasBeenLoadedInCreative", false)
.putLong("LastPlayed", System.currentTimeMillis() / 1000)
.putString("LevelName", name)
.putFloat("lightningLevel", 0)
.putInt("lightningTime", new Random().nextInt())
.putInt("limitedWorldOriginX", 128)
.putInt("limitedWorldOriginY", 70)
.putInt("limitedWorldOriginZ", 128)
.putInt("Platform", 0)
.putFloat("rainLevel", 0)
.putInt("rainTime", new Random().nextInt())
.putLong("RandomSeed", seed)
.putByte("spawnMobs", 0)
.putInt("SpawnX", 128)
.putInt("SpawnY", 70)
.putInt("SpawnZ", 128)
.putInt("storageVersion", 4)
.putLong("Time", 0)
.putLong("worldStartCount", ((long) Integer.MAX_VALUE) & 0xffffffffL);
byte[] data = NBTIO.write(levelData, ByteOrder.LITTLE_ENDIAN);
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
outputStream.write(Binary.writeLInt(3));
outputStream.write(Binary.writeLInt(data.length));
outputStream.write(data);
Utils.writeFile(path + "level.dat", new ByteArrayInputStream(outputStream.toByteArray()));
DB db = Iq80DBFactory.factory.open(new File(path + "/db"), new Options().createIfMissing(true));
db.close();
}
示例7: saveNotices
import cn.nukkit.utils.Utils; //导入方法依赖的package包/类
public void saveNotices() throws IOException {
JsonArray array = new JsonArray();
noticeList.forEach(array::add);
Utils.writeFile(noticeFile, array.toString());
}
示例8: init
import cn.nukkit.utils.Utils; //导入方法依赖的package包/类
private void init() throws Throwable {
logger = getLogger();
pluginDataDir = getDataFolder();
pluginDataDir.mkdirs();
logger.info("Initializing plugin listener");
pluginListener = new PluginListener();
getServer().getPluginManager().registerEvents(pluginListener, this);
logger.info("Loading configurations' handler");
File configFile = new File(pluginDataDir, "config.yml");
if (!configFile.exists()) {
logger.info("Missing configuration file");
Utils.writeFile(configFile, getResource("config.yml"));
}
configuration = new Configuration(new File(pluginDataDir, "config.yml"));
logger.info("Loading I18N");
Locale locale = Locale.forLanguageTag(configuration.getString("core.language"));
if (I18n.DEFAULT_LOCALE.equals(locale)) {
load18N(locale);
} else {
load18N(I18n.DEFAULT_LOCALE);
load18N(locale);
}
logger.info(I18n.translate("lang.loaded_msg"));
logger.info("Loading auto notices");
File noticeFile = new File(pluginDataDir, "notices.json");
if (!noticeFile.exists()) {
Utils.writeFile(noticeFile, getResource("notices.json"));
}
autoNoticeHandler = new AutoNoticeHandler(this, noticeFile, configuration.getInteger("auto_notices.delay"));
getServer().getScheduler().scheduleRepeatingTask(autoNoticeHandler, 20 * 1); //per second
logger.info("Loading players' home positions");
teleportPositionsHandler = new TeleportPositionsHandler(new File(pluginDataDir, "teleport_positions.json"));
logger.info("Loading teleport requests' handler");
teleportRequestsHandler = new TeleportRequestsHandler(this, configuration.getInteger("tpa.request_max_wait_time"));
getServer().getScheduler().scheduleRepeatingTask(teleportRequestsHandler, 1); // per 1/20 second
logger.info("Loading commands");
commandHandler = new CommandHandler();
commandHandler.registerCommand(new CommandHome());
commandHandler.registerCommand(new CommandSetHome());
commandHandler.registerCommand(new CommandDelHome());
commandHandler.registerCommand(new CommandTp());
commandHandler.registerCommand(new CommandTpa());
commandHandler.registerCommand(new CommandTpaHere());
commandHandler.registerCommand(new CommandTpAccept());
commandHandler.registerCommand(new CommandTpAll());
commandHandler.registerCommand(new CommandAddNotice());
commandHandler.registerCommand(new CommandDelNotice());
commandHandler.registerCommand(new CommandNoticeList());
commandHandler.registerCommand(new CommandWarp());
commandHandler.registerCommand(new CommandSetWarp());
commandHandler.registerCommand(new CommandDelWarp());
commandHandler.registerCommand(new CommandWarpList());
commandHandler.registerCommand(new CommandBack());
commandHandler.registerCommand(new CommandSuicide());
commandHandler.registerCommand(new CommandSpawn());
commandHandler.registerCommand(new CommandSetSpawn());
}
示例9: 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();
}