Added try-with-resources.
This commit is contained in:
parent
94871a4df8
commit
70d99a028d
2 changed files with 18 additions and 15 deletions
|
@ -81,17 +81,19 @@ public class FeedReader implements Runnable {
|
||||||
public final void run() {
|
public final void run() {
|
||||||
try {
|
try {
|
||||||
final SyndFeedInput input = new SyndFeedInput();
|
final SyndFeedInput input = new SyndFeedInput();
|
||||||
final SyndFeed feed = input.build(new XmlReader(new URL(url)));
|
try (final XmlReader reader = new XmlReader(new URL(url))) {
|
||||||
|
final SyndFeed feed = input.build(reader);
|
||||||
|
|
||||||
final List<SyndEntry> items = feed.getEntries();
|
final List<SyndEntry> items = feed.getEntries();
|
||||||
if (items.isEmpty()) {
|
if (items.isEmpty()) {
|
||||||
bot.send(sender, "There is currently nothing to view.", false);
|
bot.send(sender, "There is currently nothing to view.", false);
|
||||||
} else {
|
} else {
|
||||||
SyndEntry item;
|
SyndEntry item;
|
||||||
for (int i = 0; (i < items.size()) && (i < MAX_ITEMS); i++) {
|
for (int i = 0; (i < items.size()) && (i < MAX_ITEMS); i++) {
|
||||||
item = items.get(i);
|
item = items.get(i);
|
||||||
bot.send(sender, item.getTitle(), false);
|
bot.send(sender, item.getTitle(), false);
|
||||||
bot.send(sender, Utils.helpIndent(Utils.green(item.getLink()), false), false);
|
bot.send(sender, Utils.helpIndent(Utils.green(item.getLink()), false), false);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (MalformedURLException e) {
|
} catch (MalformedURLException e) {
|
||||||
|
|
|
@ -90,7 +90,7 @@ final class TellMessagesMgr {
|
||||||
public static List<TellMessage> load(final String file, final Logger logger) {
|
public static List<TellMessage> load(final String file, final Logger logger) {
|
||||||
try {
|
try {
|
||||||
try (final ObjectInput input = new ObjectInputStream(
|
try (final ObjectInput input = new ObjectInputStream(
|
||||||
new BufferedInputStream(Files.newInputStream(Paths.get(file))))) {
|
new BufferedInputStream(Files.newInputStream(Paths.get(file))))) {
|
||||||
logger.debug("Loading the messages.");
|
logger.debug("Loading the messages.");
|
||||||
|
|
||||||
return ((List<TellMessage>) input.readObject());
|
return ((List<TellMessage>) input.readObject());
|
||||||
|
@ -113,10 +113,11 @@ final class TellMessagesMgr {
|
||||||
*/
|
*/
|
||||||
public static void save(final String file, final List<TellMessage> messages, final Logger logger) {
|
public static void save(final String file, final List<TellMessage> messages, final Logger logger) {
|
||||||
try {
|
try {
|
||||||
try (final ObjectOutput output = new ObjectOutputStream(
|
try (final BufferedOutputStream bos = new BufferedOutputStream(Files.newOutputStream(Paths.get(file)))) {
|
||||||
new BufferedOutputStream(Files.newOutputStream(Paths.get(file))))) {
|
try (final ObjectOutput output = new ObjectOutputStream(bos)) {
|
||||||
logger.debug("Saving the messages.");
|
logger.debug("Saving the messages.");
|
||||||
output.writeObject(messages);
|
output.writeObject(messages);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
logger.error("Unable to save messages queue.", e);
|
logger.error("Unable to save messages queue.", e);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue