List of usage examples for java.io FileWriter close
public void close() throws IOException
From source file:Util.PacketGenerator.java
public static void GenerateTopology() { try {/*from w w w . j a v a 2 s.c o m*/ File file = new File("D:\\Mestrado\\Prototipo\\topologydata\\AS1239\\CONVERTED.POP.1239"); File newFile = new File("D:\\Mestrado\\SketchMatrix\\trunk\\AS1239_TOPOLOGY"); FileInputStream topologyFIS = new FileInputStream(file); DataInputStream topologyDIS = new DataInputStream(topologyFIS); BufferedReader topologyBR = new BufferedReader(new InputStreamReader(topologyDIS)); String topologyStr = topologyBR.readLine(); int numberOfEdges = 0; Set<Integer> nodes = new HashSet<>(); while (topologyStr != null) { String[] edge = topologyStr.split(" "); nodes.add(Integer.parseInt(edge[0])); nodes.add(Integer.parseInt(edge[1])); numberOfEdges++; topologyStr = topologyBR.readLine(); } topologyBR.close(); topologyDIS.close(); topologyFIS.close(); topologyFIS = new FileInputStream(file); topologyDIS = new DataInputStream(topologyFIS); topologyBR = new BufferedReader(new InputStreamReader(topologyDIS)); FileWriter topologyFW = new FileWriter(newFile); topologyStr = topologyBR.readLine(); topologyFW.write(nodes.size() + " " + numberOfEdges + "\n"); while (topologyStr != null) { String[] edge = topologyStr.split(" "); nodes.add(Integer.parseInt(edge[0])); nodes.add(Integer.parseInt(edge[1])); nodes.add(Integer.parseInt(edge[1])); topologyFW.write(Integer.parseInt(edge[0]) + " " + Integer.parseInt(edge[1]) + " 1\n"); topologyStr = topologyBR.readLine(); } topologyBR.close(); topologyDIS.close(); topologyFIS.close(); topologyFW.close(); } catch (Exception e) { e.printStackTrace(); } }
From source file:com.mhs.hboxmaintenanceserver.utils.Utils.java
/** * Create properties file// ww w . j a v a 2s. c o m * * @param filename * @param props * @return */ private static File createPropFile(String filename, String[] props) { File file = new File(filename); if (!file.exists()) { FileWriter pw = null; try { pw = new FileWriter(file); for (String s : props) { pw.write(new String(s.getBytes(), "UTF-8")); } pw.close(); } catch (IOException ex) { Logger.getLogger(Utils.class.getName()).log(Level.SEVERE, null, ex); } finally { try { if (pw != null) { pw.close(); } } catch (IOException ex) { Logger.getLogger(Utils.class.getName()).log(Level.SEVERE, null, ex); } } } return file; }
From source file:edu.kit.dama.util.SystemUtils.java
/** * Generate the lock script for Unix systems. * * @return The full path to the lock script. * * @throws IOException If the generation fails. */// ww w .j a v a2 s. c o m private static String generateLockScript() throws IOException { String scriptFile; FileWriter fout = null; try { scriptFile = FilenameUtils.concat(System.getProperty("java.io.tmpdir"), "lockFolder.sh"); fout = new FileWriter(scriptFile, false); StringBuilder b = new StringBuilder(); b.append("#!/bin/sh\n"); b.append("echo Changing owner of $1 to `whoami`\n"); b.append("chown `whoami` $1 -R\n"); b.append("echo Changing access of $1 to 700\n"); b.append("chmod 700 $1 -R\n"); LOGGER.debug("Writing script data to '{}'", scriptFile); fout.write(b.toString()); fout.flush(); } finally { if (fout != null) { try { fout.close(); } catch (IOException ioe) {//ignore } } } return scriptFile; }
From source file:com.magnet.mmx.tsung.GenTestScript.java
public static void generateScripts(Settings settings) throws TemplateException { genSettings = settings;/*from w w w . j a va2 s.co m*/ File file = new File(settings.outputDir + "/userdb.csv"); FileWriter fileWriter = null; try { fileWriter = new FileWriter(file); // hard-code to "test" for all passwords String password = "test"; for (int i = 1; i <= settings.maxCount; i++) { String jid = settings.userName + i + "%" + settings.appId; int random = new Random().nextInt(settings.maxCount); // make sure it's at least 1 if (random == 0) random++; String toJid = settings.userName + random + "%" + settings.appId; // jid;password;toJid StringBuilder rowBuilder = new StringBuilder(); rowBuilder.append(jid).append(";").append(password).append(";").append(toJid).append("\n"); fileWriter.write(rowBuilder.toString()); } fileWriter.close(); // generate the login load test file generateLoginScript(settings); // generate the dev registration files generateDevRegScript(settings); // generate the message send files generateSendMessageScript(settings); } catch (IOException e) { e.printStackTrace(); } }
From source file:gumga.framework.application.GumgaLoggerService.java
public void logToFile(String msg, int level) { try {/*from www . j a va 2 s . c om*/ String line = createLogLine(msg, level); File folder = new File(gumgaValues.getLogDir()); folder.mkdirs(); File log = new File(folder, "gumgalog.txt"); FileWriter fw = new FileWriter(log, true); fw.write(line); fw.close(); } catch (IOException ex) { log.error("Problema ao loggar no arquivo", ex); } }
From source file:com.lhings.java.LhingsDevice.java
private static void updateProperties() { try {//from ww w.j a va 2 s. co m FileWriter writer = new FileWriter(fileUuids); uuids.store(writer, "Java Lhings SDK device list - last modified " + new Date()); writer.close(); } catch (IOException ex) { log.error("Device list properties file could not be saved."); } }
From source file:io.gumga.application.GumgaLoggerService.java
/** * Adiciona uma mensagem no gumgalog.txt * @param msg mensagem a ser adicionada no arquivo * @param level index da execption do StrackTrace */// w w w . ja v a2s .com public void logToFile(String msg, int level) { try { String line = createLogLine(msg, level); File folder = new File(gumgaValues.getLogDir()); folder.mkdirs(); File log = new File(folder, "gumgalog.txt"); FileWriter fw = new FileWriter(log, true); fw.write(line); fw.close(); } catch (IOException ex) { log.error("Problema ao loggar no arquivo", ex); } }
From source file:AuthenticateNT.java
public Object run() { try {//from ww w . j a va 2 s. c o m File file = new File("D:/", "privilegedFile.txt"); FileWriter fileWriter = new FileWriter(file); fileWriter.write("Welcome to JAAS!"); fileWriter.close(); } catch (IOException ioException) { ioException.printStackTrace(); } return null; }
From source file:hd3gtv.mydmam.auth.AuthenticationBackend.java
public static void checkFirstPlayBoot() throws Exception { if (authenticators == null) { throw new NullPointerException("No backend"); }//from w w w .ja v a2 s . co m if (authenticators.size() == 0) { throw new NullPointerException("No backend"); } if ((authenticators.get(0) instanceof AuthenticatorLocalsqlite) == false) { /** * Admin has set a configuration : no need to setup a first boot */ return; } AuthenticatorLocalsqlite authenticatorlocalsqlite = (AuthenticatorLocalsqlite) authenticators.get(0); if (authenticatorlocalsqlite.isUserExists(ACLUser.ADMIN_NAME) == false) { String newpassword = passwordGenerator(); authenticatorlocalsqlite.createUser(ACLUser.ADMIN_NAME, newpassword, "Local Admin", true); File textfile = new File("play-new-password.txt"); FileWriter fw = new FileWriter(textfile, false); fw.write("Admin login: " + ACLUser.ADMIN_NAME + "\r\n"); fw.write("Admin password: " + newpassword + "\r\n"); fw.write("\r\n"); fw.write("You should remove this file after keeping this password..\r\n"); fw.write("\r\n"); fw.write("You can change this password with mydmam-cli:\r\n"); fw.write("$ mydmam-cli localauth -f " + authenticatorlocalsqlite.getDbfile().getAbsolutePath() + " -key " + authenticatorlocalsqlite.getMaster_password_key() + " -passwd -u " + ACLUser.ADMIN_NAME + "\r\n"); fw.write("\r\n"); fw.write( "Note: you haven't need a local authenticator if you set another backend and if you grant some new administrators\r\n"); fw.close(); Log2Dump dump = new Log2Dump(); dump.add("login", ACLUser.ADMIN_NAME); dump.add("password file", textfile.getAbsoluteFile()); dump.add("local database", authenticatorlocalsqlite.getDbfile()); Log2.log.security("Create Play administrator account", dump); } else if (authenticatorlocalsqlite.isEnabledUser(ACLUser.ADMIN_NAME) == false) { throw new Exception("User " + ACLUser.ADMIN_NAME + " is disabled in sqlite file !"); } }
From source file:de.prozesskraft.pkraft.Manager.java
private static void exiterException(String pathToInstance, Exception e) { try {//w w w . j ava 2 s . c om java.io.FileWriter writer = new FileWriter(pathToInstance + ".pkraft-manager.stacktrace", true); writer.write(new Timestamp(System.currentTimeMillis()).toString() + "\n"); writer.write(e.getMessage() + "\n"); writer.write(e.getStackTrace() + "\n"); writer.write("--------------" + "\n"); writer.close(); } catch (IOException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } exit = true; System.exit(1); }