Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?

Re^2: passing data structures from java to perl

by almut (Canon)
on Jul 28, 2010 at 20:15 UTC ( #851788=note: print w/replies, xml ) Need Help??

in reply to Re: passing data structures from java to perl
in thread passing data structures from java to perl

It should be no real problem to have Java create UTF-8 encoded files/streams (both JSON and XML), and JSON can read UTF-8 data just fine... (Similarly for XML)

  • Comment on Re^2: passing data structures from java to perl

Replies are listed 'Best First'.
Re^3: passing data structures from java to perl
by exussum0 (Vicar) on Jul 28, 2010 at 20:27 UTC
    Agreed. As long as no UTF-16 chars are used, which is really easy to do in java since strings are all UTF-16, it's all gravy.

    Java strings are UTF-16

    A good XML writer that prevents you from going outside of the declared format will protect you from future mistakes. Down side is the extra effort in using some XML api over others. JSON is usually gravy in all languages.

    Gravy.. mmmm...

      Java strings are UTF-16

      The way strings are stored internally doesn't really matter.

      While Perl stores unicode strings internally as UTF-8 (or something very close to it), it can encode those strings to many other encodings for output.  The same holds for Java: while it stores strings internally as UTF-16, there's no problem creating UTF-8 output, for example.

      Writer utf8out = new BufferedWriter( new OutputStreamWriter( new FileOutputStream("outfile"), "UTF-8" ) ); utf8out.write("some unicode data");
        That's really really bad advice. You can get encoding errors like that on the java side. Yeah, the bytes in memory are all that matter and you're fine to interpret, but on the way in and out, you're playing with things.

        It's the same thing like binmode. You're affecting the data as the IO occurs to get into our out of memory. See...

        I've run into this exact problem using the XML feeds for perlmonks while working in java.

          A reply falls below the community's threshold of quality. You may see it by logging in.

        Just an OT question ... do all these writers in writers in writers look as crazy to you as they do to me? I mean I have no experience with Java (nor do I want any), but it seems IO in Java is just as overcomplicated as in C#/.Net. There probably is a reason that I, being OO unclean, do not see, but still. Looks like someone went heavily overboard when designing the libraries.

        Enoch was right!
        Enjoy the last years of Rome.

Log In?

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://851788]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (2)
As of 2023-06-04 11:06 GMT
Find Nodes?
    Voting Booth?
    How often do you go to conferences?

    Results (20 votes). Check out past polls.