1
0
Fork 0
mirror of https://github.com/M66B/FairEmail.git synced 2024-12-29 11:15:51 +00:00

Read message file as stream

This commit is contained in:
M66B 2019-07-06 13:02:32 +02:00
parent 7630a6edcb
commit 9341b166ba
2 changed files with 11 additions and 15 deletions

View file

@ -67,7 +67,7 @@ import com.sun.mail.iap.ConnectionException;
import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.BufferedWriter;
import java.io.DataInputStream;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
@ -510,12 +510,17 @@ public class Helper {
}
}
static String readStream(InputStream is, String charset) throws IOException {
ByteArrayOutputStream os = new ByteArrayOutputStream();
byte[] buffer = new byte[16384];
for (int len = is.read(buffer); len != -1; len = is.read(buffer))
os.write(buffer, 0, len);
return new String(os.toByteArray(), charset);
}
static String readText(File file) throws IOException {
try (FileInputStream in = new FileInputStream(file)) {
byte[] buffer = new byte[(int) file.length()];
DataInputStream dis = new DataInputStream(in);
dis.readFully(buffer);
return new String(buffer);
return readStream(in, "UTF-8");
}
}

View file

@ -29,7 +29,6 @@ import com.sun.mail.util.MessageRemovedIOException;
import java.io.BufferedOutputStream;
import java.io.BufferedReader;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileOutputStream;
import java.io.FileReader;
@ -801,7 +800,7 @@ public class MessageHelper {
result = (String) content;
else if (content instanceof InputStream)
// Typically com.sun.mail.util.QPDecoderStream
result = readStream((InputStream) content, "UTF-8");
result = Helper.readStream((InputStream) content, "UTF-8");
else
result = content.toString();
} catch (IOException | FolderClosedException | MessageRemovedException ex) {
@ -1112,14 +1111,6 @@ public class MessageHelper {
}
}
private static String readStream(InputStream is, String charset) throws IOException {
ByteArrayOutputStream os = new ByteArrayOutputStream();
byte[] buffer = new byte[4096];
for (int len = is.read(buffer); len != -1; len = is.read(buffer))
os.write(buffer, 0, len);
return new String(os.toByteArray(), charset);
}
static boolean equal(Address[] a1, Address[] a2) {
if (a1 == null && a2 == null)
return true;