Created
June 11, 2010 10:46
-
-
Save rewbs/434349 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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