Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > Writing objects to random file

Reply
Thread Tools

Writing objects to random file

 
 
Ron Albright
Guest
Posts: n/a
 
      02-05-2004
You use a ByteArrayOutputStream but only way you can access the result
is by getting a copy of the byte array each time you write. Is there a
better way to do this that doesn't require creating a new byte array
for each write? I looked at the nio package and didn't see any support
for writing objects to a file.
--
My email isn't airmail.
Ron
 
Reply With Quote
 
 
 
 
Andrew Thompson
Guest
Posts: n/a
 
      02-05-2004
Ron Albright wrote:
> You use a ByteArrayOutputStream but only way you can access the result
> is by getting a copy of the byte array each time you write. Is there a
> better way to do this that doesn't require creating a new byte array
> for each write?


'Better'? In what way is the existing situation 'worse'?

[ I do not know much about the specific area
that you are speaking of, but wonder if you
are not attempting to optimize something
that does not require optimization?]

--
Andrew Thompson
* http://www.PhySci.org/ Open-source software suite
* http://www.PhySci.org/codes/ Web & IT Help
* http://www.1point1C.org/ Science & Technology


 
Reply With Quote
 
 
 
 
Andrew Hobbs
Guest
Posts: n/a
 
      02-05-2004

"Ron Albright" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> You use a ByteArrayOutputStream but only way you can access the result
> is by getting a copy of the byte array each time you write. Is there a
> better way to do this that doesn't require creating a new byte array
> for each write?


In what way are you using the ByteArrayOutputStream. You don't need to
create an array each time you write. Surely that is the objective of using
this class.

>I looked at the nio package and didn't see any support
> for writing objects to a file.


And how does the above relate to writing to a file. If you want to write
your bytes to a file then have a look at the java.io package. You need to
include something like a DataOutputStream and a FileWriter.

Cheers

Andrew


--
************************************************** ******
Andrew Hobbs PhD

MetaSense Pty Ltd - www.metasense.com.au
12 Ashover Grove
Carine W.A.
Australia 6020

61 8 9246 2026
metasens AntiSpam @iinet dot net dot au


************************************************** *******


> --
> My email isn't airmail.
> Ron



 
Reply With Quote
 
Ron Albright
Guest
Posts: n/a
 
      02-05-2004
On Thu, 5 Feb 2004 11:24:04 +0800, "Andrew Hobbs"
<(E-Mail Removed)> wrote:

>
>"Ron Albright" <(E-Mail Removed)> wrote in message
>news:(E-Mail Removed).. .
>> You use a ByteArrayOutputStream but only way you can access the result
>> is by getting a copy of the byte array each time you write. Is there a
>> better way to do this that doesn't require creating a new byte array
>> for each write?

>
>In what way are you using the ByteArrayOutputStream. You don't need to
>create an array each time you write. Surely that is the objective of using
>this class.


The only way to write the byte array from a
ByteArrayOutputStream is the getByteArray() method or the
writeTo() method. The first gives you a copy of the array
which has to be alloced and garbage collected every time you
write an object. The second requires opening a stream and
skipping to the position you want to write to every time you
write an object. Neither seems very efficient.

>
>>I looked at the nio package and didn't see any support
>> for writing objects to a file.

>
>And how does the above relate to writing to a file. If you want to write
>your bytes to a file then have a look at the java.io package. You need to
>include something like a DataOutputStream and a FileWriter.


You can't write to a random position with streams.

The context of the questions is a fast guarantied persistent
queue or stack. The idea is a collector getting data and
persisting it before acking and a distributor passing it on
and getting an ack before it is removed.

Ron Albright
moron(at)KILLSPAM.pobox.com
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Math.random() and Math.round(Math.random()) and Math.floor(Math.random()*2) VK Javascript 15 05-02-2010 03:43 PM
random.random(), random not defined!? globalrev Python 4 04-20-2008 08:12 AM
class objects, method objects, function objects 7stud Python 11 03-20-2007 06:05 PM
is Random Access File really "random access"? Kevin Java 19 02-13-2006 09:31 PM
Any problems with writing the information into a file - Multi-users perform writing the same file at the same time ???? HNguyen ASP .Net 4 12-21-2004 01:53 PM



Advertisments