Message5864

Author rdesgroppes
Recipients fwierzbicki, pekka.klarck, pjenvey, rdesgroppes, yanne
Date 2010-06-30.16:00:14
SpamBayes Score 0.020814344
Marked as misclassified No
Message-id <1277913616.19.0.606439342823.issue1568@psf.upfronthosting.co.za>
In-reply-to
Content
Yes, Philip, you're right: we could steal that information via reflection. Here using Jython:
---
from java.lang import System

def get_encoding(console):
    """returns encoding of this console
    <!> untested if console is null (i.e. when not attached to a tty)
    <!> might fail if a security manager is set without "suppressAccessChecks"
    """
    encoding_method = console.getClass().getDeclaredMethod("encoding", None)
    encoding_method.setAccessible(True)
    return encoding_method.invoke(console, None)

def get_charset(console):
    """returns charset of this console
    <!> untested if console is null (i.e. when not attached to a tty)
    <!> might fail if a security manager is set without "suppressAccessChecks"
    """
    charset_field = console.getClass().getDeclaredField("cs")
    charset_field.setAccessible(True)
    return charset_field.get(console)

if __name__ == "__main__":
    print "java.io.Console's encoding:", get_encoding(System.console())
     # cp437 (string)

    print "java.io.Console's charset:", get_charset(System.console())
     # IBM437 (java.nio.charset.Charset object)
---
Regards,
Regis
History
Date User Action Args
2010-06-30 16:00:16rdesgroppessetmessageid: <1277913616.19.0.606439342823.issue1568@psf.upfronthosting.co.za>
2010-06-30 16:00:16rdesgroppessetrecipients: + rdesgroppes, fwierzbicki, pekka.klarck, pjenvey, yanne
2010-06-30 16:00:16rdesgroppeslinkissue1568 messages
2010-06-30 16:00:14rdesgroppescreate