How to construct maximal char sequence using some Charset

Hi, all!Presume I have some Charset object and I know that being encoded any String should not exceed N bytes.How can I get the greatest string (in terms of Comparable interface) that fits in given N bytes?Thanks in advance.
[259 byte] By [jutea] at [2007-11-26 23:35:57]
# 1
In general you can't. Consider UTF-8. Each character encodes as 1,2,3 or 4 bytes! Of course, any fixed length encoding (e.g. ISO-8859-1)is trivial to deal with.
sabre150a at 2007-7-11 14:58:04 > top of Java-index,Java Essentials,Java Programming...
# 2

> In general you can't. Consider UTF-8. Each character

> encodes as 1,2,3 or 4 bytes!

>

> Of course, any fixed length encoding (e.g.

> ISO-8859-1)is trivial to deal with.

I think, it is not trivial. At first, I don't know, what the charset is. It is trivial if I know that it will always be particular charset, e.g. US-ASCII. For US-ASCII I know, that all characters is one-byte encoded, the first is 0x00 and the last is 0x7F. But if I have not that data, I can only request the average and the maximum bytes per char, and using CharacterEncoder I can test 65536 characters - whether they could be encoded or not.

Message was edited by:

jute

jutea at 2007-7-11 14:58:04 > top of Java-index,Java Essentials,Java Programming...