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:io.milton.httpclient.NotifyingFileInputStream.java

public NotifyingFileInputStream(File f, ProgressListener listener) throws FileNotFoundException, IOException {
    this.fin = FileUtils.openInputStream(f);
    this.wrapped = new BufferedInputStream(fin);
    this.listener = listener;
    this.totalLength = f.length();
    this.fileName = f.getAbsolutePath();
    this.timeLastNotify = System.currentTimeMillis();
}

From source file:de.tudarmstadt.ukp.dkpro.spelling.experiments.hoo2012.lab.report.HOO2012ResultsReport.java

@Override
public void execute() throws Exception {
    int i = 0;//www  .  j  a v a  2  s . c  o m
    for (TaskContextMetadata subcontext : getSubtasks()) {
        File folder = getContext().getStorageService().getStorageFolder(subcontext.getId(),
                HOO2012Experiments.OUTPUT_KEY);
        for (File resultFile : folder.listFiles()) {
            if (resultFile.isFile()) {
                InputStream is = FileUtils.openInputStream(resultFile);
                storeBinary(resultFile.getName() + i + ".txt", is);
            }
        }

        i++;
    }
}

From source file:eu.seaclouds.platform.dashboard.model.SeaCloudsApplicationDataStorageTest.java

@BeforeMethod
public void setUp() throws Exception {
    Yaml yamlParser = new Yaml();

    URL resource = Resources.getResource(TOSCA_DAM_FILE_PATH);
    Map toscaDamMap = (Map) yamlParser.load(FileUtils.openInputStream(new File(resource.getFile())));
    // Fill SeaCloudsApplicationDataStorage with empty applications with distinct SeaCloudsID
    for (int i = 0; i < INITIAL_DATASTORE_SIZE; i++) {
        dataStore.addSeaCloudsApplicationData(new SeaCloudsApplicationData(toscaDamMap));
    }// w  w w .  j av a 2  s .c om
}

From source file:com.sandstone_tech.lendfastselenium2.util.PoiFileReader.java

/**
 * Extracts the content of the excel file to be converted as
 * {@link TestDataModel} object usable by the data provider
 * /*  ww w .j  a  va 2 s  .  c o m*/
 * @param fileName
 * @return
 */
protected Object[][] readExcelFileAsTDM(String fileName) {

    try {
        XSSFWorkbook wb = new XSSFWorkbook(FileUtils.openInputStream(new File(fileName)));

        // CONFIGURATION
        //         XSSFSheet sheet = wb.getSheetAt(0);

        // DATA
        XSSFSheet dataSheet = wb.getSheetAt(1);

        if (dataSheet != null && dataSheet.getPhysicalNumberOfRows() > 1) {

            Object[][] testData = new Object[dataSheet.getPhysicalNumberOfRows() - 2][1];

            for (int rowCount = 2; rowCount < dataSheet.getPhysicalNumberOfRows(); rowCount++) {
                XSSFRow row = dataSheet.getRow(rowCount);
                TestDataModel testDataModel = new TestDataModel();

                testDataModel.setUsername(getStringValue(row.getCell(0)));
                testDataModel.setPassword(getStringValue(row.getCell(1)));
                testDataModel.setApplicationType(getStringValue(row.getCell(2)));

                testDataModel.setOrginationFormModel(this.getOrigination(row));
                testDataModel.setPersonalDetailsModel(this.getPersonalDetail(row));
                testDataModel.setSignedDeclaration(this.getSignedDeclaration(row));

                testDataModel.setCurrentAddress(this.getCurrentAddress(row));
                testDataModel.setEmploymentDetails(this.getEmploymentDetails(row));
                testDataModel.setPreviousEmploymentDetails(this.getPreviousEmploymentDetails(row));
                testDataModel.setPurchaseProperty(
                        new PurchaseProperty(this.getPropertyContract(row), this.getPropertyPurpose(row)));

                testData[rowCount - 2][0] = testDataModel;
            }

            wb.close();
            return testData;

        }

        wb.close();

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

    }

    return null;
}

From source file:com.github.tddts.jet.util.Util.java

/**
 * Save given property to given propeorty file.
 *
 * @param fileName property file path/*from  w  w  w.java  2 s . co m*/
 * @param key      property key
 * @param value    property value
 */
public static void saveProperty(String fileName, String key, String value) {
    try {
        File file = new File(fileName);
        if (!file.exists())
            file.createNewFile();
        Properties properties = new Properties();

        try (InputStream in = FileUtils.openInputStream(file)) {
            properties.load(in);
        }

        properties.setProperty(key, value);

        try (OutputStream out = FileUtils.openOutputStream(file)) {
            properties.store(out, "");
        }

    } catch (IOException e) {
        throw new ApplicationException(e);
    }
}

From source file:com.sangupta.jerry.store.PropertiesUserLocalStore.java

public PropertiesUserLocalStore(String folderName, String fileName) {
    super(folderName);

    if (AssertUtils.isEmpty(fileName)) {
        throw new IllegalArgumentException("Filename cannot be null/empty");
    }/*  w w  w.  j a  v a2 s.c  o  m*/

    this.propertiesFile = new File(this.dataDirectory, fileName);
    this.properties = new Properties();

    if (this.propertiesFile.exists() && this.propertiesFile.isFile()) {
        try {
            this.properties.load(FileUtils.openInputStream(this.propertiesFile));
        } catch (IOException e) {
            throw new RuntimeException("Unable to read from the data store", e);
        }
    }
}

From source file:io.druid.data.input.impl.prefetch.OpenedObject.java

OpenedObject(FetchedFile<T> fetchedFile) throws IOException {
    this(fetchedFile.getObject(), FileUtils.openInputStream(fetchedFile.getFile()),
            fetchedFile.getResourceCloser());
}

From source file:com.splunk.shuttl.archiver.filesystem.glacier.AWSCredentialsImpl.java

/**
 * @param properties/*from  w ww  . j a v  a2s. c  om*/
 *          file containing amazon properties for all the fields.
 */
public static AWSCredentialsImpl createWithPropertyFile(File amazonProperties) {
    try {
        Properties properties = new Properties();
        properties.load(FileUtils.openInputStream(amazonProperties));
        String id = properties.getProperty("aws.id");
        String secret = properties.getProperty("aws.secret");
        String bucket = properties.getProperty("s3.bucket");
        String vault = properties.getProperty("glacier.vault");
        String endpoint = properties.getProperty("glacier.endpoint");

        return new AWSCredentialsImpl(id, secret, endpoint, bucket, vault);
    } catch (IOException e) {
        throw new RuntimeException(e);
    }
}

From source file:gov.nih.nci.cacis.transform.SourceTransformerTest.java

@Before
public void init() throws URISyntaxException, IOException {

    sampleMessageIS = FileUtils.openInputStream(
            new File(getClass().getClassLoader().getResource("xsl2/sampleForXSLv2.xml").toURI()));
}

From source file:eu.seaclouds.platform.dashboard.model.SeaCloudsApplicationDataTest.java

@BeforeMethod
public void setUp() throws Exception {
    URL resource = Resources.getResource(TOSCA_DAM_FILE_PATH);
    toscaDamMap = (Map) new Yaml().load(FileUtils.openInputStream(new File(resource.getFile())));
}