Skip to content

Instantly share code, notes, and snippets.

@rewbs
Created June 11, 2010 10:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rewbs/434349 to your computer and use it in GitHub Desktop.
Save rewbs/434349 to your computer and use it in GitHub Desktop.
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