Simplification

This commit is contained in:
M66B 2021-01-20 20:00:44 +01:00
parent 0e8c016713
commit 3d2cb49610
4 changed files with 10 additions and 7 deletions

View File

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

View File

@ -104,6 +104,7 @@ import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.UnsupportedEncodingException;
import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets;
import java.security.MessageDigest;
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()));
byte[] buffer = new byte[BUFFER_SIZE];
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 {
try (FileInputStream in = new FileInputStream(file)) {
return readStream(in, StandardCharsets.UTF_8.name());
return readStream(in);
}
}

View File

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

View File

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