diff options
author | Vitaly Takmazov | 2016-11-23 12:40:44 +0300 |
---|---|---|
committer | Vitaly Takmazov | 2016-11-23 12:40:44 +0300 |
commit | 78a1a68e5555648a07588873b08d59a094391709 (patch) | |
tree | 615df80d629beb93bfa73ac98023b43e53746deb | |
parent | 42718787291bed507caf4f7ae13f6c41f9b8d7ff (diff) |
streamToString -> IOUtils.toString
-rw-r--r-- | juick-crosspost/src/main/java/com/juick/components/Crosspost.java | 28 |
1 files changed, 8 insertions, 20 deletions
diff --git a/juick-crosspost/src/main/java/com/juick/components/Crosspost.java b/juick-crosspost/src/main/java/com/juick/components/Crosspost.java index 5dc86f27..fb6dd7d5 100644 --- a/juick-crosspost/src/main/java/com/juick/components/Crosspost.java +++ b/juick-crosspost/src/main/java/com/juick/components/Crosspost.java @@ -18,7 +18,10 @@ package com.juick.components; import com.juick.service.CrosspostService; +import org.apache.commons.codec.Charsets; import org.apache.commons.codec.binary.Base64; +import org.apache.commons.io.IOUtils; +import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.math.NumberUtils; import org.apache.commons.lang3.tuple.Pair; import org.slf4j.Logger; @@ -36,7 +39,8 @@ import javax.annotation.PostConstruct; import javax.crypto.Mac; import javax.crypto.spec.SecretKeySpec; import javax.net.ssl.HttpsURLConnection; -import java.io.*; +import java.io.OutputStreamWriter; +import java.io.UnsupportedEncodingException; import java.net.URL; import java.net.URLEncoder; import java.security.Key; @@ -151,7 +155,7 @@ public class Crosspost implements AutoCloseable { wr.write(body); wr.close(); - ret = streamToString(conn.getInputStream()) != null; + ret = StringUtils.isNotEmpty(IOUtils.toString(conn.getInputStream(), Charsets.UTF_8)); conn.disconnect(); } catch (Exception e) { @@ -188,7 +192,7 @@ public class Crosspost implements AutoCloseable { wr.write(body); wr.close(); - ret = streamToString(conn.getInputStream()) != null; + ret = StringUtils.isNotEmpty(IOUtils.toString(conn.getInputStream(), Charsets.UTF_8)); conn.disconnect(); } catch (Exception e) { @@ -243,7 +247,7 @@ public class Crosspost implements AutoCloseable { wr.write("status=" + status); wr.close(); - ret = streamToString(conn.getInputStream()) != null; + ret = IOUtils.toString(conn.getInputStream(), Charsets.UTF_8) != null; conn.disconnect(); } catch (Exception e) { @@ -278,22 +282,6 @@ public class Crosspost implements AutoCloseable { return null; } - public String streamToString(final InputStream is) { - try { - BufferedReader buf = new BufferedReader(new InputStreamReader(is)); - StringBuilder str = new StringBuilder(); - String line; - do { - line = buf.readLine(); - str.append(line).append("\n"); - } while (line != null); - return str.toString(); - } catch (Exception e) { - logger.error("streamToString: " + e.getMessage(), e); - } - return null; - } - public String getMessageHashTags(final com.juick.Message jmsg) { String hashtags = ""; for (int i = 0; i < jmsg.getTags().size(); i++) { |