noisebrain wrote:

> Hello,
>
> (forgive me since this is mostly off topic, though the answer
> might possibly be specific to the operating system.)
>
> I want to write a little java app to copy a url and its relative links.
> The url itself is a text html file; some of the links may be binary
> files such as .jpg, .ps.gz, etc.
>
> My question: can you copy a binary file such as a .jpg using a *Reader,
> rather than a Stream?  Each byte will then be represented with
> a 16bit char, but will writing with a corresponding Writer preserve the
> data?

If you're going to be reasonably clever about this copy, there are a
couple of reasonable things to do here:

1) Use streams everywhere - don't count on what Reader/Writer may or may
not do to data that doesn't represent a known text encoding. If you need
to interpret the data as text (such as reading html and interpreting the
links), you can pump it through another pipeline that will apply the
appropriate text encoding. That pipeline might, for example, consist of a
piped stream feeding an InputStreamReader.

2) Don't ignore the header fields of the HTTP objects you retrieve. Except
for ancient or strange Web servers, they'll contain a Content-Type field
that will tell you whether or not the object is text/http.

These recommendations should apply across all platforms (which makes this
one of those dreaded, generic, off-topic questions :-).

Nathan


>
>
> Generally the top-level url should be read using a Reader,
> but I believe it will be difficult to tell if the links are binary
> or html without reading them (and even then... some html does not
> start with the <html> tag.  Thus, the easy/general way to do it would
> be to just open every file with a Reader, thus my question.
>
> Any other approaches?
>
> Thanks.
>
> ----------------------------------------------------------------------
> To UNSUBSCRIBE, email to [EMAIL PROTECTED]
> with a subject of "unsubscribe". Trouble? Contact [EMAIL PROTECTED]


----------------------------------------------------------------------
To UNSUBSCRIBE, email to [EMAIL PROTECTED]
with a subject of "unsubscribe". Trouble? Contact [EMAIL PROTECTED]

Reply via email to