comp.lang.ada
 help / color / mirror / Atom feed
From: Nick Roberts <nick.roberts@acm.org>
Subject: Re: Ada streams
Date: Wed, 15 Dec 2004 17:26:23 +0000
Date: 2004-12-15T17:26:23+00:00	[thread overview]
Message-ID: <32baduF3gtbllU1@individual.net> (raw)
In-Reply-To: <cpoq0o$vuk$1@sunce.iskon.hr>

Daniel Vencler wrote:

> Hi, I want to ask you where I can get good explanation what are and
> how to use (and when) ada streams. There are a few ada tutorials on 
> the net but not single one of them mentions streams.

To answer the question of when to use streams, the brief answer is: in
almost any situation where you are not using text I/O (using the
package Ada.[Wide_]Text_IO and its children), and a few besides.

Consider a variety of different file types in common use today: the
JPEG pictorial image format; the PKWare ZIP compression format; the
Microsoft word processor DOC format; the HTML (HyperText Markup
Language) format used for web pages. For the HTML format, you may wish
to use Ada.Text_IO, but for some rather esoteric (and unfortunate)
technical reasons, you might want to use Ada.Streams.Stream_IO. For
all the others, you will certainly want to use Ada.Streams.Stream_IO.

Similarly, streams will be used to perform packet-based network
communications, and possibly some other kinds of communications. A
package will provide a stream into which you write data into a packet
(it's payload), prior to sending the packet, as well as a stream to
read the (payload) data out of a packet when it is received. A device
driver (interface) package for a printer, say, may well provide a
stream into which you write the data to be sent to the printer.

There are certain rare situations in which you might want to streams
for a purpose other than I/O, for example a memory buffer.

Section 11.12 of the Big Online Book of Linux Ada Programming, as
pointed to by another replier, seems to give quite a good introduction
into how to use streams.

Maybe I should say a quick word on what a stream is. In practice, a
stream is a sequence of bytes -- which are called 'octets' formally --
which comprise the binary representation of one or a sequence of
variable values. The values can be of any type. The bytes do not
normally encode the type (they do if you use the Output procedure on a
tagged type) of each value, nor do they encode what the sequence of
values was (if there was more than one value). You simply have to know
these things to read the values back again correctly. The binary
representation of each type will depend on the target machine, and is
in any case implementation specific. These means that, unless you take
special precautions, you must use the same compiler and target machine
to read a file as you used to write the file in the first place.

Ada.Streams.Stream_IO can be used to read binary files in a standard
format (such as JPEG, ZIP, or DOC), provided you know the exact
details of the formats of all the data types in the format, and use
representation clauses or other methods to read those data types
correctly.

I hope this is helpful. I think you'll have to ask more specific
questions to get more detailed answers.

-- 
Nick Roberts



  parent reply	other threads:[~2004-12-15 17:26 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2004-12-15  7:43 Ada streams Daniel Vencler
2004-12-15 13:41 ` John B. Matthews
2004-12-15 17:26 ` Nick Roberts [this message]
2004-12-15 19:35   ` tmoran
2004-12-15 19:26 ` David C. Hoos
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox