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;
}
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();
}
}
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));
}
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;
}
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);
}
Aggregations