use of com.tvd12.properties.file.exception.PropertiesFileException in project properties-file by tvd12.
the class PropertiesFileReaderTest method loadInputStreamTest.
@SuppressWarnings("unchecked")
@Test(expectedExceptions = { PropertiesFileException.class })
public void loadInputStreamTest() throws PropertiesFileException, IOException {
InputStream stream = mock(InputStream.class);
when(stream.read()).thenThrow(IOException.class);
new BaseFileReader().loadInputStream(stream);
}
use of com.tvd12.properties.file.exception.PropertiesFileException in project properties-file by tvd12.
the class PropertiesFileReaderTest method testWithValidData2.
@Test
public void testWithValidData2() throws PropertiesFileException {
File file = new File(getClass().getClassLoader().getResource("classes.properties").getFile());
assertNotNull(new BaseFileReader().read(Lists.newArrayList(file, file)));
assertNotNull(new BaseFileReader().read(Lists.newArrayList(file, file)));
}
use of com.tvd12.properties.file.exception.PropertiesFileException in project properties-file by tvd12.
the class PropertiesFileWriterTest method test.
@Test
public void test() throws PropertiesFileException {
Properties properties = new Properties();
properties.setProperty("hello", "word");
new BaseFileWriter().write(properties, "hello.output_test");
}
use of com.tvd12.properties.file.exception.PropertiesFileException in project properties-file by tvd12.
the class MultiFileReader method read.
private Properties read(ClassLoader classLoader, String filePath, Set<String> passedFilePaths) {
List<String> filePaths = new ArrayList<>();
filePaths.add(filePath);
for (String profile : includeProfiles) {
filePaths.add(getFileClasspathByProfile(filePath, profile));
}
filePaths.removeAll(passedFilePaths);
Properties properties = new Properties();
for (String fp : filePaths) {
if (passedFilePaths.contains(fp)) {
continue;
}
Properties prop;
try {
prop = super.read(classLoader, fp);
} catch (PropertiesFileException e) {
continue;
}
passedFilePaths.add(fp);
properties.putAll(prop);
String profilesString = prop.getProperty(Constants.PROFILES_KEY);
List<String> profiles = getIncludeProfiles(profilesString);
if (profiles.size() > 0) {
properties.putAll(new MultiFileReader(profiles).read(classLoader, filePath, passedFilePaths));
}
}
return properties;
}
use of com.tvd12.properties.file.exception.PropertiesFileException in project properties-file by tvd12.
the class PropertiesInputStreamReader method readInputStream.
@Override
public Properties readInputStream(InputStream inputStream) {
Properties properties = new Properties();
try {
byte[] contentBytes = InputStreamUtil.toByteArray(inputStream);
ByteArrayInputStream stream = new ByteArrayInputStream(contentBytes);
try {
properties.load(stream);
} finally {
stream.close();
inputStream.close();
}
} catch (IOException e) {
throw new PropertiesFileException("Can not read properties file", e);
}
return properties;
}
Aggregations