List of usage examples for java.io FileWriter write
public void write(int c) throws IOException
From source file:net.sf.keystore_explorer.crypto.signing.MidletSigner.java
/** * Sign a JAD file outputting the modified JAD to a different file. * * @param jadFile//from w w w. j av a 2 s . c o m * JAD file * @param outputJadFile * Output JAD file * @param jarFile * JAR file * @param privateKey * Private RSA key to sign with * @param certificateChain * Certificate chain for private key * @param certificateNumber * Certificate number * @throws IOException * If an I/O problem occurs while signing the MIDlet * @throws CryptoException * If a crypto problem occurs while signing the MIDlet */ public static void sign(File jadFile, File outputJadFile, File jarFile, RSAPrivateKey privateKey, X509Certificate[] certificateChain, int certificateNumber) throws IOException, CryptoException { Properties jadProperties = readJadFile(jadFile); Properties newJadProperties = new Properties(); // Copy over existing attrs (excepting digest and any certificates at // provided number) for (Enumeration enumPropNames = jadProperties.propertyNames(); enumPropNames.hasMoreElements();) { String propName = (String) enumPropNames.nextElement(); // Ignore digest attr if (propName.equals(MIDLET_JAR_RSA_SHA1_ATTR)) { continue; } // Ignore certificates at provided number if (propName.startsWith(MessageFormat.format(SUB_MIDLET_CERTIFICATE_ATTR, certificateNumber))) { continue; } newJadProperties.put(propName, jadProperties.getProperty(propName)); } // Get certificate attrs for (int i = 0; i < certificateChain.length; i++) { X509Certificate certificate = certificateChain[i]; String base64Cert = null; try { base64Cert = new String(Base64.encode(certificate.getEncoded())); } catch (CertificateEncodingException ex) { throw new CryptoException(res.getString("Base64CertificateFailed.exception.message"), ex); } String midletCertificateAttr = MessageFormat.format(MIDLET_CERTIFICATE_ATTR, certificateNumber, (i + 1)); newJadProperties.put(midletCertificateAttr, base64Cert); } // Get signed Base 64 SHA-1 digest of JAR file as attr byte[] signedJarDigest = signJarDigest(jarFile, privateKey); String base64SignedJarDigest = new String(Base64.encode(signedJarDigest)); newJadProperties.put(MIDLET_JAR_RSA_SHA1_ATTR, base64SignedJarDigest); // Sort properties alphabetically TreeMap<String, String> sortedJadProperties = new TreeMap<String, String>(); for (Enumeration names = newJadProperties.propertyNames(); names.hasMoreElements();) { String name = (String) names.nextElement(); String value = newJadProperties.getProperty(name); sortedJadProperties.put(name, value); } // Write out new JAD properties to JAD file FileWriter fw = null; try { fw = new FileWriter(outputJadFile); for (Iterator itrSorted = sortedJadProperties.entrySet().iterator(); itrSorted.hasNext();) { Map.Entry property = (Map.Entry) itrSorted.next(); fw.write(MessageFormat.format(JAD_ATTR_TEMPLATE, property.getKey(), property.getValue())); fw.write(CRLF); } } finally { IOUtils.closeQuietly(fw); } }
From source file:edu.uci.ics.asterix.event.service.AsterixEventServiceUtil.java
public static void dumpToFile(String dest, String content) throws IOException { FileWriter writer = new FileWriter(dest); writer.write(content); writer.close();// w ww . j a v a2 s . c om }
From source file:au.org.ands.vocabs.toolkit.utils.ToolkitFileUtils.java
/** Save data to a file. * @param dirName The full directory name * @param fileName The base name of the file to create * @param format The format to use; a key in * ToolkitConfig.FORMAT_TO_FILEEXT_MAP. * @param data The data to be written/*w w w .ja va 2 s . c o m*/ * @return The complete, full path to the file. */ public static String saveFile(final String dirName, final String fileName, final String format, final String data) { String fileExtension = ToolkitConfig.FORMAT_TO_FILEEXT_MAP.get(format.toLowerCase()); String filePath = dirName + File.separator + fileName + fileExtension; FileWriter writer = null; try { requireDirectory(dirName); File oFile = new File(filePath); writer = new FileWriter(oFile); writer.write(data); writer.close(); } catch (IOException e) { return "Exception: " + e.toString(); } finally { if (writer != null) { try { writer.close(); } catch (IOException e) { return "Exception: " + e.toString(); } } } return filePath; }
From source file:com.me.edu.Servlet.ElasticSearch_Backup.java
public static String cleanStopWords(String inputText) { String[] stopwords = { "the", "-RRB-", "-LRB-", "a", "as", "able", "about", "WHEREAS", "above", "according", "accordingly", "across", "actually", "after", "afterwards", "again", "against", "aint", "all", "allow", "allows", "almost", "alone", "along", "already", "also", "although", "always", "am", "among", "amongst", "an", "and", "another", "any", "anybody", "anyhow", "anyone", "anything", "anyway", "anyways", "anywhere", "apart", "appear", "appreciate", "appropriate", "are", "arent", "around", "as", "aside", "ask", "asking", "associated", "at", "available", "away", "awfully", "be", "became", "because", "become", "becomes", "becoming", "been", "before", "beforehand", "behind", "being", "believe", "below", "beside", "besides", "best", "better", "between", "beyond", "both", "brief", "but", "by", "cmon", "cs", "came", "can", "cant", "cannot", "cant", "cause", "causes", "certain", "certainly", "changes", "clearly", "co", "com", "come", "comes", "concerning", "consequently", "consider", "considering", "contain", "containing", "contains", "corresponding", "could", "couldnt", "course", "currently", "definitely", "described", "despite", "did", "didnt", "different", "do", "does", "doesnt", "doing", "dont", "done", "down", "downwards", "during", "each", "edu", "eg", "eight", "either", "else", "elsewhere", "enough", "entirely", "especially", "et", "etc", "even", "ever", "every", "everybody", "everyone", "everything", "everywhere", "ex", "exactly", "example", "except", "far", "few", "ff", "fifth", "first", "five", "followed", "following", "follows", "for", "former", "formerly", "forth", "four", "from", "further", "furthermore", "get", "gets", "getting", "given", "gives", "go", "goes", "going", "gone", "got", "gotten", "greetings", "had", "hadnt", "happens", "hardly", "has", "hasnt", "have", "havent", "having", "he", "hes", "hello", "help", "hence", "her", "here", "heres", "hereafter", "hereby", "herein", "hereupon", "hers", "herself", "hi", "him", "himself", "his", "hither", "hopefully", "how", "howbeit", "however", "i", "id", "ill", "im", "ive", "ie", "if", "ignored", "immediate", "in", "inasmuch", "inc", "indeed", "indicate", "indicated", "indicates", "inner", "insofar", "instead", "into", "inward", "is", "isnt", "it", "itd", "itll", "its", "its", "itself", "just", "keep", "keeps", "kept", "know", "knows", "known", "last", "lately", "later", "latter", "latterly", "least", "less", "lest", "let", "lets", "like", "liked", "likely", "little", "look", "looking", "looks", "ltd", "mainly", "many", "may", "maybe", "me", "mean", "meanwhile", "merely", "might", "more", "moreover", "most", "mostly", "much", "must", "my", "myself", "name", "namely", "nd", "near", "nearly", "necessary", "need", "needs", "neither", "never", "nevertheless", "new", "next", "nine", "no", "nobody", "non", "none", "noone", "nor", "normally", "not", "nothing", "novel", "now", "nowhere", "obviously", "of", "off", "often", "oh", "ok", "okay", "old", "on", "once", "one", "ones", "only", "onto", "or", "other", "others", "otherwise", "ought", "our", "ours", "ourselves", "out", "outside", "over", "overall", "own", "particular", "particularly", "per", "perhaps", "placed", "please", "plus", "possible", "presumably", "probably", "provides", "que", "quite", "qv", "rather", "rd", "re", "really", "reasonably", "regarding", "regardless", "regards", "relatively", "respectively", "right", "said", "same", "saw", "say", "saying", "says", "second", "secondly", "see", "seeing", "seem", "seemed", "seeming", "seems", "seen", "self", "selves", "sensible", "sent", "serious", "seriously", "seven", "several", "shall", "she", "should", "shouldnt", "since", "six", "so", "some", "somebody", "somehow", "someone", "something", "sometime", "sometimes", "somewhat", "somewhere", "soon", "sorry", "specified", "specify", "specifying", "still", "sub", "such", "sup", "sure", "ts", "take", "taken", "tell", "tends", "th", "than", "thank", "thanks", "thanx", "that", "thats", "thats", "the", "their", "theirs", "them", "themselves", "then", "thence", "there", "theres", "thereafter", "thereby", "therefore", "therein", "theres", "thereupon", "these", "they", "theyd", "theyll", "theyre", "theyve", "think", "third", "this", "thorough", "thoroughly", "those", "though", "three", "through", "throughout", "thru", "thus", "to", "together", "too", "took", "toward", "towards", "tried", "tries", "truly", "try", "trying", "twice", "two", "un", "under", "unfortunately", "unless", "unlikely", "until", "unto", "up", "upon", "us", "use", "used", "useful", "uses", "using", "usually", "value", "various", "very", "via", "viz", "vs", "want", "wants", "was", "wasnt", "way", "we", "wed", "well", "were", "weve", "welcome", "well", "went", "were", "werent", "what", "whats", "whatever", "when", "whence", "whenever", "where", "wheres", "whereafter", "whereas", "whereby", "wherein", "whereupon", "wherever", "whether", "which", "while", "whither", "who", "whos", "whoever", "whole", "whom", "whose", "why", "will", "willing", "wish", "with", "within", "without", "wont", "wonder", "would", "would", "wouldnt", "yes", "yet", "you", "youd", "youll", "youre", "youve", "your", "yours", "yourself", "yourselves", "zero" }; List<String> wordsList = new ArrayList<String>(); //String tweet = "Feeling miserable with the cold? Here's WHAT you can do."; inputText = inputText.trim().replaceAll("\\s+", " "); System.out.println("After trim: " + inputText); //Get all the words Tokenize rather than spliting String[] words = inputText.split(" "); for (String word : words) { wordsList.add(word);//from ww w .j av a 2 s. c o m } System.out.println("After for loop: " + wordsList); //remove stop words here from the temp list for (int i = 0; i < wordsList.size(); i++) { // get the item as string for (int j = 0; j < stopwords.length; j++) { if (stopwords[j].contains(wordsList.get(i)) || stopwords[j].toUpperCase().contains(wordsList.get(i))) { wordsList.remove(i); } } } String cleanString = ""; for (String str : wordsList) { System.out.print(str + " "); cleanString = cleanString.replaceAll(",", ""); cleanString = cleanString + " " + str; } try { FileWriter file = new FileWriter("cleanDoc.txt"); file.write(cleanString.toString()); file.flush(); file.close(); } catch (IOException e) { e.printStackTrace(); } return cleanString; }
From source file:com.qawaa.gui.EventWebScanGUI.java
/** * ??/*w w w . j a v a2 s. com*/ */ private static void setConsoleRight() { consoleRight = new JPopupMenu(); consoleRight.setBorderPainted(true); consoleRight.setPopupSize(new Dimension(105, 135)); JMenuItem clear = new JMenuItem(CONTEXT.getMessage("gobal.right.menu.clear", null, Locale.CHINA), KeyEvent.VK_L); JMenuItem copy = new JMenuItem(CONTEXT.getMessage("gobal.right.menu.copy", null, Locale.CHINA), KeyEvent.VK_C); JMenuItem cut = new JMenuItem(CONTEXT.getMessage("gobal.right.menu.cut", null, Locale.CHINA), KeyEvent.VK_X); JMenuItem font = new JMenuItem(CONTEXT.getMessage("gobal.right.menu.font", null, Locale.CHINA), KeyEvent.VK_F); JMenuItem choose = new JMenuItem(CONTEXT.getMessage("gobal.right.menu.choose", null, Locale.CHINA), KeyEvent.VK_O); JMenuItem saveas = new JMenuItem(CONTEXT.getMessage("gobal.right.menu.saveas", null, Locale.CHINA), KeyEvent.VK_S); consoleRight.add(clear); consoleRight.add(copy); consoleRight.add(cut); consoleRight.add(font); consoleRight.add(choose); consoleRight.add(saveas); clear.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { consolePane.setText(""); jConsole.clear(); } }); copy.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { if (consolePane.getText() != null && !consolePane.getText().trim().isEmpty()) { Clipboard clip = Toolkit.getDefaultToolkit().getSystemClipboard(); Transferable tText = new StringSelection(consolePane.getText()); clip.setContents(tText, null); } } }); cut.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { if (consolePane.getText() != null && !consolePane.getText().trim().isEmpty()) { Clipboard clip = Toolkit.getDefaultToolkit().getSystemClipboard(); Transferable tText = new StringSelection(consolePane.getText()); clip.setContents(tText, null); } consolePane.setText(""); jConsole.clear(); } }); saveas.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { JFileChooser fileChooser = new JFileChooser(); int option = fileChooser.showSaveDialog(null); if (option == JFileChooser.APPROVE_OPTION) { File file = fileChooser.getSelectedFile(); try { if (file.exists() == false) { file.createNewFile(); } FileWriter writer = new FileWriter(file); char[] arry = consolePane.getText().toCharArray(); writer.write(arry); writer.flush(); writer.close(); LOG.info(CONTEXT.getMessage("gobal.right.menu.saveas.success", null, Locale.CHINA)); } catch (IOException ioe) { } } } }); }
From source file:com.palantir.gerrit.gerritci.servlets.JobsServlet.java
public static ArrayList<String> updateProjectJobFiles(File projectFile, File projectConfigDirectory, ArrayList<String> receivedJobNames) throws IOException { Scanner scanner = new Scanner(projectFile); ArrayList<String> updatedJobs = new ArrayList<String>(); ArrayList<String> newJobs = new ArrayList<String>(); ArrayList<String> deletedJobs = new ArrayList<String>(); while (scanner.hasNextLine()) { String line = scanner.nextLine(); if (receivedJobNames.contains(line)) { updatedJobs.add(line);//from w w w. ja v a2s. c o m receivedJobNames.remove(line); } else { deletedJobs.add(line); } } logger.info("There are " + receivedJobNames.size() + " new jobs"); logger.info("There are " + deletedJobs.size() + " deleted jobs"); logger.info("There are " + updatedJobs.size() + " updated jobs"); for (String s : receivedJobNames) { newJobs.add(s); } scanner.close(); FileWriter writer = new FileWriter(projectFile, false); for (String s : updatedJobs) { writer.write(s); writer.write("\n"); } for (String s : newJobs) { writer.write(s); writer.write("\n"); } writer.close(); return deletedJobs; }
From source file:ml.hsv.java
public static fileData[] batchColorFeatureBuilder(String ip, int N, int C_h, int C_s, int C_v, File trainFile, File fileInputList, int cellDimension) throws IOException { //get array of all files File ipFiles = new File(ip); File allImages[] = ipFiles.listFiles(); int nImages = allImages.length; fileData allImageData[] = new fileData[nImages]; FileWriter op = new FileWriter(trainFile.toString()); FileWriter op2 = new FileWriter(fileInputList.toString()); for (int i = 0; i < nImages; i++) { //System.out.print("On file number :"+(i+1)+", "+allImages[i].getName() + "\n"); String fileNameWithOutExt = FilenameUtils.removeExtension(allImages[i].getName()); op2.write(fileNameWithOutExt + "\n"); op2.flush();/*from ww w. j ava 2 s . c o m*/ //System.out.println(allImages[i].getName()); if (allImages[i].getName().contains("cat")) //1=dog, 0=cat, -1=unknown { allImageData[i] = new fileData(0, colorFeatureBuilder(img2RGB2HSV(new File(allImages[i].toURI())), N, C_h, C_s, C_v, cellDimension)); } else if (allImages[i].getName().contains("dog")) { allImageData[i] = new fileData(1, colorFeatureBuilder(img2RGB2HSV(new File(allImages[i].toURI())), N, C_h, C_s, C_v, cellDimension)); } else if (allImages[i].getName().contains("airplane")) { allImageData[i] = new fileData(2, colorFeatureBuilder(img2RGB2HSV(new File(allImages[i].toURI())), N, C_h, C_s, C_v, cellDimension)); } else if (allImages[i].getName().contains("automobile")) { allImageData[i] = new fileData(3, colorFeatureBuilder(img2RGB2HSV(new File(allImages[i].toURI())), N, C_h, C_s, C_v, cellDimension)); } else if (allImages[i].getName().contains("bird")) { allImageData[i] = new fileData(4, colorFeatureBuilder(img2RGB2HSV(new File(allImages[i].toURI())), N, C_h, C_s, C_v, cellDimension)); } else if (allImages[i].getName().contains("deer")) { allImageData[i] = new fileData(5, colorFeatureBuilder(img2RGB2HSV(new File(allImages[i].toURI())), N, C_h, C_s, C_v, cellDimension)); } else if (allImages[i].getName().contains("frog")) { allImageData[i] = new fileData(6, colorFeatureBuilder(img2RGB2HSV(new File(allImages[i].toURI())), N, C_h, C_s, C_v, cellDimension)); } else if (allImages[i].getName().contains("horse")) { allImageData[i] = new fileData(7, colorFeatureBuilder(img2RGB2HSV(new File(allImages[i].toURI())), N, C_h, C_s, C_v, cellDimension)); } else if (allImages[i].getName().contains("ship")) { allImageData[i] = new fileData(8, colorFeatureBuilder(img2RGB2HSV(new File(allImages[i].toURI())), N, C_h, C_s, C_v, cellDimension)); } else if (allImages[i].getName().contains("truck")) { allImageData[i] = new fileData(9, colorFeatureBuilder(img2RGB2HSV(new File(allImages[i].toURI())), N, C_h, C_s, C_v, cellDimension)); } //store intermed. results start here StringBuffer ip2 = new StringBuffer(); ip2.append(allImageData[i].type); for (int j = 0; j < allImageData[i].colorFeatureVector.size(); j++) { if (allImageData[i].colorFeatureVector.get(j)) { ip2.append(" " + (j + 1) + ":1"); } } ip2.append("\n"); op.write(ip2.toString()); op.flush(); //end intermed. results } op.close(); op2.close(); return allImageData; }
From source file:org.owasp.proxy.Main.java
private static SSLContextSelector getServerSSLContextSelector() throws GeneralSecurityException, IOException { File ks = new File("ca.p12"); String type = "PKCS12"; char[] password = "password".toCharArray(); String alias = "CA"; if (ks.exists()) { try {/*from w ww . j ava 2s .co m*/ return new AutoGeneratingContextSelector(ks, type, password, password, alias); } catch (GeneralSecurityException e) { System.err.println("Error loading CA keys from keystore: " + e.getLocalizedMessage()); } catch (IOException e) { System.err.println("Error loading CA keys from keystore: " + e.getLocalizedMessage()); } } System.err.println("Generating a new CA"); X500Principal ca = new X500Principal( "cn=OWASP Custom CA for " + java.net.InetAddress.getLocalHost().getHostName() + ",ou=OWASP Custom CA,o=OWASP,l=OWASP,st=OWASP,c=OWASP"); AutoGeneratingContextSelector ssl = new AutoGeneratingContextSelector(ca); try { ssl.save(ks, type, password, password, alias); } catch (GeneralSecurityException e) { System.err.println("Error saving CA keys to keystore: " + e.getLocalizedMessage()); } catch (IOException e) { System.err.println("Error saving CA keys to keystore: " + e.getLocalizedMessage()); } FileWriter pem = null; try { pem = new FileWriter("ca.pem"); pem.write(ssl.getCACert()); } catch (IOException e) { System.err.println("Error writing CA cert : " + e.getLocalizedMessage()); } finally { if (pem != null) pem.close(); } return ssl; }
From source file:it.intecs.pisa.toolbox.util.URLReader.java
public static void writeURLContentToXML(String host, String url, int port, String fileName) throws Exception { try {/* w ww . jav a 2s . co m*/ String fileContent = (String) getURLContent(host, url, port); if (fileContent == null) return; fileContent = fileContent.substring(fileContent.indexOf("<"), fileContent.lastIndexOf(">") + 1); File newFile = new File(fileName); FileWriter fw = new FileWriter(newFile); fw.write(fileContent); fw.close(); } catch (Exception e) { e.printStackTrace(System.out); return; } }
From source file:com.photon.phresco.impl.IPhoneApplicationProcessor.java
public static void updateJsonInfo(JSONObject toJson, String jsonFile) throws PhrescoException { BufferedWriter out = null;// ww w .ja v a 2s . c o m FileWriter fstream = null; try { Gson gson = new Gson(); FileWriter writer = null; String json = gson.toJson(toJson); writer = new FileWriter(jsonFile); writer.write(json); writer.flush(); } catch (IOException e) { throw new PhrescoException(e); } finally { try { if (out != null) { out.close(); } if (fstream != null) { fstream.close(); } } catch (IOException e) { throw new PhrescoException(e); } } }