Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Archived » Memory Analyzer (MAT) » Save value to file: support specific encoding
Save value to file: support specific encoding [message #9289] Wed, 04 March 2009 19:44 Go to next message
Taras Tielkes is currently offline Taras Tielkes
Messages: 38
Registered: July 2009
Member
By default (I think?) the encoding is UTF-16, which is not exactly a
common one.

It would be nice if MAT would allow me to specify the encoding (even
ASCII). Of course, if the content contains characters not supported by
some specific encoding, it should report an error and abort.

-tt
Re: Save value to file: support specific encoding [message #9381 is a reply to message #9289] Tue, 10 March 2009 09:51 Go to previous messageGo to next message
Andreas Buchen is currently offline Andreas Buchen
Messages: 113
Registered: July 2009
Senior Member
Hi Taras,

currently the logic is this (I think you mean the Save to File context
menu?):

* if only one object is selected, write the data in such a way that one
can read it via the DataInputStream (e.g. is it written as is via
DataOutputStream).

* if more than one object is selected, the string representation of the
objects is written to the text file. The output file uses the system
encoding: System.getProperty("file.encoding") Do you want a choice of
encodings here? It would only change what you need to tell your text
editor how to load the file.

Could it be that you have a byte array that contains text and we do not
convert that properly? For byte arrays we do this:

if (val >= 32 && val < 127)
result.append(val);
else
result.append("\\u").append(String.format("%04x", 0xFFFF & val));




Andreas.
Re: Save value to file: support specific encoding [message #9428 is a reply to message #9381] Tue, 10 March 2009 20:23 Go to previous messageGo to next message
Taras Tielkes is currently offline Taras Tielkes
Messages: 38
Registered: July 2009
Member
Hi Andreas,

I'm saving the value of one single java.lang.String instance to a file.
Right now, the generated file uses a UTF-16 encoding, for which support
in 'common' programs/tools is kind of spotty.

I'd like to have at ASCII or UTF-8 as options:
1) UTF-8 is pretty well-supported in most editors/tools
2) ASCII is universally supported of course

In the case of ASCII, it's possible that the String instance contains
non-ASCII characters. If this is the case, I'd like MAT to notify me,
and abort.

So, in summary, my use case applies to strings only, and the main
motivator is the relatively spotty support for UTF-16.

-tt

P.S. Any chance for a new release sometime soon? :-)

Andreas Buchen wrote:
> Hi Taras,
>
> currently the logic is this (I think you mean the Save to File context
> menu?):
>
> * if only one object is selected, write the data in such a way that one
> can read it via the DataInputStream (e.g. is it written as is via
> DataOutputStream).
>
> * if more than one object is selected, the string representation of the
> objects is written to the text file. The output file uses the system
> encoding: System.getProperty("file.encoding") Do you want a choice of
> encodings here? It would only change what you need to tell your text
> editor how to load the file.
>
> Could it be that you have a byte array that contains text and we do not
> convert that properly? For byte arrays we do this:
>
> if (val >= 32 && val < 127)
> result.append(val);
> else
> result.append("\\u").append(String.format("%04x", 0xFFFF & val));
>
>
>
>
> Andreas.
>
>
Re: Save value to file: support specific encoding [message #9477 is a reply to message #9428] Thu, 12 March 2009 18:03 Go to previous messageGo to next message
Andreas Buchen is currently offline Andreas Buchen
Messages: 113
Registered: July 2009
Senior Member
> I'm saving the value of one single java.lang.String instance to a file.
> Right now, the generated file uses a UTF-16 encoding, for which support
> in 'common' programs/tools is kind of spotty.

The output encoding is chosen by the default coding of your platform. You
should be able to change this by adding another options:

-Dfile.encoding=UTF-8

If you add the ASCII encoding, you should get an exception.

I just say:
... new OutputStreamWriter(out, System.getProperty("file.encoding"))

But indeed I can add an option so that one can change the encoding easier
than that.


Andreas.
Re: Save value to file: support specific encoding [message #9567 is a reply to message #9477] Thu, 12 March 2009 23:59 Go to previous message
Taras Tielkes is currently offline Taras Tielkes
Messages: 38
Registered: July 2009
Member
Hi Andreas,

That should provide me with a good-enough workaround for now.
I'd suggest to wait from someone else to request this as well, before
putting any effort in implementing it.

Thanks,
-tt
Previous Topic:Query on Heap Dump
Next Topic:can not get heap dump on win32 ?
Goto Forum:
  


Current Time: Wed Sep 17 21:57:38 GMT 2014

Powered by FUDForum. Page generated in 0.11073 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software