SusiMail: Fix up commented-out test so it works

(if you uncomment it)
This commit is contained in:
zzz
2021-04-24 17:09:40 -04:00
parent 78168be85c
commit f753728d8a

View File

@@ -107,23 +107,30 @@ public class DecodingOutputStream extends OutputStream {
try { try {
String s = "Consider the encoding of the Euro sign, €." + String s = "Consider the encoding of the Euro sign, €." +
" The Unicode code point for \"€\" is U+20AC."; " The Unicode code point for \"€\" is U+20AC.";
StringBuilder buf = new StringBuilder();
for (int i = 0; i < 100; i++) {
buf.append(s);
}
s = buf.toString();
byte[] test = s.getBytes("UTF-8"); byte[] test = s.getBytes("UTF-8");
InputStream bais = new java.io.ByteArrayInputStream(test); java.io.InputStream bais = new java.io.ByteArrayInputStream(test);
DecodingOutputStream r = new DecodingOutputStream(bais); Writer w = new StringBuilderWriter();
DecodingOutputStream r = new DecodingOutputStream(w, "UTF-8");
int b; int b;
StringBuilder buf = new StringBuilder(128); while ((b = bais.read()) >= 0) {
while ((b = r.write()) >= 0) { r.write(b);
buf.append((char) b);
} }
System.out.println("Received: " + buf); r.flush();
System.out.println("Test passed? " + buf.toString().equals(s)); System.out.println("Received: \"" + w.toString() + '"');
buf.setLength(0); System.out.println("Test passed? " + w.toString().equals(s));
bais = new java.io.ByteArrayInputStream(new byte[] { 'x', (byte) 0xcc, 'x' } ); bais = new java.io.ByteArrayInputStream(new byte[] { 'x', (byte) 0xcc, 'x' } );
r = new DecodingOutputStream(bais); w = new StringBuilderWriter();
while ((b = r.write()) >= 0) { r = new DecodingOutputStream(w, "UTF-8");
buf.append((char) b); while ((b = bais.read()) >= 0) {
r.write(b);
} }
System.out.println("Received: " + buf); r.flush();
System.out.println("Received: \"" + w.toString() + '"');
} catch (IOException ioe) { } catch (IOException ioe) {
ioe.printStackTrace(); ioe.printStackTrace();
} }