Possible patch some leaks

This commit is contained in:
George Kalampokis 2021-09-27 18:14:21 +03:00
parent 06364873ca
commit 99e4d231c2
3 changed files with 9 additions and 5 deletions

View File

@ -22,6 +22,7 @@ public class LocalFetcher {
JAXBContext context = JAXBContext.newInstance(Config.class);
Unmarshaller unmarshaller = context.createUnmarshaller();
Config config = (Config) unmarshaller.unmarshal(is);
is.close();
ConfigSingle currencyConfig = config.getConfigs().stream().filter(configSingle -> configSingle.getType().equals("currency")).findFirst().get();
return retrieveData(currencyConfig);
@ -39,7 +40,7 @@ public class LocalFetcher {
Unmarshaller unmarshaller = context.createUnmarshaller();
Object object = unmarshaller.unmarshal(is);
is.close();
Method reader = null;
if (configSingle.getParseField() != null && !configSingle.getParseField().isEmpty()) {
reader = new PropertyDescriptor(configSingle.getParseField(), aClass).getReadMethod();

View File

@ -86,6 +86,7 @@ public class MailServiceImpl implements MailService {
InputStream inputStream = resource.getInputStream();
StringWriter writer = new StringWriter();
IOUtils.copy(inputStream, writer, "UTF-8");
inputStream.close();
return writer.toString();
} catch (IOException e) {
logger.error(e.getMessage(), e);

View File

@ -1,17 +1,16 @@
package eu.eudat.models.rda.mapper;
import com.fasterxml.jackson.databind.ObjectMapper;
import eu.eudat.models.rda.Language;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.nio.charset.StandardCharsets;
import java.util.HashMap;
import java.util.Map;
import java.util.Objects;
import java.util.stream.Collectors;
public class LanguageRDAMapper {
private final static Map<String, Object> langMap = new HashMap<>();
@ -20,9 +19,12 @@ public class LanguageRDAMapper {
static {
String json = null;
try {
json = new BufferedReader(new InputStreamReader(LanguageRDAMapper.class.getClassLoader().getResource("internal/rda-lang-map.json").openStream(), StandardCharsets.UTF_8))
.lines().collect(Collectors.joining("\n"));
ObjectMapper mapper = new ObjectMapper();
InputStreamReader isr = new InputStreamReader(LanguageRDAMapper.class.getClassLoader().getResource("internal/rda-lang-map.json").openStream(), StandardCharsets.UTF_8);
json = mapper.readValue(isr, String.class);
isr.close();
langMap.putAll(new org.json.JSONObject(json).toMap());
} catch (IOException e) {
logger.error(e.getMessage(), e);
}