• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

I need to divide a text file into blocks of 128 bits, how do i do it?

 
Ranch Hand
Posts: 77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi
I have to divide a text file into blocks of 128 bits.
I think i must use the ByteArrayInputStream and ByteArrayOutputStream classes. my question is how would i do that?

is there any website showing how to user these two ByteArrayInputStream and ByteArrayOutputStream classes in detail.

or it would be much better if you could show me a portion of the code. so i get to learn how to do it.

Thanks

Sura
 
Bartender
Posts: 9626
16
Mac OS X Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
ByteArrayInputStream and ByteArrayOutputStream are for reading and writing to byte arrays. Perhaps you should look at the various methods of InputStream. In particular, the one which takes an array as an argument.
Be aware that in some text encodings, a byte does not equal a character so breaking text up in 128 bit blocks may screw things up big time.
 
Ranch Hand
Posts: 1780
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Why do you need to divide the file? What is your goal? Do you realize that in many character encodings, bytes and chars are not interchangeable? All that being said, the easiest way to read a fixed number of bytes is DataInputStream's readFully method:

http://java.sun.com/j2se/1.5.0/docs/api/java/io/DataInputStream.html

And it sounds like you could benefit from Sun's I/O tutorial: http://java.sun.com/docs/books/tutorial/essential/io/index.html
 
reply
    Bookmark Topic Watch Topic
  • New Topic