Simplification

pull/193/head
M66B 4 years ago
parent 0e8c016713
commit 3d2cb49610

@ -32,7 +32,6 @@ import org.json.JSONObject;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.net.URL; import java.net.URL;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Date; import java.util.Date;
import java.util.HashMap; import java.util.HashMap;
@ -120,7 +119,7 @@ public class DisconnectBlacklist {
connection.connect(); connection.connect();
try { try {
String response = Helper.readStream(connection.getInputStream(), StandardCharsets.UTF_8.name()); String response = Helper.readStream(connection.getInputStream());
Helper.writeText(file, response); Helper.writeText(file, response);
} finally { } finally {
connection.disconnect(); connection.disconnect();

@ -104,6 +104,7 @@ import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.io.OutputStream; import java.io.OutputStream;
import java.io.UnsupportedEncodingException; import java.io.UnsupportedEncodingException;
import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets; import java.nio.charset.StandardCharsets;
import java.security.MessageDigest; import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException; import java.security.NoSuchAlgorithmException;
@ -1139,7 +1140,11 @@ public class Helper {
} }
} }
static String readStream(InputStream is, String charset) throws IOException { static String readStream(InputStream is) throws IOException {
return readStream(is, StandardCharsets.UTF_8);
}
static String readStream(InputStream is, Charset charset) throws IOException {
ByteArrayOutputStream os = new ByteArrayOutputStream(Math.max(BUFFER_SIZE, is.available())); ByteArrayOutputStream os = new ByteArrayOutputStream(Math.max(BUFFER_SIZE, is.available()));
byte[] buffer = new byte[BUFFER_SIZE]; byte[] buffer = new byte[BUFFER_SIZE];
for (int len = is.read(buffer); len != -1; len = is.read(buffer)) for (int len = is.read(buffer); len != -1; len = is.read(buffer))
@ -1149,7 +1154,7 @@ public class Helper {
static String readText(File file) throws IOException { static String readText(File file) throws IOException {
try (FileInputStream in = new FileInputStream(file)) { try (FileInputStream in = new FileInputStream(file)) {
return readStream(in, StandardCharsets.UTF_8.name()); return readStream(in);
} }
} }

@ -31,7 +31,6 @@ import java.io.IOException;
import java.net.InetAddress; import java.net.InetAddress;
import java.net.URL; import java.net.URL;
import java.net.UnknownHostException; import java.net.UnknownHostException;
import java.nio.charset.StandardCharsets;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
@ -79,7 +78,7 @@ public class IPInfo {
Organization organization = new Organization(); Organization organization = new Organization();
try { try {
String response = Helper.readStream(connection.getInputStream(), StandardCharsets.UTF_8.name()); String response = Helper.readStream(connection.getInputStream());
organization.name = response.trim(); organization.name = response.trim();
if ("".equals(organization.name) || "undefined".equals(organization.name)) if ("".equals(organization.name) || "undefined".equals(organization.name))
organization.name = null; organization.name = null;

@ -1748,7 +1748,7 @@ public class MessageHelper {
result = (String) content; result = (String) content;
else if (content instanceof InputStream) else if (content instanceof InputStream)
// Typically com.sun.mail.util.QPDecoderStream // Typically com.sun.mail.util.QPDecoderStream
result = Helper.readStream((InputStream) content, StandardCharsets.UTF_8.name()); result = Helper.readStream((InputStream) content);
else else
result = content.toString(); result = content.toString();
} catch (IOException | FolderClosedException | MessageRemovedException ex) { } catch (IOException | FolderClosedException | MessageRemovedException ex) {

Loading…
Cancel
Save