aboutsummaryrefslogtreecommitdiff
path: root/juick-crosspost
diff options
context:
space:
mode:
Diffstat (limited to 'juick-crosspost')
-rw-r--r--juick-crosspost/src/main/java/com/juick/components/Crosspost.java28
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++) {