Search in sources :

Example 86 with SneakyThrows

use of lombok.SneakyThrows in project rxlib by RockyLOMO.

the class App method readSettings.

@SneakyThrows
public static Map<String, Object> readSettings(String yamlFile, boolean isResource) {
    Map<String, Object> result = null;
    Yaml yaml = new Yaml(new SafeConstructor());
    for (Object data : yaml.loadAll(isResource ? getClassLoader().getResourceAsStream(yamlFile) : new FileInputStream(yamlFile))) {
        Map<String, Object> map = (Map<String, Object>) data;
        if (result == null) {
            result = map;
            continue;
        }
        result.putAll(map);
    }
    if (result == null) {
        result = new HashMap<>();
    }
    return result;
}
Also used : SafeConstructor(org.yaml.snakeyaml.constructor.SafeConstructor) Yaml(org.yaml.snakeyaml.Yaml) SneakyThrows(lombok.SneakyThrows)

Example 87 with SneakyThrows

use of lombok.SneakyThrows in project rxlib by RockyLOMO.

the class App method downloadFile.

@SneakyThrows
public static void downloadFile(HttpServletResponse response, String filePath) {
    require(response, filePath);
    switch(filePath) {
        case "info":
        case "error":
            filePath = String.format("%s/logs/%s", System.getProperty("catalina.home"), filePath);
    }
    File file = new File(filePath);
    response.setCharacterEncoding(Const.Utf8);
    response.setContentType("application/octet-stream");
    response.setContentLength((int) file.length());
    response.setHeader("Content-Disposition", String.format("attachment; filename=\"%s\"", file.getName()));
    try (FileInputStream in = new FileInputStream(file)) {
        OutputStream out = response.getOutputStream();
        byte[] buffer = new byte[4096];
        int length;
        while ((length = in.read(buffer)) > 0) {
            out.write(buffer, 0, length);
        }
        out.flush();
    }
}
Also used : JarFile(java.util.jar.JarFile) SneakyThrows(lombok.SneakyThrows)

Example 88 with SneakyThrows

use of lombok.SneakyThrows in project rxlib by RockyLOMO.

the class Tester method testJson.

@Test
@SneakyThrows
public void testJson() {
    URL e = App.getClassLoader().getResource("jsonMapper/");
    System.out.println(e);
    for (Path path : App.fileStream(Paths.get(e.toURI()))) {
        System.out.println(path);
        Map<String, Object> map = App.readSettings(path.toString(), false);
        for (Map.Entry<String, Object> entry : map.entrySet()) {
            System.out.println(entry.getKey() + ": " + entry.getValue());
        }
    }
// Object p = new TestServletRequest();
// System.out.println(Contract.toJsonString(p));
// 
// ErrorBean eb = new ErrorBean();
// System.out.println(Contract.toJsonString(eb));
// 
// System.out.println(Contract.toJsonString(eb));
}
Also used : Path(java.nio.file.Path) Map(java.util.Map) URL(java.net.URL) Test(org.junit.Test) SneakyThrows(lombok.SneakyThrows)

Example 89 with SneakyThrows

use of lombok.SneakyThrows in project rxlib by RockyLOMO.

the class JsonMapper method refreshSettings.

@SneakyThrows
private Map<String, Object> refreshSettings(String configPath) {
    URL path = App.getClassLoader().getResource(configPath);
    if (path == null) {
        return Collections.emptyMap();
    }
    Map<String, Object> map = new HashMap<>();
    for (Path p : App.fileStream(Paths.get(path.toURI()))) {
        try {
            map.putAll(App.readSettings(p.toString(), false));
        } catch (Exception e) {
            log.error("refreshSettings", e);
        }
    }
    return map;
}
Also used : Path(java.nio.file.Path) HashMap(java.util.HashMap) V8Object(com.eclipsesource.v8.V8Object) JSONObject(com.alibaba.fastjson.JSONObject) URL(java.net.URL) URISyntaxException(java.net.URISyntaxException) SneakyThrows(lombok.SneakyThrows)

Example 90 with SneakyThrows

use of lombok.SneakyThrows in project selenium_java by sergueik.

the class DefaultId3vTagManager method fix.

@SneakyThrows
@Override
public File fix(File source) {
    Mp3File mp3File = new Mp3File(source);
    mp3File.removeCustomTag();
    if (mp3File.hasId3v1Tag()) {
        ID3v1 tag = mp3File.getId3v1Tag();
        tag.setArtist(fixString(tag.getArtist()));
        tag.setTitle(fixString(tag.getTitle()));
        tag.setAlbum(fixString(tag.getAlbum()));
        tag.setComment(fixString(tag.getComment()));
        mp3File.setId3v1Tag(tag);
    }
    if (mp3File.hasId3v2Tag()) {
        ID3v2 tag = mp3File.getId3v2Tag();
        tag.setArtist(fixString(tag.getArtist()));
        tag.setTitle(fixString(tag.getTitle()));
        tag.setAlbum(fixString(tag.getAlbum()));
        tag.setComment(fixString(tag.getComment()));
        mp3File.setId3v2Tag(tag);
    }
    String filename = source.toString() + "_fixed.mp3";
    try {
        mp3File.save(filename);
    } catch (NotSupportedException e) {
        mp3File.removeId3v2Tag();
        mp3File.save(filename);
    }
    return new File(filename);
}
Also used : ID3v2(com.mpatric.mp3agic.ID3v2) Mp3File(com.mpatric.mp3agic.Mp3File) ID3v1(com.mpatric.mp3agic.ID3v1) NotSupportedException(com.mpatric.mp3agic.NotSupportedException) Mp3File(com.mpatric.mp3agic.Mp3File) File(java.io.File) SneakyThrows(lombok.SneakyThrows)

Aggregations

SneakyThrows (lombok.SneakyThrows)706 lombok.val (lombok.val)314 Test (org.junit.Test)91 ArrayList (java.util.ArrayList)75 HashMap (java.util.HashMap)63 List (java.util.List)53 Cleanup (lombok.Cleanup)38 Map (java.util.Map)35 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)34 Collectors (java.util.stream.Collectors)34 LinkedHashMap (java.util.LinkedHashMap)30 File (java.io.File)28 Path (java.nio.file.Path)28 IOException (java.io.IOException)26 InputStream (java.io.InputStream)24 Slf4j (lombok.extern.slf4j.Slf4j)24 URL (java.net.URL)22 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)22 Collection (java.util.Collection)18 FishingActivityQuery (eu.europa.ec.fisheries.ers.service.search.FishingActivityQuery)17