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

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

Introduction

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

Prototype

public static List readLines(Reader input) throws IOException 

Source Link

Document

Get the contents of a Reader as a list of Strings, one entry per line.

Usage

From source file:com.buildautomation.jgit.api.ShowBlame.java

private static int countFiles(Repository repository, ObjectId commitID, String name) throws IOException {
    try (RevWalk revWalk = new RevWalk(repository)) {
        RevCommit commit = revWalk.parseCommit(commitID);
        RevTree tree = commit.getTree();
        System.out.println("Having tree: " + tree);

        // now try to find a specific file
        try (TreeWalk treeWalk = new TreeWalk(repository)) {
            treeWalk.addTree(tree);//from   w  w w.j a  v a2s.c o m
            treeWalk.setRecursive(true);
            treeWalk.setFilter(PathFilter.create(name));
            if (!treeWalk.next()) {
                throw new IllegalStateException("Did not find expected file 'README.md'");
            }

            ObjectId objectId = treeWalk.getObjectId(0);
            ObjectLoader loader = repository.open(objectId);

            ByteArrayOutputStream stream = new ByteArrayOutputStream();
            // and then one can the loader to read the file
            loader.copyTo(stream);

            revWalk.dispose();

            return IOUtils.readLines(new ByteArrayInputStream(stream.toByteArray())).size();
        }
    }
}

From source file:ee.ria.xroad.proxy.testsuite.testcases.ServerProxyConnectionAborted3.java

@Override
public AbstractHandler getServerProxyHandler() {
    return new AbstractHandler() {
        @Override//from w  w  w . j  a  va 2s .  co  m
        public void handle(String target, Request baseRequest, HttpServletRequest request,
                HttpServletResponse response) throws IOException {
            // Read all of the request.
            IOUtils.readLines(request.getInputStream());

            response.setContentType("multipart/mixed; boundary=foobar");
            response.setContentLength(1000);
            response.getOutputStream().close();
            response.flushBuffer();
            baseRequest.setHandled(true);
        }
    };
}

From source file:brut.androlib.res.ResSmaliUpdater.java

public void updateResIDs(ResTable resTable, File smaliDir) throws AndrolibException {
    try {/* w  w w  .  j  a  v  a2s. c o  m*/
        Directory dir = new FileDirectory(smaliDir);
        for (String fileName : dir.getFiles(true)) {
            Iterator<String> it = IOUtils.readLines(dir.getFileInput(fileName)).iterator();
            PrintWriter out = new PrintWriter(dir.getFileOutput(fileName));
            while (it.hasNext()) {
                String line = it.next();
                out.println(line);
                Matcher m1 = RES_NAME_PATTERN.matcher(line);
                if (!m1.matches()) {
                    continue;
                }
                Matcher m2 = RES_ID_PATTERN.matcher(it.next());
                if (!m2.matches()) {
                    throw new AndrolibException();
                }
                int resID = resTable.getPackage(m1.group(1)).getType(m1.group(2)).getResSpec(m1.group(3))
                        .getId().id;
                if (m2.group(1) != null) {
                    out.println(String.format(RES_ID_FORMAT_FIELD, m2.group(1), resID));
                } else {
                    out.println(String.format(RES_ID_FORMAT_CONST, m2.group(2), resID));
                }
            }
            out.close();
        }
    } catch (IOException ex) {
        throw new AndrolibException("Could not tag res IDs for: " + smaliDir.getAbsolutePath(), ex);
    } catch (DirectoryException ex) {
        throw new AndrolibException("Could not tag res IDs for: " + smaliDir.getAbsolutePath(), ex);
    }
}

From source file:com.ning.metrics.meteo.subscribers.FileSubscriber.java

private ImmutableList<LinkedHashMap<String, Object>> getDataPoints() {
    ImmutableList.Builder<LinkedHashMap<String, Object>> builder = new ImmutableList.Builder<LinkedHashMap<String, Object>>();

    try {/*  w w w  .  ja  v  a 2s.c  o m*/
        for (String line : (List<String>) IOUtils.readLines(new FileReader(subscriberConfig.getFilePath()))) {
            if (line.trim().length() > 0) {
                map.clear();
                String[] items = line.split(subscriberConfig.getSeparator());
                long dateTime = new DateTime(items[0], DateTimeZone.forID("UTC")).getMillis();
                map.put("timestamp", dateTime);
                for (int j = 1; j < items.length; j++) {
                    double value = Double.valueOf(items[j]);
                    map.put(subscriberConfig.getAttributes()[j], value);
                }
                builder.add(new LinkedHashMap(map));
            }
        }

        return builder.build();
    } catch (IOException e) {
        log.error("Unable to read file: " + subscriberConfig.getFilePath());
        return null;
    }
}

From source file:net.sasasin.sreader.batch.SingleAccountFeedReader.java

public void run() {
    logger.info(this.getClass().getSimpleName() + " is started.");

    File path = new File(System.getProperty("user.home") + File.separatorChar + "sreader.txt");

    if (!path.exists() || !path.isFile() || !path.canRead()) {
        System.out.println("FAIL;" + path.getPath() + " can not proc.");
        return;/* w w  w .j  a v  a  2 s.c  om*/
    }

    List<String> lines = null;
    try {
        lines = IOUtils.readLines(new FileReader(path));
    } catch (IOException e) {
        e.printStackTrace();
        return;
    }

    // import path to feed_url table.
    importSubscribe(lines);

    logger.info(this.getClass().getSimpleName() + " is ended.");
}

From source file:com.taobao.tanggong.handler.FileLoader.java

public void init() throws TangException {

    this.dataDirectory = new File(this.serverConfiguration.getBaseDirectory(), this.getWorkingDirectory());
    if (!dataDirectory.exists()) {
        //failed to create directory or not exist
        if (!this.dataDirectory.mkdirs() && !this.dataDirectory.exists()) {
            this.dataDirectory = null;
        }//from  w w  w .j  a  v  a 2s  . c  o m
    }

    File dataFile = new File(this.dataDirectory, this.getFilename());
    if (dataFile.exists()) {

        try {
            List<String> lines = IOUtils.readLines(new FileInputStream(dataFile));
            initLines(lines);
        } catch (FileNotFoundException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }

    }

}

From source file:ee.ria.xroad.proxy.testsuite.testcases.ServerProxyHttpError.java

@Override
public AbstractHandler getServerProxyHandler() {
    return new AbstractHandler() {
        @Override//w  ww  .  j  a  v  a  2 s .  c o  m
        public void handle(String target, Request baseRequest, HttpServletRequest request,
                HttpServletResponse response) throws IOException {
            // Read all of the request.
            IOUtils.readLines(request.getInputStream());

            response.sendError(HttpServletResponse.SC_BAD_GATEWAY);
            baseRequest.setHandled(true);
        }
    };
}

From source file:com.streamsets.pipeline.stage.common.TestUtil.java

public static void assertStringRecords(AmazonS3 s3client, String bucket, String prefix) throws IOException {
    //check that prefix contains 1 file
    ObjectListing objectListing = s3client.listObjects(bucket, prefix);
    Assert.assertEquals(1, objectListing.getObjectSummaries().size());

    for (S3ObjectSummary objectSummary : objectListing.getObjectSummaries()) {
        Assert.assertTrue(objectSummary.getKey().endsWith(".txt"));
    }/* ww w  .  ja  va2s . c o m*/

    S3ObjectSummary objectSummary = objectListing.getObjectSummaries().get(0);

    //get contents of file and check data - should have 9 lines
    S3Object object = s3client.getObject(bucket, objectSummary.getKey());
    S3ObjectInputStream objectContent = object.getObjectContent();

    List<String> stringList = IOUtils.readLines(objectContent);
    Assert.assertEquals(9, stringList.size());
    for (int i = 0; i < 9; i++) {
        Assert.assertEquals("\"" + TestUtil.TEST_STRING + i + "\"", stringList.get(i));
    }
}

From source file:io.selendroid.server.model.impl.DefaultHardwareDeviceFinder.java

List<String> listDevices() throws AndroidDeviceException {
    String output = null;//  ww  w.ja  v  a2  s  .c  om
    try {
        output = ShellCommand.exec(Arrays.asList(new String[] { AndroidSdk.adb(), "devices", "-l" }));
    } catch (ShellCommandException e) {
        throw new AndroidDeviceException("Error occured while searching for devices.", e);
    }
    List<String> lines = null;
    try {
        lines = IOUtils.readLines(new StringReader(output));
    } catch (IOException e) {
        throw new AndroidDeviceException("Error occured while reading devices list.", e);
    }
    return lines;
}

From source file:ml.shifu.shifu.core.dvarsel.wrapper.ValidationConductorTest.java

@Test
public void testRunValidate() throws IOException {
    ModelConfig modelConfig = CommonUtils.loadModelConfig(
            "src/test/resources/example/cancer-judgement/ModelStore/ModelSet1/ModelConfig.json",
            RawSourceData.SourceType.LOCAL);
    List<ColumnConfig> columnConfigList = CommonUtils.loadColumnConfigList(
            "src/test/resources/example/cancer-judgement/ModelStore/ModelSet1/ColumnConfig.json",
            RawSourceData.SourceType.LOCAL);

    List<Integer> columnIdList = new ArrayList<Integer>();
    boolean hasCandidates = CommonUtils.hasCandidateColumns(columnConfigList);
    for (ColumnConfig columnConfig : columnConfigList) {
        if (columnConfig.isCandidate(hasCandidates)) {
            columnIdList.add(columnConfig.getColumnNum());
        }// w w  w. j ava  2s.com
    }

    TrainingDataSet trainingDataSet = new TrainingDataSet(columnIdList);
    List<String> recordsList = IOUtils.readLines(
            new FileInputStream("src/test/resources/example/cancer-judgement/DataStore/DataSet1/part-00"));
    for (String record : recordsList) {
        addRecordIntoTrainDataSet(modelConfig, columnConfigList, trainingDataSet, record);
    }

    Set<Integer> workingList = new HashSet<Integer>();
    for (Integer columnId : trainingDataSet.getDataColumnIdList()) {
        workingList.clear();
        workingList.add(columnId);
        ValidationConductor conductor = new ValidationConductor(modelConfig, columnConfigList, workingList,
                trainingDataSet);

        double error = conductor.runValidate();
        System.out.println("The error is - " + error + ", for columnId - " + columnId);
    }
}