Example usage for org.apache.commons.io FileUtils writeLines

List of usage examples for org.apache.commons.io FileUtils writeLines

Introduction

In this page you can find the example usage for org.apache.commons.io FileUtils writeLines.

Prototype

public static void writeLines(File file, Collection lines, String lineEnding) throws IOException 

Source Link

Document

Writes the toString() value of each item in a collection to the specified File line by line.

Usage

From source file:com.clov4r.moboplayer.android.nil.codec.SubtitleJni.java

/**
 * ?????//from   w w  w  .  ja  v  a2 s.  c om
 * 
 * @param filePath
 * @param index
 * @return
 */
public int openSubtitleFile(String filePath, int index, int subtiltle_index) {
    String charSet = getFilecharset(new File(filePath));
    if (!charSet.equals("UTF-8")) {
        try {
            String tempPath = filePath.substring(0, filePath.length() - 4) + "mobo_temp_utf-8.srt";
            File tempFile = new File(tempPath);
            if (!tempFile.exists()) {
                FileUtils.writeLines(tempFile, "UTF-8", FileUtils.readLines(new File(filePath), charSet));
            }
            return openSubtitleFileInJNI(tempPath, index, subtiltle_index);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
    return openSubtitleFileInJNI(filePath, index, subtiltle_index);
}

From source file:edu.isistan.carcha.util.Utils.java

/**
 * Creates the file from string list./*from  www .  j a  v a2 s  .c o  m*/
 *
 * @param documents the documents
 * @return the file
 * @throws IOException Signals that an I/O exception has occurred.
 */
public static File createFileFromStringList(List<String> documents) throws IOException {
    File file = null;
    try {
        file = File.createTempFile("documents_", TMP);
        FileWriter writer = new FileWriter(file);
        FileUtils.writeLines(file, documents, "\n");
        writer.close();
    } catch (IOException e) {
        logger.error("Error creating the temp file", e);
        throw e;
    }
    return file;
}

From source file:com.textocat.textokit.commons.util.TrainDevTestCorpusSplitter.java

private void run() throws Exception {
    IOFileFilter corpusFileFilter;//from www  . ja  v  a 2  s  .com
    if (corpusFileSuffix == null) {
        corpusFileFilter = FileFilterUtils.trueFileFilter();
    } else {
        corpusFileFilter = FileFilterUtils.suffixFileFilter(corpusFileSuffix);
    }
    IOFileFilter corpusSubDirFilter = includeSubDirectores ? TrueFileFilter.INSTANCE : null;
    List<Set<File>> partitions = Lists.newArrayList(CorpusUtils.partitionCorpusByFileSize(corpusDir,
            corpusFileFilter, corpusSubDirFilter, partitionsNum));
    if (partitions.size() != partitionsNum) {
        throw new IllegalStateException();
    }
    // make dev partition from the last because it is a little bit smaller
    Set<File> devFiles = getAndRemove(partitions, partitions.size() - 1);
    Set<File> testFiles = getAndRemove(partitions, partitions.size() - 1);
    Set<File> trainFiles = Sets.newLinkedHashSet();
    for (Set<File> s : partitions) {
        trainFiles.addAll(s);
    }
    // write files
    File devPartFile = new File(outputDir, CorpusUtils.getDevPartitionFilename(0));
    FileUtils.writeLines(devPartFile, "utf-8", CorpusUtils.toRelativePaths(corpusDir, devFiles));
    File testPartFile = new File(outputDir, CorpusUtils.getTestPartitionFilename(0));
    FileUtils.writeLines(testPartFile, "utf-8", CorpusUtils.toRelativePaths(corpusDir, testFiles));
    File trainPartFile = new File(outputDir, CorpusUtils.getTrainPartitionFilename(0));
    FileUtils.writeLines(trainPartFile, "utf-8", CorpusUtils.toRelativePaths(corpusDir, trainFiles));
}

From source file:eu.annocultor.data.filters.IdBasedRecordFilter.java

@Override
public void save() throws Exception {
    if (isWriteMode()) {
        FileUtils.writeLines(fileToWrite, includedRecords, "\n");
    }/*w  w w . j a v a  2  s  .c o m*/
}

From source file:com.btisystems.pronx.ems.AppIntegrationTest.java

/**
 * Strips out the Java version from the notification meta data. This isn't
 * needed when diffing the contents.//www.  ja  v a  2  s  . c  o  m
 *
 * @param file
 * @throws IOException
 */
private void trimNotificationMeta(File file) throws IOException {
    List<String> lines = FileUtils.readLines(file);
    List<String> updatedLines = new ArrayList<>();
    for (final String line : lines) {
        if (!line.startsWith("<java version=")) {
            updatedLines.add(line);
        }
    }
    FileUtils.writeLines(file, updatedLines, false);
}

From source file:jclparser.NewClass.java

public static File analyze(File f) {

    String procedure = StringUtils.substringBeforeLast(f.getName(), ".");

    if (f.exists()) {
        f.delete();//w ww .  ja  va2s.  c o  m
    }

    System.out.println("gepeto args2 = " + procedure);

    String tmp;

    PROC proc = parse(PROC.class, "SYS1.VIDA.PROCLIB", procedure);

    List<STEP> steps = proc.getListSTEP();

    List<String> nodes = new ArrayList<>();
    List<String> fromsTos = new ArrayList<>();

    String nodeTemplate = "{\"key\": \"%s\", \"category\": \"program\", \"color\": \"lightblue\", \"label\": \"%s\", \"num\": \"%s\", \"card\": \"%s\"},";
    String dsnTemplate = "{\"key\": \"%s\", \"color\": \"magenta\", \"label\": \"%s\"},";
    String fromToTemplate = "{\"from\": \"%s\", \"to\": \"%s\"},";

    Map<String, Integer> programs = new HashMap<>();
    Set<String> files = new HashSet<>();

    for (STEP step : steps) {
        String pgm = step.getProgram().getName();
        String xxx = "";

        CARD card = step.getProgram().getCard();
        if (card != null) {
            if (card instanceof CARD_IKJEFT01) {
                pgm = ((CARD_IKJEFT01) card).getProgram();
            }

            xxx = step.getProgram().getCard().toString();

            System.out.println("VVV " + step.getProgram().getCard().toString());
            //                if (card instanceof CARD_SORT) {
            //                    pgm = ((CARD_SORT) card).getProgram();
            //                }
        }

        Integer num = programs.get(pgm);
        num = num == null ? 1 : num + 1;
        programs.put(pgm, num);

        if (num > 1) {
            pgm = pgm + " (" + num + ")";
        }

        String t = String.format(nodeTemplate, pgm, "XXX", "XXX", xxx);

        nodes.add(t);

        List<DSN> dsns = step.getListDSN();
        for (DSN dsn : dsns) {
            if (dsn.getName().trim().isEmpty()) {
                continue;
            }

            if (files.add(dsn.getName())) {

                String u = String.format(dsnTemplate, dsn.getName(), dsn.getLabel());
                files.add(nodeTemplate);
                nodes.add(u);
            }

            String from = dsn.getMode().equals("INPUT") ? dsn.getName() : pgm;
            String to = !dsn.getMode().equals("INPUT") ? dsn.getName() : pgm;
            tmp = String.format(fromToTemplate, from, to);

            if (!pgm.equalsIgnoreCase("COPIADOR")) {
                fromsTos.add(tmp);
            }

            System.out.println("Label: " + StringUtils.rightPad(dsn.getLabel(), 8) + " Dsn: " + dsn.getName()
                    + " Type: " + dsn.getType() + " Mode: " + dsn.getMode());
        }
    }

    String lastNode = nodes.remove(nodes.size() - 1);
    lastNode = StringUtils.removeEnd(lastNode, ",");
    nodes.add(lastNode);
    String lastFromsTos = fromsTos.remove(fromsTos.size() - 1);
    lastFromsTos = StringUtils.removeEnd(lastFromsTos, ",");
    fromsTos.add(lastFromsTos);

    try {
        FileUtils.writeStringToFile(f, "{\"class\": \"go.GraphLinksModel\",\"nodeDataArray\": [", true);
        FileUtils.writeLines(f, nodes, true);
        FileUtils.writeStringToFile(f, "],", true);
        FileUtils.writeStringToFile(f, "\"linkDataArray\": [", true);
        FileUtils.writeLines(f, fromsTos, true);
        FileUtils.writeStringToFile(f, "]}", true);
    } catch (IOException ex) {
        Logger.getLogger(NewClass.class.getName()).log(Level.SEVERE, null, ex);
    }

    System.out.println("directoru " + f.getAbsolutePath());

    //        for (String node : nodes) {
    //            System.out.println(node + ",");
    //        }
    //
    //        for (String fromTo : fromsTos) {
    //            System.out.println(fromTo + ",");
    //        }
    return f;
}

From source file:ee.ria.xroad.common.conf.globalconf.GlobalConfTest.java

private static void createConfigurationFiles() throws IOException {
    List<String> confFiles = new ArrayList<>();
    File files = GOOD_CONF_FILES.toFile();

    confFiles.add(getConfFileName("bar", "shared-params.xml"));
    confFiles.add(getConfFileName("EE", "private-params.xml"));
    confFiles.add(getConfFileName("EE", "shared-params.xml"));
    confFiles.add(getConfFileName("foo", "private-params.xml"));
    confFiles.add(getConfFileName("foo", "shared-params.xml"));

    FileUtils.writeLines(files, StandardCharsets.UTF_8.name(), confFiles);
}

From source file:com.mgmtp.jfunk.core.reporting.AbstractFileReporter.java

/**
 * Writes the report to a file. The report is written to the archive direcory as specified by
 * the property {@link JFunkConstants#ARCHIVE_DIR}.
 *//*from w  w  w .  j  a v  a  2s  . co m*/
@Override
public synchronized void createReport() throws IOException {
    if (reportLines.isEmpty()) {
        log.debug("No data to report. Skipping report generation.");
        return;
    }

    File reportFile = new File(archiveDir.get(), createFileName());

    log.debug("Writing report to file: {}", reportFile);

    String header = getHeaderLine();
    if (header != null) {
        reportLines.addFirst(header);
    }
    FileUtils.writeLines(reportFile, charset == null ? defaultCharset.name() : charset.name(), reportLines);

    reportLines.clear();
}

From source file:eu.annocultor.utils.HierarchyTracingFilter.java

public void saveListOfUrls(String fileWithSelection, Collection<String> passedUnSorted,
        List<String> passedSorted) throws IOException {
    if (fileWithSelection != null) {
        FileUtils.writeLines(new File(fileWithSelection), passedSorted, "\n");
    }//from ww w.  j  a  v  a2  s.  co  m
}

From source file:com.utdallas.s3lab.smvhunter.monkey.NetworkMonitor.java

@Override
public void run() {
    try {//from   w w  w. j a va  2  s .  c  o m
        //get the pid first
        String pidString = UIEnumerator.execSpecial(
                String.format(GET_PID, MonkeyMe.adbLocation, device.getSerialNumber(), application));
        if (StringUtils.isEmpty(pidString)) {
            logger.error(getStringforPrinting("pid string empty for app ", application, "trying again"));
            Thread.sleep(5000);
            //try again
            pidString = UIEnumerator.execSpecial(
                    String.format(GET_PID, MonkeyMe.adbLocation, device.getSerialNumber(), application));
        }
        logger.debug(getStringforPrinting("pid string for ", application, pidString));
        List<String> outList = new ArrayList<String>();
        if (StringUtils.isNotEmpty(pidString)) {
            Process pidCmd = null;
            try {
                //read the strace command output
                pidCmd = execCommand(
                        String.format(TRACE_PID, MonkeyMe.adbLocation, device.getSerialNumber(), pidString));

                BufferedReader pidReader = new BufferedReader(new InputStreamReader(pidCmd.getInputStream()));
                String out = "";
                while ((out = pidReader.readLine()) != null) {

                    //break the loop if the current thread has been cancelled
                    if (Thread.currentThread().isInterrupted()) {
                        break;
                    }
                    outList.add(getStringforPrinting(System.currentTimeMillis(), application, out));

                    if (StringUtils.contains(out, "connect")) {
                        logger.debug(out);
                        FileUtils.write(new File(MonkeyMe.straceOutputLocation),
                                getStringforPrinting(System.currentTimeMillis(), application, out) + "\n",
                                true);
                    }
                }
            } finally {
                FileUtils.writeLines(new File(MonkeyMe.straceDumpLocation), outList, true);
                if (pidCmd != null) {
                    pidCmd.destroy();
                }
            }

        }
    } catch (Exception e) {
        logger.error("Error while processing monitoring network for " + application, e);
    }
}