コード例 #1
0
ファイル: ConsoleManager.java プロジェクト: kitskub/Glowstone
 public void startFile(String logfile) {
   File parent = new File(logfile).getParentFile();
   if (!parent.isDirectory() && !parent.mkdirs()) {
     logger.warning("Could not create log folder: " + parent);
   }
   Handler fileHandler = new RotatingFileHandler(logfile);
   fileHandler.setFormatter(new DateOutputFormatter(FILE_DATE));
   logger.addHandler(fileHandler);
 }
コード例 #2
0
ファイル: LiteLoader.java プロジェクト: Nanonid/liteloader
  /** Get the "mods" folder */
  public File getModsFolder() {
    if (modsFolder == null) {
      modsFolder = new File(Minecraft.getMinecraftDir(), "mods");

      if (!modsFolder.exists() || !modsFolder.isDirectory()) {
        try {
          // Attempt to create the "mods" folder if it does not already exist
          modsFolder.mkdirs();
        } catch (Exception ex) {
        }
      }
    }

    return modsFolder;
  }
コード例 #3
0
  /** Save the bundle to a file. Returns false if save was not successful. */
  public boolean saveBundleToFile(final String localeName) {
    try {
      final File externalBundleDir = new File(EXTERNAL_BUNDLE_DIR);
      if (!externalBundleDir.isDirectory()) {
        externalBundleDir.mkdirs();
      }
      final String filename = EXTERNAL_BUNDLE_DIR + "langres_" + localeName + ".properties";
      final PrintWriter out =
          new PrintWriter(
              new BufferedWriter(new OutputStreamWriter(new FileOutputStream(filename), "UTF-8")));

      final TreeMap<String, String> sorter = new TreeMap<String, String>(bundle);

      for (final String string : sorter.keySet()) {
        String key = string;
        String val = getString(key);
        key = key.trim();
        val = val.trim();
        // change newlines in val into \n
        final StringBuilder sbTmp = new StringBuilder();
        for (int x = 0; x < val.length(); x++) {
          final char c = val.charAt(x);
          if (c == '\n') {
            sbTmp.append("\\n");
          } else {
            sbTmp.append(c);
          }
        }
        val = sbTmp.toString();

        out.println(key + "=" + val);
      }

      out.close();
      return true;
    } catch (final Throwable t) {
      logger.log(Level.SEVERE, "Error saving bundle.", t);
      return false;
    }
  }
コード例 #4
0
ファイル: OCSSWRuntimeConfig.java プロジェクト: mg1989/seadas
  private void initLogger() {
    ConsoleHandler consoleHandler = null;

    Logger rootLogger = LogManager.getLogManager().getLogger("");
    Handler[] handlers = rootLogger.getHandlers();
    for (Handler handler : handlers) {
      if (handler instanceof ConsoleHandler) {
        consoleHandler = (ConsoleHandler) handler;
        rootLogger.removeHandler(handler);
      }
    }

    logger = Logger.getLogger(contextId);
    logger.setLevel(logLevel);
    if (!logLevel.equals(Level.OFF)) {
      LogFormatter formatter = new LogFormatter();
      if (consoleLog) {
        if (consoleHandler == null) {
          consoleHandler = new ConsoleHandler();
        }
        consoleHandler.setFormatter(formatter);
        consoleHandler.setLevel(logLevel);
        logger.addHandler(consoleHandler);
      }
      String userHomePath = getProperty("user.home", ".");
      File logDir = new File(userHomePath, '.' + contextId + "/log");
      logDir.mkdirs();
      String logFilePattern = new File(logDir, contextId + "-%g.log").getPath();
      try {
        FileHandler fileHandler = new FileHandler(logFilePattern);
        fileHandler.setFormatter(formatter);
        fileHandler.setLevel(logLevel);
        logger.addHandler(fileHandler);
      } catch (IOException e) {
        System.err.println("Error: Failed to create log file: " + logFilePattern);
      }
    }
  }
コード例 #5
0
ファイル: TypeList.java プロジェクト: Oger-Lord/JPenguin
  public void save(String gamePath, String dataName) {
    XMLExporter ex = XMLExporter.getInstance();
    OutputStream os = null;
    try {

      File daveFolder = new File(System.getProperty("user.dir") + File.separator + gamePath);
      if (!daveFolder.exists() && !daveFolder.mkdirs()) {
        Logger.getLogger(Type.class.getName()).log(Level.SEVERE, "Error creating save file!");
        throw new IllegalStateException("SaveGame dataset cannot be created");
      }
      File saveFile = new File(daveFolder.getAbsolutePath() + File.separator + dataName);
      if (!saveFile.exists()) {
        if (!saveFile.createNewFile()) {
          Logger.getLogger(Type.class.getName()).log(Level.SEVERE, "Error creating save file!");
          throw new IllegalStateException("SaveGame dataset cannot be created");
        }
      }
      os = new BufferedOutputStream(new FileOutputStream(saveFile));
      // os = new GZIPOutputStream(new BufferedOutputStream(new FileOutputStream(saveFile)));
      ex.save(this, os);
    } catch (IOException ex1) {
      Logger.getLogger(Type.class.getName()).log(Level.SEVERE, "Error saving data: {0}", ex1);
      ex1.printStackTrace();
      throw new IllegalStateException("SaveGame dataset cannot be saved");
    } finally {
      try {
        if (os != null) {
          os.close();
        }
      } catch (IOException ex1) {
        Logger.getLogger(Type.class.getName()).log(Level.SEVERE, "Error saving data: {0}", ex1);
        ex1.printStackTrace();
        throw new IllegalStateException("SaveGame dataset cannot be saved");
      }
    }
  }