Example usage for java.io FileWriter flush

List of usage examples for java.io FileWriter flush

Introduction

In this page you can find the example usage for java.io FileWriter flush.

Prototype

public void flush() throws IOException 

Source Link

Document

Flushes the stream.

Usage

From source file:au.org.ala.layers.grid.GridCacheBuilder.java

private static void writeGroupHeader(File f, ArrayList<Grid> group) throws IOException {
    FileWriter fw = null;
    try {/*from   ww w .ja v  a  2  s .  com*/
        fw = new FileWriter(f);
        for (int i = 0; i < group.size(); i++) {
            fw.write(group.get(i).filename);
            fw.write("\n");
        }
        fw.flush();
    } catch (Exception e) {
        logger.error(e.getMessage(), e);
    } finally {
        if (fw != null) {
            try {
                fw.close();
            } catch (Exception e) {
                logger.error(e.getMessage(), e);
            }
        }
    }
}

From source file:com.yhfudev.SimulatorForSelfStabilizing.java

public static void main(String[] args) {
    // command line lib: apache CLI http://commons.apache.org/proper/commons-cli/
    // command line arguments:
    //  -- input file
    //  -- output line to a csv file
    //  -- algorithm: Ding's linear or randomized

    // single thread parsing ...
    Options options = new Options();
    options.addOption("h", false, "print this message");
    //heuristic//from   ww  w  . ja  va2  s .  c o  m
    options.addOption("u", false, "(rand) heuristic on");
    options.addOption("y", true, "show the graph with specified delay (ms)");
    options.addOption("i", true, "the input file name");
    options.addOption("o", true, "the results is save to a attachable output cvs file");
    options.addOption("l", true, "the graph activities trace log file name");
    options.addOption("s", true, "save the graph to a file");
    options.addOption("a", true, "the algorithm name, ding or rand");
    // options specified to generator
    options.addOption("g", true,
            "the graph generator algorithm name: fan1l, fan2l, rand, doro, flower, watt, lobster");
    options.addOption("n", true, "the number of nodes");
    options.addOption("d", true, "(rand) the node degree (max)");
    options.addOption("f", false, "(rand) if the degree value is fix or not");
    options.addOption("p", true, "(watt) the probability of beta");

    CommandLineParser parser = new DefaultParser();
    CommandLine cmd = null;
    try {
        cmd = parser.parse(options, args);
    } catch (ParseException e) {
        e.printStackTrace();
        return;
    }
    if (cmd.hasOption("h")) {
        showHelp(options);
        return;
    }

    int delay_time = 0;
    if (cmd.hasOption("y")) {
        delay_time = Integer.parseInt(cmd.getOptionValue("y"));
    }

    String sFileName = null;
    sFileName = null;
    FileWriter writer = null;
    if (cmd.hasOption("o")) {
        sFileName = cmd.getOptionValue("o");
    }
    if ((null != sFileName) && (!"".equals(sFileName))) {
        try {
            writer = new FileWriter(sFileName, true); // true: append
        } catch (IOException e) {
            e.printStackTrace();
            System.out.println("Error: unable to open the output file " + sFileName);
            return;
        }
    }
    FileWriter wrGraph = null;
    sFileName = null;
    if (cmd.hasOption("s")) {
        sFileName = cmd.getOptionValue("s");
    }
    if ((null != sFileName) && (!"".equals(sFileName))) {
        try {
            wrGraph = new FileWriter(sFileName, true); // true: append
        } catch (IOException e) {
            e.printStackTrace();
            System.out.println("Error: unable to open the saveGraph file " + sFileName);
            return;
        }
    }

    sFileName = null;
    if (cmd.hasOption("i")) {
        sFileName = cmd.getOptionValue("i");
    }
    String genname = null;
    if (cmd.hasOption("g")) {
        genname = cmd.getOptionValue("g");
    }
    if ((null == genname) && (null == sFileName)) {
        System.out.println("Error: not specify the input file or graph generator");
        showHelp(options);
        return;
    }
    if ((null != genname) && (null != sFileName)) {
        System.out.println("Error: do not specify the input file and graph generator at the same time");
        showHelp(options);
        return;
    }

    if (delay_time > 0) {
        // create and display a graph
        System.setProperty("org.graphstream.ui.renderer", "org.graphstream.ui.j2dviewer.J2DGraphRenderer");
    }

    Graph graph = new SingleGraph("test");
    //graph.setNullAttributesAreErrors(true); // to throw an exception instead of returning null (in getAttribute()).
    if (delay_time > 0) {
        graph.addAttribute("ui.quality");
        graph.addAttribute("ui.antialias");
        graph.addAttribute("ui.stylesheet", "url(data/selfstab-mwcds.css);");
        graph.display();
    }

    // save the trace to file
    FileSinkDGS dgs = null;
    if (cmd.hasOption("l")) {
        dgs = new FileSinkDGS();
        graph.addSink(dgs);
        try {
            dgs.begin(cmd.getOptionValue("l"));
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    Generator generator = null;
    if (null != sFileName) {
        System.out.println("DEBUG: the input file=" + sFileName);
        FileSource source = new FileSourceDGS();
        source.addSink(graph);
        int count_edge_error = 0;
        try {
            //source.begin("data/selfstab-mwcds.dgs"); // Ding's paper example
            //source.begin("data/selfstab-ds.dgs");    // DS example
            //source.begin("data/selfstab-doro-1002.dgs"); // DorogovtsevMendes
            //source.begin("data/selfstab-rand-p10-10002.dgs"); // random connected graph with degree = 10% nodes
            //source.begin("data/selfstab-rand-f5-34.dgs"); // random connected graph with degree = 5
            source.begin(sFileName);
            while (true) {
                try {
                    if (false == source.nextEvents()) {
                        break;
                    }
                } catch (EdgeRejectedException e) {
                    // ignore
                    count_edge_error++;
                    System.out.println("DEBUG: adding edge error: " + e.toString());
                }
                if (delay_time > 0) {
                    delay(delay_time);
                }
            }
            source.end();
            //} catch (InterruptedException e) {
            //    e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
        System.out.println("DEBUG: END read from source. # of edges ignored=" + count_edge_error);
    } else {
        // assert (genname != null);

        // graph generator
        //generator = new ChvatalGenerator(); // fix size
        //generator = new FullGenerator(); // full connected, 2 steps,1 node in dominate set
        //generator = new GridGenerator(); // only one result
        //generator = new HypercubeGenerator(); // one result
        //generator = new IncompleteGridGenerator(); // error
        //generator = new PetersenGraphGenerator(); // fix size
        //generator = new PointsOfInterestGenerator(); // error
        //generator = new RandomEuclideanGenerator(); // linear algo endless loop
        //generator = new RandomFixedDegreeDynamicGraphGenerator(); //
        //generator = new RandomGenerator(); //
        //generator = new URLGenerator("http://www.cnbeta.com"); //
        //generator = new WikipediaGenerator("Antarctica"); // no end

        //generator = new DorogovtsevMendesGenerator(); // ok
        //generator = new FlowerSnarkGenerator(); // ok
        //generator = new WattsStrogatzGenerator(maxSteps, 30, 0.5); // small world, ok
        //generator = new LobsterGenerator(); // tree like, ok

        int i;
        int n = 12; // the number of nodes
        if (cmd.hasOption("n")) {
            n = Integer.parseInt(cmd.getOptionValue("n"));
        }
        int d = 3; // the degree of nodes
        if (cmd.hasOption("d")) {
            d = Integer.parseInt(cmd.getOptionValue("d"));
        }
        boolean isFix = false;
        if (cmd.hasOption("f")) {
            isFix = true;
        }
        if ("".equals(genname)) {
            System.out.println("Error: not set generator name");
            return;
        } else if ("fan1l".equals(genname)) {
            generator = new FanGenerator();
        } else if ("fan2l".equals(genname)) {
            generator = new Fan2lGenerator(graph, d);
        } else if ("doro".equals(genname)) {
            generator = new DorogovtsevMendesGenerator();
        } else if ("flower".equals(genname)) {
            generator = new FlowerSnarkGenerator();
        } else if ("lobster".equals(genname)) {
            generator = new LobsterGenerator();
        } else if ("rand".equals(genname)) {
            generator = new ConnectionGenerator(graph, d, false, isFix);
        } else if ("watt".equals(genname)) {
            // WattsStrogatzGenerator(n,k,beta)
            // a ring of n nodes
            // each node is connected to its k nearest neighbours, k must be even
            // n >> k >> log(n) >> 1
            // beta being a probability it must be between 0 and 1.
            int k;
            double beta = 0.5;
            if (cmd.hasOption("p")) {
                beta = Double.parseDouble(cmd.getOptionValue("p"));
            }
            k = (n / 20) * 2;
            if (k < 2) {
                k = 2;
            }
            if (n < 2 * 6) {
                n = 2 * 6;
            }
            generator = new WattsStrogatzGenerator(n, k, beta);
        }
        /*int listf5[][] = {
        {12, 5},
        {34, 5},
        {102, 5},
        {318, 5},
        {1002, 5},
        {3164, 5},
        {10002, 5},
        };
        int listp3[][] = {
        {12, 2},
        {34, 2},
        {102, 3},
        {318, 9},
        {1002, 30},
        {3164, 90},
        {10002, 300},
        };
        int listp10[][] = {
        {12, 2},
        {34, 3},
        {102, 10},
        {318, 32},
        {1002, 100},
        {3164, 316},
        {10002, 1000},
        };
        i = 6;
        maxSteps = listf5[i][0];
        int degree = listf5[i][1];
        generator = new ConnectionGenerator(graph, degree, false, true);
        */
        generator.addSink(graph);
        generator.begin();
        for (i = 1; i < n; i++) {
            generator.nextEvents();
        }
        generator.end();
        delay(500);
    }

    if (cmd.hasOption("a")) {
        SinkAlgorithm algorithm = null;
        String algo = "rand";
        algo = cmd.getOptionValue("a");
        if ("ding".equals(algo)) {
            algorithm = new SelfStabilizingMWCDSLinear();
        } else if ("ds".equals(algo)) {
            algorithm = new SelfStabilizingDSLinear();
        } else {
            algorithm = new SelfStabilizingMWCDSRandom();
        }
        algorithm.init(graph);
        algorithm.setSource("0");
        if (delay_time > 0) {
            algorithm.setAnimationDelay(delay_time);
        }
        if (cmd.hasOption("u")) {
            algorithm.heuristicOn(true);
        } else {
            algorithm.heuristicOn(false);
        }
        algorithm.compute();

        GraphVerificator verificator = new MWCDSGraphVerificator();
        if (verificator.verify(graph)) {
            System.out.println("DEBUG: PASS MWCDSGraphVerificator verficiation.");
        } else {
            System.out.println("DEBUG: FAILED MWCDSGraphVerificator verficiation!");
        }

        if (null != writer) {
            AlgorithmResult result = algorithm.getResult();
            result.SaveTo(writer);
            try {
                writer.flush();
                writer.close();
            } catch (IOException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
        }
        algorithm.terminate();
    }

    if (null != generator) {
        generator.removeSink(graph);
    }
    if (dgs != null) {
        graph.removeSink(dgs);
        try {
            dgs.end();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
    if (null != wrGraph) {
        try {
            saveGraph(graph, wrGraph);
            wrGraph.flush();
            wrGraph.close();
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }
}

From source file:com.ikon.dao.HibernateUtil.java

/**
 * Generate database schema and initial data for a defined dialect
 *///from   w  w w.j a  v  a  2 s .c  o m
public static void generateDatabase(String dialect) throws IOException {
    // Configure Hibernate
    log.info("Exporting Database Schema...");
    String dbSchema = EnvironmentDetector.getUserHome() + "/schema.sql";
    Configuration cfg = getConfiguration().configure();
    cfg.setProperty("hibernate.dialect", dialect);
    SchemaExport se = new SchemaExport(cfg);
    se.setOutputFile(dbSchema);
    se.setDelimiter(";");
    se.setFormat(false);
    se.create(false, false);
    log.info("Database Schema exported to {}", dbSchema);

    String initialData = new File("").getAbsolutePath() + "/src/main/resources/default.sql";
    log.info("Exporting Initial Data from '{}'...", initialData);
    String initData = EnvironmentDetector.getUserHome() + "/data.sql";
    FileInputStream fis = new FileInputStream(initialData);
    String ret = DatabaseDialectAdapter.dialectAdapter(fis, dialect);
    FileWriter fw = new FileWriter(initData);
    IOUtils.write(ret, fw);
    fw.flush();
    fw.close();
    log.info("Initial Data exported to {}", initData);
}

From source file:com.me.edu.Servlet.ElasticSearch_Backup.java

public static String getSentence(String input) {
    String paragraph = input;//from   w  ww  .j  av  a2 s  . c om
    Reader reader = new StringReader(paragraph);
    DocumentPreprocessor dp = new DocumentPreprocessor(reader);
    List<String> sentenceList = new ArrayList<String>();

    for (List<HasWord> sentence : dp) {
        String sentenceString = Sentence.listToString(sentence);
        sentenceList.add(sentenceString.toString());
    }
    String sent = "";
    for (String sentence : sentenceList) {
        System.out.println(sentence);
        sent = sent + " " + sentence + "\n";
    }
    try {

        FileWriter file = new FileWriter("Sentences.txt");
        file.write(sent.toString());
        file.flush();
        file.close();

    } catch (IOException e) {
        e.printStackTrace();
    }
    return sent;
}

From source file:com.gumtreescraper.scraper.GumtreeScraper.java

public static void writeToCsvFile(List<Gumtree> gumtreesNeedToWrite, String outputCsvFileName) {
    try {/*from  w w  w  .  ja  va2s  .c  o m*/
        boolean isAppend = true;
        FileWriter writer = new FileWriter(outputCsvFileName, isAppend);
        for (Gumtree gumtree : gumtreesNeedToWrite) {
            writer.append(gumtree.toString()).append("\n");
        }

        writer.flush();
        writer.close();
    } catch (IOException ex) {
        Logger.getLogger(GumtreeScraper.class.getName()).log(Level.SEVERE, null, ex);
    }

}

From source file:gov.nih.nci.ncicb.tcga.dcc.common.util.FileUtil.java

/**
 * Writes the given content in the given file
 *
 * @param content the content to add//www .jav a 2 s.  com
 * @param file    the file into which to write the content
 * @throws IOException
 */
public static void writeContentToFile(final String content, final File file) throws IOException {

    FileWriter fileWriter = null;

    try {
        fileWriter = new FileWriter(file);
        fileWriter.write(content);

    } finally {

        if (fileWriter != null) {

            fileWriter.flush();
            fileWriter.close();
        }
    }
}

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);// ww  w .j  a  va2s . com
    }
    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.  jav  a  2s  . co  m
 */
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: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();

        //System.out.println(allImages[i].getName());
        if (allImages[i].getName().contains("cat")) //1=dog, 0=cat, -1=unknown
        {//  w ww  .j  a v a2  s .  c  o m
            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:com.photon.phresco.impl.IPhoneApplicationProcessor.java

public static void updateJsonInfo(JSONObject toJson, String jsonFile) throws PhrescoException {
    BufferedWriter out = null;//  w  w  w. jav a2 s.  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);
        }
    }
}