Read message file as stream

pull/157/head
M66B 5 years ago
parent 7630a6edcb
commit 9341b166ba

@ -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");
}
}

@ -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;

Loading…
Cancel
Save