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:de.tudarmstadt.ukp.experiments.ej.bills.experiment1.Exp1Reader.java

@Override
public void initialize(UimaContext context) throws ResourceInitializationException {
    super.initialize(context);

    // open JSON file here
    try {/*from  www .  j  a va 2  s.co m*/
        jsonSize = FileUtils.readLines(new File(jsonFile)).size();
        jsonIterator = FileUtils.lineIterator(new File(jsonFile), "UTF-8");
    } catch (IOException e) {
        throw new ResourceInitializationException(e);
    }
}

From source file:de.unisb.cs.st.javalanche.rhino.RhinoTestDriver.java

@SuppressWarnings("unchecked")
@Override/*  w  w  w  .j  a v  a2s .c o  m*/
protected List<String> getAllTests() {
    String rhinoTestFile = Util.getPropertyOrFail(TEST_FILE);
    try {
        List<String> allTests = FileUtils.readLines(new File(rhinoTestFile));
        return allTests;
    } catch (IOException e) {
        e.printStackTrace();
        throw new RuntimeException(e);
    }
}

From source file:hu.bme.mit.sette.tools.jpet.JPetParser.java

@Override
protected void parseSnippet(Snippet snippet, SnippetInputsXml inputsXml) throws Exception {
    File outputFile = RunnerProjectUtils.getSnippetOutputFile(getRunnerProjectSettings(), snippet);
    File errorFile = RunnerProjectUtils.getSnippetErrorFile(getRunnerProjectSettings(), snippet);

    if (errorFile.exists()) {
        // TODO enhance this section and make it clear
        List<String> lines = FileUtils.readLines(errorFile);

        String firstLine = lines.get(0);

        if (firstLine.startsWith("ERROR: test_data_generator:unfold_bck/6: Undefined procedure:")) {
            inputsXml.setResultType(ResultType.NA);
        } else if (firstLine.startsWith("ERROR: Domain error: `clpfd_expression' expected, found")) {
            inputsXml.setResultType(ResultType.NA);
        } else if (firstLine.startsWith("ERROR: Unknown message: error(resolve_classfile/")) {
            inputsXml.setResultType(ResultType.NA);
        } else if (firstLine.startsWith("ERROR: local_control:unfold/3: Undefined procedure:")) {
            inputsXml.setResultType(ResultType.NA);
        } else {/*from  w  ww.  j  av  a 2 s . c  o m*/
            // TODO enhance error handling

            // this is debug (only if unhandled error)
            System.err.println("=============================");
            System.err.println(snippet.getMethod());
            System.err.println("=============================");

            for (String line : lines) {
                System.err.println(line);
            }
            System.err.println("=============================");

            // TODO enhance error handling
            throw new RuntimeException("PARSER PROBLEM, UNHANDLED ERROR");
        }
    } else {
        // TODO enhance

        // LineIterator lines = FileUtils.lineIterator(outputFile);
        List<String> lines = FileUtils.readLines(outputFile);

        if (lines.get(lines.size() - 1).startsWith("Error loading bytecode program")) {
            // System.err.println(snippet.getMethod().getName());
            // System.err.println("BYTECODE PROBLEM");
            inputsXml.setResultType(ResultType.EX);
            // throw new RuntimeException(""
        } else {
            inputsXml.setResultType(ResultType.S);

            // extract coverage
            if (lines.size() >= 8) {
                String fullCode = lines.get(lines.size() - 3).trim();
                String topCode = lines.get(lines.size() - 2).trim();

                Matcher mFull = PATTERN_FULL_CODE.matcher(fullCode);
                Matcher mTop = PATTERN_TOP_CODE.matcher(topCode);

                // TODO should not use jPET coverage information in the
                // future
                if (mFull.matches() && mTop.matches()) {
                    double full = Double.parseDouble(mFull.group(1));
                    double top = Double.parseDouble(mTop.group(1));

                    if (full == 100.0 && top == 100.0) {
                        // full -> C
                        inputsXml.setResultType(ResultType.C);
                    } else if (snippet.getIncludedConstructors().isEmpty()
                            && snippet.getIncludedMethods().isEmpty()) {
                        // only consider top, no included things
                        if (top >= snippet.getRequiredStatementCoverage()) {
                            inputsXml.setResultType(ResultType.C);
                        } else {
                            inputsXml.setResultType(ResultType.NC);
                            // System.err.println(snippet.getMethod()
                            // .getName());
                            // System.err
                            // .println(String
                            // .format("No incl. no statis. - Full: %.2f Top: %.2f Req: %.2f",
                            // full,
                            // top,
                            // snippet.getRequiredStatementCoverage()));
                        }
                    } else {
                        // few cases, not very usefol top and full now...
                        // System.err.println(snippet.getMethod()
                        // .getName());
                        // System.err.println(String.format(
                        // "Has included - Full: %.2f Top: %.2f Req: %.2f",
                        // full,
                        // top,
                        // snippet.getRequiredStatementCoverage()));

                    }
                } else {
                    // TODO error handling
                    System.err.println("Both should match");
                }
            }

            // extract inputs
            lines = null;

            File testCasesFile = getTool().getTestCaseXmlFile(getRunnerProjectSettings(), snippet);
            new FileValidator(testCasesFile).type(FileType.REGULAR_FILE).validate();

            if (testCasesFile.length() > 10 * 10e6) {
                // TODO enhance this section
                System.err.println("Filesize is bigger than 10 MB: " + testCasesFile);
            }
            // TODO it was used to dump the cases where jpet cannot decide
            // coverage
            // if (inputsXml.getResultType() == ResultType.S) {
            // System.out.println("Only S");
            // }

            // now skip, only 12 cases are S

            System.out.println(
                    snippet.getContainer().getJavaClass().getName() + "." + snippet.getMethod().getName());

            SAXParserFactory factory = SAXParserFactory.newInstance();
            SAXParser saxParser = factory.newSAXParser();

            JPetTestCaseXmlParser testCasesParser = new JPetTestCaseXmlParser();

            saxParser.parse(testCasesFile, testCasesParser);

            JPetTestCasesConverter.convert(snippet, testCasesParser.getTestCases(), inputsXml);
        }

        // find input lines
        //
        // List<String> inputLines = new ArrayList<>();
        // boolean shouldCollect = false;
        // while (lines.hasNext()) {
        // String line = lines.next();
        // if (line.trim()
        // .equals("====================================================== Method Summaries"))
        // {
        // shouldCollect = true;
        // } else if (shouldCollect) {
        // if
        // (line.startsWith("======================================================"))
        // {
        // // start of next section
        // shouldCollect = false;
        // break;
        // } else {
        // if (!StringUtils.isBlank(line)) {
        // inputLines.add(line.trim());
        // }
        // }
        // }
        // }
        //
        // // close iterator
        // lines.close();
        //
        // // remove duplicates
        // inputLines = new ArrayList<>(new LinkedHashSet<>(inputLines));
        //
        // String firstLine = inputLines.get(0);
        // assert (firstLine.startsWith("Inputs: "));
        // firstLine = firstLine.substring(7).trim();
        // String[] parameterStrings = StringUtils.split(firstLine, ',');
        // ParameterType[] parameterTypes = new
        // ParameterType[parameterStrings.length];
        //
        // if (inputLines.size() == 2
        // && inputLines.get(1).startsWith("No path conditions for")) {
        // InputElement input = new InputElement();
        // for (int i = 0; i < parameterStrings.length; i++) {
        // // no path conditions, only considering the "default" inputs
        // Class<?> type = snippet.getMethod().getParameterTypes()[i];
        // parameterTypes[i] = getParameterType(type);
        // input.parameters().add(
        // new ParameterElement(parameterTypes[i],
        // getDefaultParameterString(type)));
        // }
        // inputsXml.generatedInputs().add(input);
        // } else {
        // // parse parameter types
        //
        // Class<?>[] paramsJavaClass = snippet.getMethod()
        // .getParameterTypes();
        //
        // for (int i = 0; i < parameterStrings.length; i++) {
        // String parameterString = parameterStrings[i];
        // Class<?> pjc = ClassUtils
        // .primitiveToWrapper(paramsJavaClass[i]);
        //
        // if (parameterString.endsWith("SYMINT")) {
        // if (pjc == Boolean.class) {
        // parameterTypes[i] = ParameterType.BOOLEAN;
        // } else if (pjc == Byte.class) {
        // parameterTypes[i] = ParameterType.BYTE;
        // } else if (pjc == Short.class) {
        // parameterTypes[i] = ParameterType.SHORT;
        // } else if (pjc == Integer.class) {
        // parameterTypes[i] = ParameterType.INT;
        // } else if (pjc == Long.class) {
        // parameterTypes[i] = ParameterType.LONG;
        // } else {
        // // int for something else
        // parameterTypes[i] = ParameterType.INT;
        // }
        // } else if (parameterString.endsWith("SYMREAL")) {
        // if (pjc == Float.class) {
        // parameterTypes[i] = ParameterType.FLOAT;
        // } else if (pjc == Float.class) {
        // parameterTypes[i] = ParameterType.DOUBLE;
        // } else {
        // // int for something else
        // parameterTypes[i] = ParameterType.DOUBLE;
        // }
        // } else {
        // // TODO error handling
        // // int for something else
        // throw new RuntimeException("PARSER PROBLEM");
        // }
        // }
        //
        // // example
        // // inheritsAPIGuessTwoPrimitives(11,-2147483648(don't care)) -->
        // // "java.lang.IllegalArgumentException..."
        // // inheritsAPIGuessTwoPrimitives(9,11) -->
        // // "java.lang.IllegalArgumentException..."
        // // inheritsAPIGuessTwoPrimitives(7,9) -->
        // // "java.lang.RuntimeException: Out of range..."
        // // inheritsAPIGuessTwoPrimitives(4,1) --> Return Value: 1
        // // inheritsAPIGuessTwoPrimitives(0,0) --> Return Value: 0
        // // inheritsAPIGuessTwoPrimitives(9,-88) -->
        // // "java.lang.IllegalArgumentException..."
        // // inheritsAPIGuessTwoPrimitives(-88,-2147483648(don't care))
        // // --> "java.lang.IllegalArgumentException..."
        //
        // String ps = String.format("^%s\\((.*)\\) --> (.*)$", snippet
        // .getMethod().getName());
        //
        // ps = String.format("^%s(.*) --> (.*)$", snippet.getMethod()
        // .getName());
        // Pattern p = Pattern.compile(ps);
        //
        // // parse inputs
        // int i = -1;
        // for (String line : inputLines) {
        // i++;
        //
        // if (i == 0) {
        // // first line
        // continue;
        // } else if (StringUtils.isEmpty(line)) {
        // continue;
        // }
        //
        // Matcher m = p.matcher(line);
        //
        // if (m.matches()) {
        // String paramsString = StringUtils.substring(m.group(1)
        // .trim(), 1, -1);
        // String resultString = m.group(2).trim();
        //
        // paramsString = StringUtils.replace(paramsString,
        // "(don't care)", "");
        //
        // String[] paramsStrings = StringUtils.split(
        // paramsString, ',');
        //
        // InputElement input = new InputElement();
        //
        // // if index error -> lesser inputs than parameters
        // for (int j = 0; j < parameterTypes.length; j++) {
        // if (parameterTypes[j] == ParameterType.BOOLEAN
        // && paramsStrings[j].contains("-2147483648")) {
        // // don't care -> 0
        // paramsStrings[j] = "false";
        // }
        //
        // ParameterElement pe = new ParameterElement(
        // parameterTypes[j], paramsStrings[j].trim());
        //
        // try {
        // // just check the type format
        // pe.validate();
        // } catch (Exception e) {
        // // TODO debug - remove or log
        // System.out.println(parameterTypes[j]);
        // System.out.println(paramsStrings[j]);
        // System.out.println(pe.getType());
        // System.out.println(pe.getValue());
        // e.printStackTrace();
        //
        // System.err
        // .println("=============================");
        // System.err.println(snippet.getMethod());
        // System.err
        // .println("=============================");
        // for (String lll : inputLines) {
        // System.err.println(lll);
        // }
        // System.err
        // .println("=============================");
        //
        // System.exit(-1);
        // }
        //
        // input.parameters().add(pe);
        // }
        //
        // if (resultString.startsWith("Return Value:")) {
        // // has retval, nothing to do
        // } else {
        // // exception; example (" is present inside the
        // // string!!!):
        // // "java.lang.ArithmeticException: div by 0..."
        // // "java.lang.IndexOutOfBoundsException: Index: 1, Size: 5..."
        //
        // int pos = resultString.indexOf(':');
        // if (pos < 0) {
        // // not found :, search for ...
        // pos = resultString.indexOf("...");
        // }
        //
        // String ex = resultString.substring(1, pos);
        //
        // input.setExpected((Class<? extends Throwable>) Class
        // .forName(ex));
        //
        // // System.err.println(resultString);
        // // System.err.println(ex);
        // // // input.setExpected(expected);
        // }
        //
        // inputsXml.generatedInputs().add(input);
        // } else {
        // System.err.println("NO MATCH");
        // System.err.println(ps);
        // System.err.println(line);
        // throw new Exception("NO MATCH: " + line);
        // }
        // }
        // }
        //
        // inputsXml.validate();
    }
}

From source file:com.gargoylesoftware.htmlunit.javascript.host.ObjectsTest.java

private static List<String> getObjects(final BrowserVersion browserVersion) throws Exception {
    final URL url = ObjectsTest.class.getClassLoader()
            .getResource("objects/objects." + browserVersion.getNickname() + ".txt");
    return FileUtils.readLines(new File(url.toURI()));
}

From source file:hudson.model.ItemGroupMixInTest.java

/**
 * This test unit makes sure that if part of the config.xml file is
 * deleted it will still load everything else inside the folder.
 * The test unit expects an IOException is thrown, and the one failed
 * job fails to load.//from  w w w  .  j  ava 2 s. c  o m
 */
@Issue("JENKINS-22811")
@Test
public void xmlFileFailsToLoad() throws Exception {
    MockFolder folder = r.createFolder("folder");
    assertNotNull(folder);

    AbstractProject project = folder.createProject(FreeStyleProject.class, "job1");
    AbstractProject project2 = folder.createProject(FreeStyleProject.class, "job2");
    AbstractProject project3 = folder.createProject(FreeStyleProject.class, "job3");

    File configFile = project.getConfigFile().getFile();

    List<String> lines = FileUtils.readLines(configFile).subList(0, 5);
    configFile.delete();

    // Remove half of the config.xml file to make "invalid" or fail to load
    FileUtils.writeByteArrayToFile(configFile, lines.toString().getBytes());
    for (int i = lines.size() / 2; i < lines.size(); i++) {
        FileUtils.writeStringToFile(configFile, lines.get(i), true);
    }

    // Reload Jenkins.
    r.jenkins.reload();

    // Folder
    assertNotNull("Folder failed to load.", r.jenkins.getItemByFullName("folder"));
    assertNull("Job should have failed to load.", r.jenkins.getItemByFullName("folder/job1"));
    assertNotNull("Other job in folder should have loaded.", r.jenkins.getItemByFullName("folder/job2"));
    assertNotNull("Other job in folder should have loaded.", r.jenkins.getItemByFullName("folder/job3"));
}

From source file:edu.ku.brc.specify.tools.StrLocaleFile.java

/**
 * /* www .j a  v  a2  s. c  om*/
 */
@SuppressWarnings("unchecked")
private void load() {
    char[] dstBytes = new char[2048];
    try {
        itemHash.clear();

        File file = new File(dstPath);
        if (file.exists()) {
            int duplicateCnt = 0;
            int index = 0;
            int count = 0;
            List<String> lines = (List<String>) FileUtils.readLines(file);
            for (String line : lines) {
                if (line.trim().startsWith("#")) {
                    items.add(new StrLocaleEntry("#", line, null, STATUS.IsComment));

                } else if (line.indexOf('=') > -1) {
                    int inx = line.indexOf('=');

                    String key = line.substring(0, inx);
                    String value = line.substring(inx + 1, line.length());

                    boolean debug = false;//key.equals("TOP5") && StringUtils.contains(dstPath, "_pt");

                    if (debug) {
                        //System.out.println((byte)value.charAt(12)+"="+value.charAt(12));
                        char spec = '';
                        int fInx = value.indexOf(spec);
                        if (fInx > -1) {
                            int jj = 0;
                            byte[] bytes = value.getBytes();
                            for (int ii = 0; ii < bytes.length; ii++) {
                                byte b1 = bytes[ii];
                                short s1 = (short) (b1 < 0 ? (256 + b1) : b1);
                                if (s1 > 127 && s1 != 195)
                                    s1 += 64;

                                //System.out.println(ii+"  "+bytes[ii]+" ");
                                if (s1 == 195) {
                                    ii++;
                                    b1 = bytes[ii];
                                    s1 = (short) (b1 < 0 ? (256 + b1) : b1);
                                    if (s1 > 127 && s1 != 195)
                                        s1 += 64;

                                    dstBytes[jj++] = (char) s1;
                                } else {
                                    dstBytes[jj++] = (char) bytes[ii];
                                }
                            }
                            System.out.print(value + '=');
                            value = new String(dstBytes, 0, jj);
                            System.out.println(value);
                        }
                        /*for (String k : l10nMappingHash.keySet())
                        {
                        String before = value;
                        int    sInx   = value.indexOf(k);
                        if (sInx > -1)
                        {
                            for (int i=0;i<value.length();i++)
                            {
                                byte b = (byte)value.charAt(i);
                                System.out.print(b);
                                if (b < 0) b = (byte)(256 + (int)b);
                                System.out.println(" ["+value.charAt(i)+"]["+b+"]");
                            }
                            //int eInx = sInx + 2;
                            //value = value.substring(0, sInx-1) + l10nMappingHash.get(k) + (eInx < value.length() ? value.substring(eInx) : "");
                            //value = StringUtils.replace(value, k, l10nMappingHash.get(k));
                            //System.out.println("Contains["+k+"] b4["+before+"]["+value+"]["+k+"]["+l10nMappingHash.get(k)+"]");
                        } else
                        {
                            System.out.println("NOT Contains["+k+"]");
                        }
                        }*/
                    }

                    if (itemHash.get(key) != null) {
                        log.error("Key '" + key + "' on Line " + count + " is a duplicate.");
                        duplicateCnt++;

                    } else {
                        StrLocaleEntry entry = new StrLocaleEntry(key, value, null,
                                StringUtils.isEmpty(value) ? STATUS.IsNew : STATUS.IsOK);
                        items.add(entry);
                        itemHash.put(key, entry);
                        keyToInxMap.put(key, keys.size());
                        keys.add(entry);
                    }

                    index++;

                } else {
                    items.add(new StrLocaleEntry(null, null, null, STATUS.IsBlank));
                }
                count++;
            }
            log.error(duplicateCnt + " duplicate keys: " + dstPath);
        }

        if (isDestination) {
            loadCheckFile();
        }

        clearEditFlags();

    } catch (IOException ex) {
        ex.printStackTrace();
    }
}

From source file:de.tudarmstadt.ukp.dkpro.core.mallet.lda.io.MalletLdaTopicProportionsWriterTest.java

@Test
public void testSingularTarget() throws UIMAException, IOException, URISyntaxException {
    File modelFile = new File(testContext.getTestOutputFolder(), "model");
    File targetFile = new File(testContext.getTestOutputFolder(), "topics.txt");
    MalletLdaUtil.trainModel(modelFile);

    int expectedLines = 2;
    String expectedLine0Regex = "dummy1.txt\t(0\\.[0-9]{4}\\t){9}0\\.[0-9]{4}";
    String expectedLine1Regex = "dummy2.txt\t(0\\.[0-9]{4}\\t){9}0\\.[0-9]{4}";

    CollectionReaderDescription reader = createReaderDescription(TextReader.class,
            TextReader.PARAM_SOURCE_LOCATION, MalletLdaUtil.CAS_DIR, TextReader.PARAM_PATTERNS,
            MalletLdaUtil.CAS_FILE_PATTERN, TextReader.PARAM_LANGUAGE, MalletLdaUtil.LANGUAGE);
    AnalysisEngineDescription segmenter = createEngineDescription(BreakIteratorSegmenter.class);

    AnalysisEngineDescription inferencer = createEngineDescription(MalletLdaTopicModelInferencer.class,
            MalletLdaTopicModelInferencer.PARAM_MODEL_LOCATION, modelFile);

    AnalysisEngineDescription writer = createEngineDescription(MalletLdaTopicProportionsWriter.class,
            MalletLdaTopicProportionsWriter.PARAM_TARGET_LOCATION, targetFile,
            MalletLdaTopicProportionsWriter.PARAM_OVERWRITE, true,
            MalletLdaTopicProportionsWriter.PARAM_SINGULAR_TARGET, true);

    SimplePipeline.runPipeline(reader, segmenter, inferencer, writer);
    List<String> lines = FileUtils.readLines(targetFile);
    assertTrue(lines.get(0).matches(expectedLine0Regex));
    assertTrue(lines.get(1).matches(expectedLine1Regex));
    assertEquals(expectedLines, lines.size());
}

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

/**
 * Tests that the deployed snapshot is not more than two weeks old.
 *
 * Currently it is configured to check every week.
 *
 * @throws Exception if an error occurs/* w w  w. j av a  2  s  .  com*/
 */
@Test
public void snapshot() throws Exception {
    if (isDifferentWeek()) {
        final List<String> lines = FileUtils.readLines(new File("pom.xml"));
        String version = null;
        for (int i = 0; i < lines.size(); i++) {
            if ("<artifactId>htmlunit</artifactId>".equals(lines.get(i).trim())) {
                version = getValue(lines.get(i + 1));
                break;
            }
        }
        if (version.contains("SNAPSHOT")) {
            try (final WebClient webClient = getWebClient()) {
                final XmlPage page = webClient
                        .getPage("https://oss.sonatype.org/content/repositories/snapshots/"
                                + "net/sourceforge/htmlunit/htmlunit/" + version + "/maven-metadata.xml");
                final String timestamp = page.getElementsByTagName("timestamp").get(0).getTextContent();
                final DateFormat format = new SimpleDateFormat("yyyyMMdd.HHmmss", Locale.ROOT);
                final long snapshotMillis = format.parse(timestamp).getTime();
                final long nowMillis = System.currentTimeMillis();
                final long days = TimeUnit.MILLISECONDS.toDays(nowMillis - snapshotMillis);
                assertTrue("Snapshot not deployed for " + days + " days", days < 14);
            }
        }
    }
}

From source file:edu.ku.brc.specify.dbsupport.cleanuptools.LocalityGeoBoundsChecker2.java

/**
 * //from ww  w. jav  a  2s.co  m
 */
public void load() {
    File file = new File(XMLHelper.getConfigDirPath("st99_d00a.dat"));
    try {
        List<String> lines = (List<String>) FileUtils.readLines(file);
        for (int i = 0; i < lines.size(); i++) {
            String polygonId = StringUtils.remove(StringUtils.deleteWhitespace(lines.get(i++)), '"');
            String stateId = StringUtils.remove(StringUtils.deleteWhitespace(lines.get(i++)), '"');
            String stateNm = StringUtils.remove(StringUtils.deleteWhitespace(lines.get(i++)), '"');
            i += 2;

            StateInfo si = statesHash.get(stateNm);
            if (si == null) {
                String code = statesCodeHash.get(stateNm);
                si = new StateInfo(stateNm, code, stateId);
                statesHash.put(stateNm, si);
                codeToStateInfoHash.put(code, si);
            }
            statesIdHash.put(polygonId, si);
        }

        for (String polygonId : statesIdHash.keySet()) {
            System.out.println(String.format("%s - %s", polygonId, statesIdHash.get(polygonId).name));
        }

        file = new File(XMLHelper.getConfigDirPath("st99_d00.dat"));
        FileInputStream fis = new FileInputStream(file);
        BufferedReader bufRdr = new BufferedReader(new InputStreamReader(fis));

        StateInfo si = null;
        ArrayList<Position> points = null;

        String s;
        while ((s = bufRdr.readLine()) != null) {
            String[] tokens = StringUtils.split(s, ' ');
            if (tokens.length == 3) {
                //System.out.println(tokens[0]);
                /*if (points != null)
                {
                Polyline polygon = new Polyline(); 
                polygon.setPositions(points);
                si.addPolygon(polygon);
                }*/

                si = statesIdHash.get(tokens[0]);
                points = new ArrayList<Position>();

                //double lat = Double.valueOf(tokens[1]);
                //double lon = Double.valueOf(tokens[2]);
                //points.add(Position.fromDegrees(lat, lon, 0));

            } else if (tokens.length == 2) {
                double lat = Double.valueOf(tokens[1]);
                double lon = Double.valueOf(tokens[0]);
                points.add(Position.fromDegrees(lat, lon, 0));

            } else if (si != null) {
                Polyline polygon = new Polyline();
                polygon.setPositions(points);
                si.addPolygon(polygon);
                si = null;
            }
        }
        bufRdr.close();
        fis.close();

        for (StateInfo stateInfo : statesHash.values()) {
            System.out.println(String.format("%s - %d", stateInfo.name, stateInfo.polygons.size()));
        }

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

From source file:dkpro.similarity.uima.io.MeterCorpusReader.java

@Override
public List<CombinationPair> getAlignedPairs() throws ResourceInitializationException {
    List<CombinationPair> pairs = new ArrayList<CombinationPair>();

    List<File> sourceDirs = listDirectories(new File(inputDir.getAbsolutePath() + "/PA/annotated"));
    for (File sourceDir : sourceDirs) {
        File sourceFile = new ArrayList<File>(FileUtils.listFiles(sourceDir, new String[] { "sgml" }, false))
                .get(0);//www. j a v  a 2  s . c  om

        File suspiciousDir = new File(
                sourceDir.getAbsolutePath().replace("PA", "newspapers").replace("annotated", "rawtexts"));

        Collection<File> suspiciousFiles = FileUtils.listFiles(suspiciousDir, new String[] { "txt" }, false);

        for (File suspiciousFile : suspiciousFiles) {
            try {
                // Source files has a 13-line header. Remove it first.
                List<String> sourceLines = FileUtils.readLines(sourceFile);
                for (int i = 0; i < 13; i++) {
                    sourceLines.remove(0);
                }

                // Also remove the 5-line footer
                for (int i = 0; i < 5; i++) {
                    sourceLines.remove(sourceLines.size() - 1);
                }

                // Besides that, lines may end with a "<" character. Remove it, too.
                for (int i = 0; i < sourceLines.size(); i++) {
                    String line = sourceLines.get(i);

                    if (line.endsWith("<")) {
                        line = line.substring(0, line.length() - 1);
                        sourceLines.set(i, line);
                    }
                }

                String source = StringUtils.join(sourceLines, LF);
                String suspicious = FileUtils.readFileToString(suspiciousFile);

                // Get IDs
                String sourceID = sourceFile.getAbsolutePath()
                        .substring(sourceFile.getAbsolutePath().indexOf("meter") + 6);
                sourceID = sourceID.substring(0, sourceID.length() - 5);
                sourceID = sourceID.replace("annotated/", "");

                String suspiciousID = suspiciousFile.getAbsolutePath()
                        .substring(suspiciousFile.getAbsolutePath().indexOf("meter") + 6);
                suspiciousID = suspiciousID.substring(0, suspiciousID.length() - 4);
                suspiciousID = suspiciousID.replace("rawtexts/", "");

                CombinationPair pair = new CombinationPair(inputDir.getAbsolutePath());
                pair.setID1(suspiciousID);
                pair.setID2(sourceID);
                pair.setText1(suspicious);
                pair.setText2(source);

                pairs.add(pair);
            } catch (IOException e) {
                throw new ResourceInitializationException(e);
            }
        }
    }

    return pairs;
}