Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
import java.nio.charset.*
import java.nio.*
class ebcdic2 {
static main(args) {
Charset.metaClass.isEBCDIC = {
// This byte value of 'a' is the same in all EBCDIC flavours.
// We use can this to positively identify EBCDIC Charsets.
final ByteBuffer FIXED_EBCDIC_CODEPOINT = ByteBuffer.wrap("a".getBytes("IBM-1047"))
try {
return delegate.newDecoder()
.onMalformedInput(CodingErrorAction.REPLACE)
.onUnmappableCharacter(CodingErrorAction.REPLACE)
.decode(FIXED_EBCDIC_CODEPOINT).toString().equals("a")
} catch (Exception e) {
return false
}
}
println Charset
.availableCharsets()
.findAll { name, charset -> charset.isEBCDIC() }
.values()
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment