dev@fi.java.net

Re: Encoding algorithms

From: Santiago Pericas-Geertsen <Santiago.Pericasgeertsen_at_Sun.COM>
Date: Thu, 10 Feb 2005 08:50:02 -0500

On Feb 9, 2005, at 11:47 AM, Paul Sandoz wrote:

> Alan Hudson wrote:
>>> I think i already need to make one modification to the encodeToBytes
>>> method. It is not possible to obtain how many bytes have been
>>> written.
>> Does this method follow standard java rules of not reallocating of
>> the array is big enough?
>
> Yes.

  If it does not reallocate the array, why can't it return the number of
bytes written as an int?

>> Instead of a wrapper class, how about a getNumberBytesWritten to get
>> the last number of bytes?
>>
>
> But then it would not necessarily be thread safe.

  If by thread safe you mean sharing the same instance across threads,
this is an implementation issue, I'm not sure how this relates to the
interface. I.e., even without this method you can still have an
implementation that is not thread safe. In fact, I think requiring
thread safety in EncodingAlgorithmImpl's is probably not a good idea,
it is usually better to do synchronization externally.

  I believe you're concern is ensuring that, if thread safety is
required, then the encoding and the getter methods can be synchronized
in such a way that they return consistent results, which I believe is
doable using the concurrency API (instead of the more limited block
synchronization mechanism).

-- Santiago