• 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

Creating file blocks

 
Ranch Hand
Posts: 75
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have been thrown into an assignment in an area where I have VERY little experience.

I need to create a class that manipulates a file using .nio. Some parts of this class include create, get, put etc. To get started, I need to divide the file into blocks. Every other method revloves around this. The problem is, I do not know what a block is. I dont know if it is figurative or literal.

If figurative would some have some advice on what a block should be?

I hope you and understand what I am trying to say...

Thanks!
 
Bartender
Posts: 1638
IntelliJ IDE MySQL Database Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Using nio one can lock a portion of a file, this means that no other program will be able to lock that portion of the file(if it is not a shared lock). So, the lock owner can modify the contents of that portion of the file without worrying whether someone else(provided it also uses locks) is working on the file or not. This provides a way of multiple threads working on different portions of the file simultaneously.
Probably, this is what you mean when you say "block" of a file.
You can refer to the FileChannel API to get details on how to lock a file portion.
Yeah, the concept of this lock is just figurative and there is no literal partitionof the file on the file system.

[ August 06, 2007: Message edited by: Nitesh Kant ]
[ August 06, 2007: Message edited by: Nitesh Kant ]
 
Ryan Waggoner
Ranch Hand
Posts: 75
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm not blocking access yet. I meant dividing the file into byte blocks. Is a byte block just a buffer?

If so, how do I divide the entire file into buffer that can be identified?

Thanks!
 
Ranch Hand
Posts: 1282
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
[Ryan Waggoner: ] The problem is, I do not know what a block is. I dont know if it is figurative or literal.


The definition of exactly what a block is leads into discussions that can be dicey to work through. In general,a block is something you define or work with yourself, in code, and no matter how many critics lead you to superficial solutions to your question, only write some code and test it will provide meaningful, reliable answers that you can use for later thought.

A block is some sort of portion of the file. Files do not have intrinsic blocks, from Java's viewpoint. Anytime you hear the word block, you need to consider the possibility that there are two blind cooks in the kitchen, in which case you get wording like that in the comments on the short code snippet above.

The entire purpose of creating some sort of block - as in FileBlock, or any other representation of this idea - is that there appears often in real practice a need to set some portion of a file apart for work by the program. There can be other programs running. If two or more programs write to a file, they may change the file while another program is reading the file.

The result may look funny to the student. It looks hideous to someone who paid money for the machine to do some work in a real business.
 
reply
    Bookmark Topic Watch Topic
  • New Topic