Search in sources :

Example 26 with BaseFileReader

use of com.tvd12.properties.file.reader.BaseFileReader in project properties-file by tvd12.

the class PropertiesFileReaderTest method getInputStreamByAbsolutePathTest.

@Test
public void getInputStreamByAbsolutePathTest() {
    Method method = MethodBuilder.create().clazz(InputStreamUtil.class).method("getInputStreamByAbsolutePath").argument(File.class).build();
    ReflectMethodUtil.invokeMethod(method, new BaseFileReader(), new File(getClass().getResource("/invalid.properties").getFile()));
    ReflectMethodUtil.invokeMethod(method, new BaseFileReader(), new ExFile("abc"));
}
Also used : BaseFileReader(com.tvd12.properties.file.reader.BaseFileReader) InputStreamUtil(com.tvd12.properties.file.util.InputStreamUtil) Method(java.lang.reflect.Method) File(java.io.File) Test(org.testng.annotations.Test) BaseTest(com.tvd12.test.base.BaseTest)

Example 27 with BaseFileReader

use of com.tvd12.properties.file.reader.BaseFileReader in project ezyhttp by youngmonkeys.

the class MessageReader method read.

public Map<String, Properties> read(String folderPath) {
    List<MessagesFile> files = getMessagesFiles(folderPath);
    Map<String, Properties> answer = new HashMap<>();
    FileReader fileReader = new BaseFileReader();
    for (MessagesFile file : files) {
        Properties properties = file.resourceFile.isInJar() ? fileReader.read(file.resourceFile.getRelativePath()) : fileReader.read(new File(file.resourceFile.getFullPath()));
        answer.computeIfAbsent(file.language, k -> new Properties()).putAll(properties);
        answer.computeIfAbsent(file.language.toLowerCase(), k -> new Properties()).putAll(properties);
    }
    return answer;
}
Also used : BaseFileReader(com.tvd12.properties.file.reader.BaseFileReader) List(java.util.List) Properties(java.util.Properties) BaseFileReader(com.tvd12.properties.file.reader.BaseFileReader) Map(java.util.Map) ResourceLoader(com.tvd12.ezyhttp.server.core.resources.ResourceLoader) HashMap(java.util.HashMap) EzyFileUtil.getFileName(com.tvd12.ezyfox.util.EzyFileUtil.getFileName) ResourceFile(com.tvd12.ezyhttp.server.core.resources.ResourceFile) AllArgsConstructor(lombok.AllArgsConstructor) Collectors(java.util.stream.Collectors) File(java.io.File) FileReader(com.tvd12.properties.file.reader.FileReader) HashMap(java.util.HashMap) BaseFileReader(com.tvd12.properties.file.reader.BaseFileReader) FileReader(com.tvd12.properties.file.reader.FileReader) Properties(java.util.Properties) ResourceFile(com.tvd12.ezyhttp.server.core.resources.ResourceFile) File(java.io.File)

Example 28 with BaseFileReader

use of com.tvd12.properties.file.reader.BaseFileReader in project ezyfox-examples by tvd12.

the class PropertiesFile method main.

public static void main(String[] args) {
    Properties properties = new MultiFileReader().read("application.properties");
    System.out.println("properties: " + properties);
    Properties propertiesAlpha = new MultiFileReader("alpha").read("application.properties");
    System.out.println("properties alpha: " + propertiesAlpha);
    ApplicationConfig applicationConfig = new PropertiesMapper().reader(new MultiFileReader("alpha")).file("application.properties").map(ApplicationConfig.class);
    System.out.println("applicationConfig alpha: " + applicationConfig);
    Properties yamlProperties = new BaseFileReader().read("application.yaml");
    System.out.println("yaml properties: " + yamlProperties);
    Properties yamlPropertiesAlpha = new MultiFileReader("alpha").read("application.yaml");
    System.out.println("yaml properties alpha: " + yamlPropertiesAlpha);
    ApplicationConfig applicationConfigYaml = new PropertiesMapper().reader(new MultiFileReader("alpha")).file("application.yaml").map(ApplicationConfig.class);
    System.out.println("applicationConfigYaml alpha: " + applicationConfigYaml);
}
Also used : BaseFileReader(com.tvd12.properties.file.reader.BaseFileReader) PropertiesMapper(com.tvd12.properties.file.mapping.PropertiesMapper) Properties(java.util.Properties) MultiFileReader(com.tvd12.properties.file.reader.MultiFileReader)

Aggregations

BaseFileReader (com.tvd12.properties.file.reader.BaseFileReader)28 Test (org.testng.annotations.Test)26 Properties (java.util.Properties)8 BaseTest (com.tvd12.test.base.BaseTest)6 File (java.io.File)5 HashMap (java.util.HashMap)5 InputStreamUtil (com.tvd12.properties.file.util.InputStreamUtil)2 InputStream (java.io.InputStream)2 Method (java.lang.reflect.Method)2 EzyFileUtil.getFileName (com.tvd12.ezyfox.util.EzyFileUtil.getFileName)1 ResourceFile (com.tvd12.ezyhttp.server.core.resources.ResourceFile)1 ResourceLoader (com.tvd12.ezyhttp.server.core.resources.ResourceLoader)1 PropertiesMapper (com.tvd12.properties.file.mapping.PropertiesMapper)1 FileReader (com.tvd12.properties.file.reader.FileReader)1 MultiFileReader (com.tvd12.properties.file.reader.MultiFileReader)1 List (java.util.List)1 Map (java.util.Map)1 Collectors (java.util.stream.Collectors)1 AllArgsConstructor (lombok.AllArgsConstructor)1