Jim LaGrone <[email protected]> wrote on 08/10/2009 05:42:30 PM:
> I'm trying to read and write to binary files. I don't see a method for
> writing or reading Rails or Arrays of anything but bytes.
>
> Can someone please verify this?
> Are there methods for dealing with this that I may not have seen yet?
>
>
> I'm also having a problem with writing/reading values to/from binary
> files.
> For instance, if I write 0, 2, 4, ..., 18 as shorts to a file and
> examine using Unix od -X I get:
>
> tests$ od -x x10RailsFile.bin
> 0000000 0000 0200 0400 0600 0800 0a00 0c00
> 0e00
> 0000020 1000 1200
> 0000024
>
>
> Can you tell me the byte order X10 is using to produce the file? It
> looks like big-endian (MSB). However, I'm trying to read a file that
> is stored LSB.
>
> Can someone verify this?
> Any suggestions for reading binary files?
Hi, Jim,
Unfortunately, there is no API documentation available yet for the X10
standard libraries. This means that your best bet is to look at the
source.
You can browse the sources in the SVN repository (use the appropriate
tags for the current releases, or the x10-1.7 branch for the upcoming
one), or, if you downloaded a particular release of X10, you can also
look inside lib/x10.jar for the library sources.
There is a read[T](Marshal[T], Rail[T]) method in x10.io.Reader which
reads a Rail[T] for any T. You can use the constants in the Marshal
class as the first argument to this method.
There are no methods yet to read arrays. A partial implementation of
some is commented out in Reader.x10 -- if you can make it work, great.
We do plan to have some Array I/O APIs, but there is no timeframe for
that.
Shorts are written to and read from files (actually, streams) using
Marshal.SHORT. According to the implementation, both happen in
big-endian fashion (MSB first). If you wish to read an LSB file,
provide your own Marshal[Short] implementation that does it. You can
simply copy the code of Marshal.ShortMarshal and reverse the order of
bytes. Pass it into the read[T]() method, and you should be set.
Arguably, we should probably provide a version of the read[T]()
method that uses the default Marshal for certain data types... If
you feel that supplying the Marshal[T] explicitly is undue burden,
please open a JIRA.
On a final note, there are likely limitations to the Marshal API
(e.g., I can't easily see how to write a Marshal to read a bit
vector into a Rail[Boolean]). Suggestions for improvements of that
design are always welcome (preferably in JIRA), and will definitely
be discussed and considered.
Igor
--
Igor Peshansky (note the spelling change!)
IBM T.J. Watson Research Center
XJ: No More Pain for XML's Gain (http://www.research.ibm.com/xj/)
X10: Parallel Productivity and Performance (http://x10.sf.net/)
------------------------------------------------------------------------------
Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day
trial. Simplify your report design, integration and deployment - and focus on
what you do best, core application coding. Discover what's new with
Crystal Reports now. http://p.sf.net/sfu/bobj-july
_______________________________________________
X10-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/x10-users