[brailleblaster] Re: byte arrays versus strings

  • From: Chris von See <chris@xxxxxxxxxxxxx>
  • To: brailleblaster@xxxxxxxxxxxxx
  • Date: Fri, 10 Dec 2010 11:17:32 -0800

Maybe I'm not understanding your question...

Any classes derived from java.io.InputStream and java.io.OutputStream are by definition byte-oriented streams:

http://download.oracle.com/javase/tutorial/essential/io/bytestreams.html

so if you are using the objects returned from Process.getInputStream() and Process.getOutputStream() you are required to write bytes, not Java characters, to the stream.

Character streams, by contrast, are derived from java.io.Reader and java.io.Writer:

http://download.oracle.com/javase/tutorial/essential/io/charstreams.html

and allow you to read and write Java characters and String objects.

You can convert a character-oriented reader/writer to a byte-oriented stream using java.io.InputStreamReader and java.io.OutputStreamWriter, which allow you to specify the encoding of the byte stream to be written. Any characters read from or written to those classes are automatically converted from/to bytes using the encoding you specify, or the default encoding if you don't specify one.


Cheers
Chris

On Dec 10, 2010, at 10:20 AM, John J. Boyer wrote:

Laura,

I am no exxpert, but I think the input, output and error streems should
be character streams. This will handle most stuff and will be easily
usable by Java. Graphics would have to be handled differently, but I
think we should wait until we have a need to handle them with C
libraries. They will require separate clases.

I haven't looked much at the Process class, though I have looked at
Runtime to find out how to call file2brl in a subcommand. I'm afraid we
will be learning together.

John

On Fri, Dec 10, 2010 at 11:54:04AM -0600, qubit wrote:
JohnB --
I understand what you are saying -- but there's still a sticking point.
The input, output, and error streams are declared as InputStream and
OutputStream's, which are general streams that could take either byte arrays (for binary or general data) or character streams, which I understand can be put in a String class. I am unsure what exactly the getInputStream(), getOutputStream() and getErrorStream() are returning as there are subclasses to class InputStream and OutputStream that cater to both kinds of data. I am wondering if there is a way to query the type of subclass of a class of
an object.  That would solve it.
Anyway, There might be uses of my class that want to do some kind of
operation on a general data file. For example, is there ever a graphic or other binary data embedded in what I would be sending through the program
that would be spit back out on the output stream?

This is just a matter of understanding java from the ters online docs. I could resort to one of the books I guess. But I think the online docs
should be enough.
--le






----- Original Message -----
From: "John J. Boyer" <john.boyer@xxxxxxxxxxxxxxxxx>
To: <brailleblaster@xxxxxxxxxxxxx>
Sent: Friday, December 10, 2010 1:29 AM
Subject: [brailleblaster] Re: byte arrays versus strings


Laura,

As I see it, your code should be written for generality, so it can be
used to calll other command-line filters. The input and output streams
should therefore be strings.

Another part of your code might take a stream containing a MathML
fragment and convert it to a JDOM subtree. This code might be useful in
other parts of BrailleBlaster, so it should  also be generalized.

Hope this helps,
John B.

On Thu, Dec 09, 2010 at 07:25:06PM -0600, qubit wrote:
Ok, this is where I need JohnB's expertise with characters and byte
strings.
Of course, anyone else can chime in too.

I have a buffered stream going from brailleblaster to the input of process just spawned, and 2 streams coming back for standard error and standard
out.

I will be managing the pipes in a class constructor / finalizer.
My question is, in the docs for the input and output streams in java.io, there are subclasses that manage byte arrays and subclasses that do just
character strings.
My class will provide you with a read and a write method. Should I just assume that everything that goes over the pipe is a character stream, or
are
there cases where I can't assume that?

Should this be a character stream or a byte stream?
Should I use threads that handle the input and output on these streams?

I am trying to get all my "ducks in a row" as a family member likes to
say.
Any comments are welcome.
--le


--
John J. Boyer; President, Chief Software Developer
Abilitiessoft, Inc.
http://www.abilitiessoft.com
Madison, Wisconsin USA
Developing software for people with disabilities



--
John J. Boyer; President, Chief Software Developer
Abilitiessoft, Inc.
http://www.abilitiessoft.com
Madison, Wisconsin USA
Developing software for people with disabilities




Other related posts: