Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.java.programmer > #21513 > unrolled thread

StringBuilder for byte[]

Started byRoedy Green <see_website@mindprod.com.invalid>
First post2013-01-18 00:40 -0800
Last post2013-01-18 18:44 -0500
Articles 12 — 4 participants

Back to article view | Back to comp.lang.java.programmer


Contents

  StringBuilder for byte[] Roedy Green <see_website@mindprod.com.invalid> - 2013-01-18 00:40 -0800
    Re: StringBuilder for byte[] Sven Köhler <remove-sven.koehler@gmail.com> - 2013-01-18 12:15 +0100
      Re: StringBuilder for byte[] Lew <lewbloch@gmail.com> - 2013-01-18 08:54 -0800
        Re: StringBuilder for byte[] Sven Köhler <remove-sven.koehler@gmail.com> - 2013-01-18 18:08 +0100
        Re: StringBuilder for byte[] Arne Vajhøj <arne@vajhoej.dk> - 2013-01-18 18:42 -0500
          Re: StringBuilder for byte[] Lew <lewbloch@gmail.com> - 2013-01-18 17:07 -0800
            Re: StringBuilder for byte[] Arne Vajhøj <arne@vajhoej.dk> - 2013-01-18 20:27 -0500
              Re: StringBuilder for byte[] Arne Vajhøj <arne@vajhoej.dk> - 2013-01-18 20:28 -0500
            Re: StringBuilder for byte[] Roedy Green <see_website@mindprod.com.invalid> - 2013-01-18 23:21 -0800
              Re: StringBuilder for byte[] Lew <lewbloch@gmail.com> - 2013-01-19 00:42 -0800
                Re: StringBuilder for byte[] Roedy Green <see_website@mindprod.com.invalid> - 2013-01-20 00:48 -0800
    Re: StringBuilder for byte[] Arne Vajhøj <arne@vajhoej.dk> - 2013-01-18 18:44 -0500

#21513 — StringBuilder for byte[]

FromRoedy Green <see_website@mindprod.com.invalid>
Date2013-01-18 00:40 -0800
SubjectStringBuilder for byte[]
Message-ID<ti2if89pi9o6fcd32b739prbocff6i9plp@4ax.com>
It would be a fairly simple task to write a StringBuilder or FastCat
that worked with byte[].  I wonder if such a beast exists already, or
if there would be much use for it.
-- 
Roedy Green Canadian Mind Products http://mindprod.com
The first 90% of the code accounts for the first 90% of the development time.
The remaining 10% of the code accounts for the other 90% of the development 
time. 
~ Tom Cargill  Ninety-ninety Law 

[toc] | [next] | [standalone]


#21515

FromSven Köhler <remove-sven.koehler@gmail.com>
Date2013-01-18 12:15 +0100
Message-ID<alsp4iF91cjU1@mid.dfncis.de>
In reply to#21513
Am 18.01.2013 09:40, schrieb Roedy Green:
> It would be a fairly simple task to write a StringBuilder or FastCat
> that worked with byte[].  I wonder if such a beast exists already, or
> if there would be much use for it.

ByteArrayOutputStream exists. Its write() method would be the equivalent
of StringBuilder.append().

Regards,
  Sven

[toc] | [prev] | [next] | [standalone]


#21525

FromLew <lewbloch@gmail.com>
Date2013-01-18 08:54 -0800
Message-ID<7ff63461-89b5-4196-8902-ead245eb6945@googlegroups.com>
In reply to#21515
Sven Köhler wrote:
> Roedy Green:
>> It would be a fairly simple task to write a StringBuilder or FastCat
>> that worked with byte[].  I wonder if such a beast exists already, or
>> if there would be much use for it.
> 
> ByteArrayOutputStream exists. Its write() method would be the equivalent
> of StringBuilder.append().

Actually, not quite. The former needs a Writer to handle encoding.

A better choice would be 
http://docs.oracle.com/javase/7/docs/api/java/io/CharArrayWriter.html

-- 
Lew

[toc] | [prev] | [next] | [standalone]


#21527

FromSven Köhler <remove-sven.koehler@gmail.com>
Date2013-01-18 18:08 +0100
Message-ID<altdruFdqh6U1@mid.dfncis.de>
In reply to#21525
Am 18.01.2013 17:54, schrieb Lew:
> Sven Köhler wrote:
>> Roedy Green:
>>> It would be a fairly simple task to write a StringBuilder or FastCat
>>> that worked with byte[].  I wonder if such a beast exists already, or
>>> if there would be much use for it.
>>
>> ByteArrayOutputStream exists. Its write() method would be the equivalent
>> of StringBuilder.append().
> 
> Actually, not quite. The former needs a Writer to handle encoding.

Oh I see. You interpreted the question completely different.
I was assuming, that the input was bytes, not characters.

But anyway: wouldn't ByteArrayOutputStream + OutputStreamWriter be
exactly the right thing if the input was characters?

> A better choice would be 
> http://docs.oracle.com/javase/7/docs/api/java/io/CharArrayWriter.html

It works with char[] internally. The question was about something that
works with byte[] internally, I believe. Not sure, what that is good for
though.


Regards,
  Sven

[toc] | [prev] | [next] | [standalone]


#21555

FromArne Vajhøj <arne@vajhoej.dk>
Date2013-01-18 18:42 -0500
Message-ID<50f9de01$0$282$14726298@news.sunsite.dk>
In reply to#21525
On 1/18/2013 11:54 AM, Lew wrote:
> Sven Köhler wrote:
>> Roedy Green:
>>> It would be a fairly simple task to write a StringBuilder or FastCat
>>> that worked with byte[].  I wonder if such a beast exists already, or
>>> if there would be much use for it.
>>
>> ByteArrayOutputStream exists. Its write() method would be the equivalent
>> of StringBuilder.append().
>
> Actually, not quite. The former needs a Writer to handle encoding.
>
> A better choice would be
> http://docs.oracle.com/javase/7/docs/api/java/io/CharArrayWriter.html

But wasn't the point to work with byte[] instead of String/char[] ?

Arne

[toc] | [prev] | [next] | [standalone]


#21561

FromLew <lewbloch@gmail.com>
Date2013-01-18 17:07 -0800
Message-ID<f9276cb7-52df-4fcf-86a7-442d0a9a21d2@googlegroups.com>
In reply to#21555
Arne Vajhøj wrote:
> Lew wrote:
>>> Roedy Green:
>>>> It would be a fairly simple task to write a StringBuilder or FastCat
>>>> that worked with byte[].  I wonder if such a beast exists already, or
>>>> if there would be much use for it.

>> A better choice would be
>> http://docs.oracle.com/javase/7/docs/api/java/io/CharArrayWriter.html
> 
> But wasn't the point to work with byte[] instead of String/char[] ?

Was it? 

He said that the task is "to write a StringBuilder or FastCat". I don't know what a 
"FastCat" is, but a 'StringBuilder' needs encodings. So 'byte[]' is a case of being 
focused on implementation rather than goal, a flaw you yourself often notice in 
people's queries, Arne.

So I have to ask, if your goal is to build a 'String', why would you use 'byte' when 'char' 
is for that purpose?

I presume to conclude that Roedy screwed up on that one.

-- 
Lew

[toc] | [prev] | [next] | [standalone]


#21562

FromArne Vajhøj <arne@vajhoej.dk>
Date2013-01-18 20:27 -0500
Message-ID<50f9f6a1$0$285$14726298@news.sunsite.dk>
In reply to#21561
On 1/18/2013 8:07 PM, Lew wrote:
> Arne Vajhøj wrote:
>> Lew wrote:
>>>> Roedy Green:
>>>>> It would be a fairly simple task to write a StringBuilder or FastCat
>>>>> that worked with byte[].  I wonder if such a beast exists already, or
>>>>> if there would be much use for it.
>
>>> A better choice would be
>>> http://docs.oracle.com/javase/7/docs/api/java/io/CharArrayWriter.html
>>
>> But wasn't the point to work with byte[] instead of String/char[] ?
>
> Was it?
>
> He said that the task is "to write a StringBuilder or FastCat".

Not really.

That was the first part of what he said that you just arbitrarily truncated.

>                                                    I don't know what a
> "FastCat" is, but a 'StringBuilder' needs encodings.

True. But byte[] does not.

>                                               So 'byte[]' is a case of being
> focused on implementation rather than goal,

It asked for a StringBuilder for byte[]. That is a goal.

It seems weird to me to assume that he want something else than
what he asked for.

> So I have to ask, if your goal is to build a 'String', why would you use 'byte' when 'char'
> is for that purpose?

There are not really any indication that he want to build a String.

There is every indication that he want to build a byte array.

When somebody ask for "Type1Something for Type2" it seems
natural to assume that they want "Type2Something" and a
ByteArrayBuilder would produce a byte array.

> I presume to conclude that Roedy screwed up on that one.

It happens.

But I doubt it is the case this time.

Arne

[toc] | [prev] | [next] | [standalone]


#21563

FromArne Vajhøj <arne@vajhoej.dk>
Date2013-01-18 20:28 -0500
Message-ID<50f9f6d0$0$285$14726298@news.sunsite.dk>
In reply to#21562
On 1/18/2013 8:27 PM, Arne Vajhøj wrote:
> On 1/18/2013 8:07 PM, Lew wrote:
>> Arne Vajhøj wrote:
>>> Lew wrote:
>>>>> Roedy Green:
>>>>>> It would be a fairly simple task to write a StringBuilder or FastCat
>>>>>> that worked with byte[].  I wonder if such a beast exists already, or
>>>>>> if there would be much use for it.
>>
>>>> A better choice would be
>>>> http://docs.oracle.com/javase/7/docs/api/java/io/CharArrayWriter.html
>>>
>>> But wasn't the point to work with byte[] instead of String/char[] ?
>>
>> Was it?
>>
>> He said that the task is "to write a StringBuilder or FastCat".
>
> Not really.
>
> That was the first part of what he said that you just arbitrarily
> truncated.
>
>>                                                    I don't know what a
>> "FastCat" is, but a 'StringBuilder' needs encodings.
>
> True. But byte[] does not.
>
>>                                               So 'byte[]' is a case of
>> being
>> focused on implementation rather than goal,
>
> It asked for a StringBuilder for byte[]. That is a goal.
>
> It seems weird to me to assume that he want something else than
> what he asked for.
>
>> So I have to ask, if your goal is to build a 'String', why would you
>> use 'byte' when 'char'
>> is for that purpose?
>
> There are not really any indication that he want to build a String.
>
> There is every indication that he want to build a byte array.
>
> When somebody ask for "Type1Something for Type2" it seems
> natural to assume that they want "Type2Something" and a
> ByteArrayBuilder would produce a byte array.
>
>> I presume to conclude that Roedy screwed up on that one.
>
> It happens.
>
> But I doubt it is the case this time.

This is somewhat confirmed by his other question.

Arne

[toc] | [prev] | [next] | [standalone]


#21569

FromRoedy Green <see_website@mindprod.com.invalid>
Date2013-01-18 23:21 -0800
Message-ID<o1ikf8hd1n2cu88e05etv433ta7dc3v72s@4ax.com>
In reply to#21561
On Fri, 18 Jan 2013 17:07:16 -0800 (PST), Lew <lewbloch@gmail.com>
wrote, quoted or indirectly quoted someone who said :

>
>He said that the task is "to write a StringBuilder or FastCat".

What I intended was just something to concatenate byte[] into longer
byte[], no encodings involved, not a StringBuilder than squirted out
encoded bytes.  It is a subset of what ByteArrayOutputStream does.

A FastCat is like a StringBuilder but where you estimate the number
fragments to be joined, not the total length of the result. It is more
RAM efficient since it allocates the precise amount of space needed
for the concatenated String.

see http://mindprod.com/jgloss/stringbuilder.html
where I discuss the merits of StringBuilder vs FastCat vs StringBuffer
-- 
Roedy Green Canadian Mind Products http://mindprod.com
The first 90% of the code accounts for the first 90% of the development time.
The remaining 10% of the code accounts for the other 90% of the development 
time. 
~ Tom Cargill  Ninety-ninety Law 

[toc] | [prev] | [next] | [standalone]


#21574

FromLew <lewbloch@gmail.com>
Date2013-01-19 00:42 -0800
Message-ID<60a15fd6-7cfd-4fe8-a73c-f54022c548dd@googlegroups.com>
In reply to#21569
Roedy Green wrote:
> Lew wrote, quoted or indirectly quoted someone who said :
>> He said that the task is "to write a StringBuilder or FastCat".
> 
> What I intended was just something to concatenate byte[] into longer
> byte[], no encodings involved, not a StringBuilder than squirted out
> encoded bytes.  It is a subset of what ByteArrayOutputStream does.
> 
> A FastCat is like a StringBuilder but where you estimate the number
> fragments to be joined, not the total length of the result. It is more
> RAM efficient since it allocates the precise amount of space needed
> for the concatenated String.
> 
> see http://mindprod.com/jgloss/stringbuilder.html
> 
> where I discuss the merits of StringBuilder vs FastCat vs StringBuffer

I stand corrected.

-- 
Lew

[toc] | [prev] | [next] | [standalone]


#21580

FromRoedy Green <see_website@mindprod.com.invalid>
Date2013-01-20 00:48 -0800
Message-ID<epbnf8pqkqf7obp1k492kv2iib4oep35a6@4ax.com>
In reply to#21574
On Sat, 19 Jan 2013 00:42:52 -0800 (PST), Lew <lewbloch@gmail.com>
wrote, quoted or indirectly quoted someone who said :

>I stand corrected.

I said something that was interpreted two different ways. That is my
bad, not yours.
-- 
Roedy Green Canadian Mind Products http://mindprod.com
The first 90% of the code accounts for the first 90% of the development time.
The remaining 10% of the code accounts for the other 90% of the development 
time. 
~ Tom Cargill  Ninety-ninety Law 

[toc] | [prev] | [next] | [standalone]


#21556

FromArne Vajhøj <arne@vajhoej.dk>
Date2013-01-18 18:44 -0500
Message-ID<50f9de6d$0$282$14726298@news.sunsite.dk>
In reply to#21513
On 1/18/2013 3:40 AM, Roedy Green wrote:
> It would be a fairly simple task to write a StringBuilder or FastCat
> that worked with byte[].  I wonder if such a beast exists already, or
> if there would be much use for it.

There are plenty of classes in java.io that writes bytes
sequentially.

ByteArrayOutputStream or DataOutputStream on top of
ByteArrayOutputStream was two options.

Arne

[toc] | [prev] | [standalone]


Back to top | Article view | comp.lang.java.programmer


csiph-web