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

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

Introduction

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

Prototype

public static List readLines(File file) throws IOException 

Source Link

Document

Reads the contents of a file line by line to a List of Strings using the default encoding for the VM.

Usage

From source file:com.mythesis.profileanalysis.Evaluate.java

public Evaluate(String outputDirectory, List<Integer> nTopics, List<Double> beta, int niters, int top_words,
        String LDAdir, double testSplit) {
    this.outputDirectory = outputDirectory;
    this.nTopics = new ArrayList<>();
    this.alpha = new ArrayList<>();
    this.beta = new ArrayList<>();
    this.nTopics = nTopics;
    for (Integer nTopic : nTopics) {
        this.alpha.add((double) (50 / nTopic));
    }//from ww w.  ja  va  2s  .  c o m
    this.beta = beta;
    this.niters = niters;
    this.top_words = top_words;
    logLikelihoods = new ArrayList<>();
    trainingSet = new ArrayList<>();
    testSet = new ArrayList<>();

    File ldaFile = new File(LDAdir);
    List<String> pages = new ArrayList<>();
    try {
        pages = FileUtils.readLines(ldaFile);
    } catch (IOException ex) {
        Logger.getLogger(Evaluate.class.getName()).log(Level.SEVERE, null, ex);
    }

    pages.remove(0);
    //shuffle pages 
    Collections.shuffle(pages);
    int testSetSize = (int) (pages.size() * testSplit);
    int trainingSetSize = pages.size() - testSetSize;
    int counter = 0;
    Random rn = new Random();
    testSet.add(String.valueOf(testSetSize));
    trainingSet.add(String.valueOf(trainingSetSize));

    while (counter < testSetSize) {
        int index = rn.nextInt(pages.size());
        if (!testSet.contains(pages.get(index))) {
            testSet.add(pages.get(index));
            pages.remove(index);
            counter++;
        }
    }

    trainingSet.addAll(pages);
}

From source file:jenkins.plugins.tanaguru.ProjectTanaguruAction.java

@Override
public String getUrlName() {
    String webappUrl = Jenkins.getInstance().getDescriptorByType(TanaguruRunnerBuilder.DescriptorImpl.class)
            .getInstallation().getWebappUrl();
    if (project.getLastBuild() != null) {
        try {//from w  ww. ja  v  a2 s . c o m
            for (String line : FileUtils.readLines(project.getLastBuild().getLogFile())) {
                if (StringUtils.startsWith(line, "Audit Id")) {
                    return buildAuditResultUrl(line, webappUrl);
                }
            }
        } catch (IOException ex) {
            Logger.getLogger(ProjectTanaguruAction.class.getName()).log(Level.SEVERE, null, ex);
        }
    }
    return webappUrl;
}

From source file:dk.nsi.haiba.lprimporter.testdata.SQLStatementsFromCPR83174CSV.java

private void generateAdministrationData() throws IOException {
    File file = FileUtils.toFile(getClass().getClassLoader().getResource("data/cpr83174ADM.csv"));
    boolean first = true;
    List<String> lines = FileUtils.readLines(file);

    for (String line : lines) {
        if (first) {
            // first row is column metadata
            first = false;//w  w  w.  java2 s  . c  om
            continue;
        }
        //v_recnum;c_sgh;c_afd;c_pattype;v_cpr;d_inddto;d_uddto;v_indtime;v_udtime

        String[] splits = line.split(";");
        String recnum = splits[0];
        String sygehus = splits[1];
        String afdeling = splits[2];
        String type = splits[3];
        String cpr = splits[4];

        String idate = splits[5];
        String udate = splits[6];

        String itime = splits[7];
        if (itime.length() == 0) {
            itime = "0";
        }
        String utime = splits[8];
        if (utime.length() == 0) {
            utime = "0";
        }

        StringBuffer sql = new StringBuffer();
        sql.append(
                "INSERT INTO T_ADM (v_RECNUM, C_SGH, C_AFD, V_CPR, D_INDDTO,D_UDDTO,V_INDTIME,V_UDTIME, C_PATTYPE) VALUES (");
        sql.append(recnum);
        sql.append(", '");
        sql.append(sygehus);
        sql.append("', '");
        sql.append(afdeling);
        sql.append("', '");
        sql.append(cpr);
        sql.append("', '");
        sql.append(idate);
        sql.append("', '");
        sql.append(udate);
        sql.append("', ");
        sql.append(itime);
        sql.append(", ");
        sql.append(utime);
        sql.append(", ");
        sql.append(type);
        sql.append(");");

        System.out.println(sql.toString());
    }
}

From source file:com.kurento.kmf.test.base.KmsLogOnFailure.java

@Override
protected void failed(Throwable e, Description description) {

    if (KurentoServicesTestHelper.printKmsLog()) {

        String testDir = KurentoServicesTestHelper.getTestDir();
        String testCaseName = KurentoServicesTestHelper.getTestCaseName();
        String testName = KurentoServicesTestHelper.getTestName();
        File logFile = new File(testDir + "TEST-" + testCaseName + "/" + testName + "-kms.log");

        if (logFile.exists()) {
            System.err//  w w  w.  j  av  a 2 s  . c om
                    .println("******************************************************************************");
            System.err.println(description.getClassName() + "." + testName + " TEST FAILED");
            // showException(e);
            System.err
                    .println("******************************************************************************");
            System.err.println("Log file path: " + logFile.getAbsolutePath());
            System.err.println("Content:");

            try {
                for (String line : FileUtils.readLines(logFile)) {
                    System.err.println(line);
                }
            } catch (IOException e1) {
                System.err.println("Error reading lines in log file");
                e1.printStackTrace();
            }

            System.err
                    .println("******************************************************************************");

        }
    }

}

From source file:cloud.gui.DistributionSelectionActionListener.java

@SuppressWarnings("static-access")
@Override/* w w  w  . j a  v  a2 s  .com*/
public void actionPerformed(ActionEvent e) {
    String name = (String) gui.getDistributions().getSelectedItem();
    if (DistributionName.EXPONENTIAL.getName().equals(name)) {
        gui.decorateExponentialDistribution();
    } else if (DistributionName.UNIFORM.getName().equals(name)) {
        gui.decorateForUniformDistribution();
    } else if (DistributionName.CONSTANT.getName().equals(name)) {
        gui.decorateForConstantDistribution();
    } else if (DistributionName.CUSTOM.getName().equals(name)) {
        JFileChooser fileChooser = new JFileChooser();
        int returnVal = fileChooser.showOpenDialog(gui);
        if (returnVal == fileChooser.APPROVE_OPTION) {
            File file = fileChooser.getSelectedFile();
            try {
                List<String> lines = FileUtils.readLines(file);
                boolean result = validate(lines);
                if (!result) {
                    gui.decorateForInValidDistribution();
                    logger.error("Invalid Distribution file " + file.getName());
                } else {
                    gui.decorateForCustomDistribution(lines);
                    logger.info("File " + file.getName() + " is imported to generate the distribution from");
                }
            } catch (IOException e1) {
                e1.printStackTrace();
            }
        } else {
            gui.getDistributions().setSelectedIndex(0);
            gui.decorateForUniformDistribution();
        }
    }
}

From source file:com.splunk.shuttl.archiver.bucketsize.BucketSizeIOTest.java

public void getFileWithBucketSize_givenBucket_returnsFileWithSizeOfBucket() throws IOException {
    File fileWithBucketSize = bucketSizeIO.getFileWithBucketSize(bucket);
    List<String> linesOfFile = FileUtils.readLines(fileWithBucketSize);
    assertEquals(1, linesOfFile.size());
    String firstLine = linesOfFile.get(0);
    assertEquals(bucket.getSize() + "", firstLine);
}

From source file:ca.weblite.xmlvm.ConstantPoolHelper.java

public static void removeConstantPoolDependencies(Map<Integer, Constant> constantPool, File file)
        throws IOException {
    String strPattern = "xmlvm_create_java_string_from_pool\\((\\d+)\\)";
    Pattern regex = Pattern.compile(strPattern);

    List<String> lines = FileUtils.readLines(file);
    List<String> out = new ArrayList<String>();
    boolean changed = false;
    for (String line : lines) {
        if (line.indexOf("xmlvm_create_java_string_from_pool") != -1) {
            Matcher m = regex.matcher(line);
            if (m.find()) {
                String idStr = m.group(1);
                Constant theConstant = constantPool.get(Integer.parseInt(idStr));
                String strVal = theConstant.data;
                int len = theConstant.len;
                if (strVal == null) {
                    throw new RuntimeException("Constant pool does not contain string id " + idStr);
                }//  w w w.  j a va2 s  .  c om
                changed = true;
                line = line.replaceAll(strPattern,
                        "xmlvm_create_java_string_from_char_array((JAVA_OBJECT)" + strVal + "," + len + ")");
            }
        }
        out.add(line);
    }

    if (changed) {
        FileUtils.writeLines(file, out);
    }

}

From source file:com.gargoylesoftware.htmlunit.source.Patch.java

/**
 * Prints to <tt>System.out</tt> the "String html = ..." string from the actual HTML file.
 * @param htmlFile the path of the HTML file
 * @throws IOException if an exception occurs
 *///  w w w  .  ja va 2s . c om
public static void generateHtmlString(final File htmlFile) throws IOException {
    final List<String> lines = FileUtils.readLines(htmlFile);
    for (int i = 0; i < lines.size(); i++) {
        final String line = lines.get(i).replace("\t", "    ").replace("\\", "\\\\").replace("\"", "\\\"");
        if (i == 0) {
            System.out.println("        final String html = \"" + line + "\\n\"");
        } else {
            System.out.print("            + \"" + line);
            if (i == lines.size() - 1) {
                System.out.print("\";");
            } else {
                System.out.print("\\n\"");
            }
            System.out.println();
        }
    }
}

From source file:net.itransformers.topologyviewer.fulfilmentfactory.impl.TestFulfilmentImpl.java

public void execute(String fileName, Map<String, String> params) throws IOException {
    List<String> lines = FileUtils.readLines(new File(projectPath, fileName));
    Set<String> vars = new HashSet<String>();
    Map<String, String> readUntilArgs = null;
    for (String line : lines) {
        if (line.startsWith("### vars:")) {
            vars.addAll(readVars(line));
        } else if (line.startsWith("### read_until")) {
            Map<String, String> readSingleUntilArgs = parseReadUntilArgs(line, params);
            readUntil(readSingleUntilArgs);
            continue;
        } else if (line.startsWith("### start read_until")) {
            readUntilArgs = parseReadUntilArgs(line, params);
            readUntil(readUntilArgs);//from  w  ww.  j ava  2  s .com
            continue;
        } else if (line.startsWith("### stop read_until")) {
            readUntilArgs = null; // if no readUntilArgs then no read_until will be performed
        } else if (line.startsWith("### exit")) {
            exit();
        } else if (line.startsWith("### //")) {
            // do nothing just a comment
        } else if (line.startsWith("###")) {
            throw new RuntimeException("Unexpected line: " + line);
        } else {
            sendCommand(line, vars, params);
        }
        if (readUntilArgs != null) {
            readUntil(readUntilArgs);
        }
    }
}

From source file:admincommands.SendRawPacket.java

@Override
public void executeCommand(Player admin, String[] params) {
    if (admin.getAccessLevel() < AdminConfig.COMMAND_SENDRAWPACKET) {
        PacketSendUtility.sendMessage(admin, "You dont have enough rights to execute this command");
        return;// w  w  w  . j  a  v  a 2  s.com
    }

    if (params.length != 1) {
        PacketSendUtility.sendMessage(admin, "Usage: //raw [name]");
        return;
    }

    File file = new File(ROOT, params[0] + ".txt");

    if (!file.exists() || !file.canRead()) {
        PacketSendUtility.sendMessage(admin, "Wrong file selected.");
        return;
    }

    try {
        @SuppressWarnings({ "unchecked" })
        List<String> lines = FileUtils.readLines(file);

        SM_CUSTOM_PACKET packet = null;

        for (String row : lines) {
            String[] tokens = row.substring(0, 48).trim().split(" ");
            int len = tokens.length;

            for (int i = 0; i < len; i++) {
                if (i == 0) {
                    packet = new SM_CUSTOM_PACKET(Integer.valueOf(tokens[i], 16));
                } else if (i > 2) {
                    packet.addElement(PacketElementType.C, "0x" + tokens[i]);
                }
            }
        }

        if (packet != null)
            PacketSendUtility.sendPacket(admin, packet);
    } catch (IOException e) {
        PacketSendUtility.sendMessage(admin, "An error has occurred.");
        logger.warn("IO Error.", e);
    }
}