Here is the simple checking code. As always, if you have something better to share, please use comments.
public static boolean canEncode(String s, String cs)
{
try
{
ByteArrayOutputStream baos = new ByteArrayOutputStream();
Writer w = new OutputStreamWriter(baos, cs);
w.write(s);
w.close();
String t = baos.toString(cs);
return s.equals(t);
}
catch(Exception e)
{
return false;
}
}
{
try
{
ByteArrayOutputStream baos = new ByteArrayOutputStream();
Writer w = new OutputStreamWriter(baos, cs);
w.write(s);
w.close();
String t = baos.toString(cs);
return s.equals(t);
}
catch(Exception e)
{
return false;
}
}
No comments:
Post a Comment