Small improvement

This commit is contained in:
M66B 2024-01-24 11:02:41 +01:00
parent 8e91278ec9
commit 371b858a13
1 changed files with 14 additions and 8 deletions

View File

@ -59,7 +59,7 @@ public class text_plain extends handler_base {
try { try {
enc = getCharset(ds.getContentType()); enc = getCharset(ds.getContentType());
is = new InputStreamReader(ds.getInputStream(), enc); is = new InputStreamReader(ds.getInputStream(), enc);
} catch (IllegalArgumentException iex) { } catch (UnsupportedEncodingException | IllegalArgumentException iex) {
/* /*
* An unknown charset of the form ISO-XXX-XXX will cause * An unknown charset of the form ISO-XXX-XXX will cause
* the JDK to throw an IllegalArgumentException. The * the JDK to throw an IllegalArgumentException. The
@ -68,9 +68,12 @@ public class text_plain extends handler_base {
* and this results in an IllegalArgumentException, rather than * and this results in an IllegalArgumentException, rather than
* the expected UnsupportedEncodingException. Yikes. * the expected UnsupportedEncodingException. Yikes.
*/ */
//throw new UnsupportedEncodingException(enc); try {
is = new InputStreamReader(ds.getInputStream(), is = new InputStreamReader(ds.getInputStream(),
eu.faircode.email.UnknownCharsetProvider.charsetForMime(getCharset(ds.getContentType()))); eu.faircode.email.UnknownCharsetProvider.charsetForMime(getCharset(ds.getContentType())));
} catch (IllegalArgumentException ex) {
throw new UnsupportedEncodingException(enc);
}
} }
try { try {
@ -118,7 +121,7 @@ public class text_plain extends handler_base {
try { try {
enc = getCharset(type); enc = getCharset(type);
osw = new OutputStreamWriter(new NoCloseOutputStream(os), enc); osw = new OutputStreamWriter(new NoCloseOutputStream(os), enc);
} catch (IllegalArgumentException iex) { } catch (UnsupportedEncodingException | IllegalArgumentException iex) {
/* /*
* An unknown charset of the form ISO-XXX-XXX will cause * An unknown charset of the form ISO-XXX-XXX will cause
* the JDK to throw an IllegalArgumentException. The * the JDK to throw an IllegalArgumentException. The
@ -127,9 +130,12 @@ public class text_plain extends handler_base {
* and this results in an IllegalArgumentException, rather than * and this results in an IllegalArgumentException, rather than
* the expected UnsupportedEncodingException. Yikes. * the expected UnsupportedEncodingException. Yikes.
*/ */
//throw new UnsupportedEncodingException(enc); try {
osw = new OutputStreamWriter(new NoCloseOutputStream(os), osw = new OutputStreamWriter(new NoCloseOutputStream(os),
eu.faircode.email.UnknownCharsetProvider.charsetForMime(getCharset(type))); eu.faircode.email.UnknownCharsetProvider.charsetForMime(getCharset(type)));
} catch (IllegalArgumentException ex) {
throw new UnsupportedEncodingException(enc);
}
} }
String s = (String)obj; String s = (String)obj;