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

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

Introduction

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

Prototype

public static FileInputStream openInputStream(File file) throws IOException 

Source Link

Document

Opens a FileInputStream for the specified file, providing better error messages than simply calling new FileInputStream(file).

Usage

From source file:org.sonar.server.computation.batch.BatchReportReaderImpl.java

@Override
public CloseableIterator<BatchReport.Test> readTests(int testFileRef) {
    File file = delegate.readTests(testFileRef);
    if (file == null) {
        return CloseableIterator.emptyCloseableIterator();
    }/*from  w  ww . jav  a 2s .  c  o  m*/

    try {
        return new ParserCloseableIterator<>(BatchReport.Test.parser(), FileUtils.openInputStream(file));
    } catch (IOException e) {
        Throwables.propagate(e);
        // actually never reached
        return CloseableIterator.emptyCloseableIterator();
    }
}

From source file:org.sonar.server.computation.batch.BatchReportReaderImpl.java

@Override
public CloseableIterator<BatchReport.CoverageDetail> readCoverageDetails(int testFileRef) {
    File file = delegate.readCoverageDetails(testFileRef);
    if (file == null) {
        return CloseableIterator.emptyCloseableIterator();
    }/*from   w  ww.j  ava 2 s. c om*/

    try {
        return new ParserCloseableIterator<>(BatchReport.CoverageDetail.parser(),
                FileUtils.openInputStream(file));
    } catch (IOException e) {
        Throwables.propagate(e);
        // actually never reached
        return CloseableIterator.emptyCloseableIterator();
    }
}

From source file:org.sonar.server.computation.source.ReportIterator.java

public ReportIterator(File file, Parser<E> parser) {
    try {//from www.j a v a 2 s. c om
        this.parser = parser;
        this.stream = FileUtils.openInputStream(file);
    } catch (IOException e) {
        throw Throwables.propagate(e);
    }
}

From source file:org.sonar.server.computation.task.projectanalysis.batch.BatchReportReaderImpl.java

@Override
public CloseableIterator<String> readScannerLogs() {
    ensureInitialized();// w ww .  ja va 2s .  c om
    File file = delegate.getFileStructure().analysisLog();
    if (!file.exists()) {
        return CloseableIterator.emptyCloseableIterator();
    }
    try {
        InputStreamReader reader = new InputStreamReader(FileUtils.openInputStream(file),
                StandardCharsets.UTF_8);
        return new LineReaderIterator(reader);
    } catch (IOException e) {
        throw new IllegalStateException("Fail to open file " + file, e);
    }
}

From source file:org.sonar.server.computation.task.projectanalysis.batch.BatchReportReaderImpl.java

@Override
public Optional<CloseableIterator<String>> readFileSource(int fileRef) {
    ensureInitialized();//from w  ww . ja v  a 2 s .  co  m
    File file = delegate.readFileSource(fileRef);
    if (file == null) {
        return Optional.absent();
    }

    try {
        return Optional.of(new CloseableLineIterator(
                IOUtils.lineIterator(FileUtils.openInputStream(file), StandardCharsets.UTF_8)));
    } catch (IOException e) {
        throw new IllegalStateException("Fail to traverse file: " + file, e);
    }
}

From source file:org.sonar.server.computation.task.projectanalysis.batch.BatchReportReaderImpl.java

@Override
public CloseableIterator<ScannerReport.Test> readTests(int testFileRef) {
    ensureInitialized();//from www .j a va 2  s .c om
    File file = delegate.readTests(testFileRef);
    if (file == null) {
        return CloseableIterator.emptyCloseableIterator();
    }

    try {
        return new ParserCloseableIterator<>(ScannerReport.Test.parser(), FileUtils.openInputStream(file));
    } catch (IOException e) {
        Throwables.propagate(e);
        // actually never reached
        return CloseableIterator.emptyCloseableIterator();
    }
}

From source file:org.sonar.server.computation.task.projectanalysis.batch.BatchReportReaderImpl.java

@Override
public CloseableIterator<ScannerReport.CoverageDetail> readCoverageDetails(int testFileRef) {
    ensureInitialized();//  ww w. ja  v a2s  .  c o m
    File file = delegate.readCoverageDetails(testFileRef);
    if (file == null) {
        return CloseableIterator.emptyCloseableIterator();
    }

    try {
        return new ParserCloseableIterator<>(ScannerReport.CoverageDetail.parser(),
                FileUtils.openInputStream(file));
    } catch (IOException e) {
        Throwables.propagate(e);
        // actually never reached
        return CloseableIterator.emptyCloseableIterator();
    }
}

From source file:org.sonar.server.computation.task.projectanalysis.step.ExtractReportStepTest.java

@Test
public void unzip_report() throws Exception {
    File reportFile = generateReport();
    try (InputStream input = FileUtils.openInputStream(reportFile)) {
        dbTester.getDbClient().ceTaskInputDao().insert(dbTester.getSession(), TASK_UUID, input);
    }/*w w w.ja  va2s . co m*/
    dbTester.getSession().commit();
    dbTester.getSession().close();

    underTest.execute();

    // directory contains the uncompressed report (which contains only metadata.pb in this test)
    File unzippedDir = reportDirectoryHolder.getDirectory();
    assertThat(unzippedDir).isDirectory().exists();
    assertThat(unzippedDir.listFiles()).hasSize(1);
    assertThat(new File(unzippedDir, "metadata.pb")).hasContent("{metadata}");
}

From source file:org.sonar.server.qualityprofile.QProfileCopier.java

private void restore(DbSession dbSession, File backupFile, QualityProfileDto profile) {
    try (Reader reader = new InputStreamReader(FileUtils.openInputStream(backupFile), UTF_8)) {
        backuper.restore(dbSession, reader, profile);
    } catch (IOException e) {
        throw new IllegalStateException("Fail to create temporary backup file: " + backupFile, e);
    }//w w w  .  j  a va 2 s.c  om
}

From source file:org.sonar.server.util.cache.DiskCache.java

public CloseableIterator<O> traverse() {
    try {/*from   ww  w .  j  a  v a2  s  .  c  om*/
        return new ObjectInputStreamIterator<>(FileUtils.openInputStream(file));
    } catch (IOException e) {
        throw new IllegalStateException("Fail to traverse file: " + file, e);
    }
}