From dce503bbd66b7cb22b0894dad27930d081a46093 Mon Sep 17 00:00:00 2001 From: mishako Date: Wed, 23 Dec 2015 21:03:46 +0100 Subject: [PATCH] Fix small code problems --- .../java/com/rometools/rome/io/WireFeedInput.java | 11 +++++++---- .../java/com/rometools/rome/io/WireFeedOutput.java | 7 +++++-- src/main/java/com/rometools/rome/io/XmlReader.java | 2 +- .../com/rometools/rome/io/impl/Atom03Generator.java | 4 ++-- 4 files changed, 15 insertions(+), 9 deletions(-) diff --git a/src/main/java/com/rometools/rome/io/WireFeedInput.java b/src/main/java/com/rometools/rome/io/WireFeedInput.java index 3f88be1..4d69ac3 100644 --- a/src/main/java/com/rometools/rome/io/WireFeedInput.java +++ b/src/main/java/com/rometools/rome/io/WireFeedInput.java @@ -204,11 +204,14 @@ public class WireFeedInput { public WireFeed build(final File file) throws FileNotFoundException, IOException, IllegalArgumentException, FeedException { WireFeed feed; Reader reader = new FileReader(file); - if (xmlHealerOn) { - reader = new XmlFixerReader(reader); + try { + if (xmlHealerOn) { + reader = new XmlFixerReader(reader); + } + feed = this.build(reader); + } finally { + reader.close(); } - feed = this.build(reader); - reader.close(); return feed; } diff --git a/src/main/java/com/rometools/rome/io/WireFeedOutput.java b/src/main/java/com/rometools/rome/io/WireFeedOutput.java index 0096c24..34ba85f 100644 --- a/src/main/java/com/rometools/rome/io/WireFeedOutput.java +++ b/src/main/java/com/rometools/rome/io/WireFeedOutput.java @@ -185,8 +185,11 @@ public class WireFeedOutput { */ public void output(final WireFeed feed, final File file, final boolean prettyPrint) throws IllegalArgumentException, IOException, FeedException { final Writer writer = new FileWriter(file); - this.output(feed, writer, prettyPrint); - writer.close(); + try { + this.output(feed, writer, prettyPrint); + } finally { + writer.close(); + } } /** diff --git a/src/main/java/com/rometools/rome/io/XmlReader.java b/src/main/java/com/rometools/rome/io/XmlReader.java index 511aa1f..5942efc 100644 --- a/src/main/java/com/rometools/rome/io/XmlReader.java +++ b/src/main/java/com/rometools/rome/io/XmlReader.java @@ -518,7 +518,7 @@ public class XmlReader extends Reader { private String calculateHttpEncoding(final String cTMime, final String cTEnc, final String bomEnc, final String xmlGuessEnc, final String xmlEnc, final InputStream is, final boolean lenient) throws IOException { String encoding; - if (lenient & xmlEnc != null) { + if (lenient && xmlEnc != null) { encoding = xmlEnc; } else { final boolean appXml = isAppXml(cTMime); diff --git a/src/main/java/com/rometools/rome/io/impl/Atom03Generator.java b/src/main/java/com/rometools/rome/io/impl/Atom03Generator.java index b41c06d..57a508d 100644 --- a/src/main/java/com/rometools/rome/io/impl/Atom03Generator.java +++ b/src/main/java/com/rometools/rome/io/impl/Atom03Generator.java @@ -283,7 +283,7 @@ public class Atom03Generator extends BaseWireFeedGenerator { final String rel = link.getRel(); if (rel != null) { - final Attribute relAttribute = new Attribute("rel", rel.toString()); + final Attribute relAttribute = new Attribute("rel", rel); linkElement.setAttribute(relAttribute); } @@ -351,7 +351,7 @@ public class Atom03Generator extends BaseWireFeedGenerator { final String mode = content.getMode(); if (mode != null) { - final Attribute modeAttribute = new Attribute("mode", mode.toString()); + final Attribute modeAttribute = new Attribute("mode", mode); contentElement.setAttribute(modeAttribute); }