wood burning stoves 2.0*
The moose likes I/O and Streams and the fly likes Creating file blocks Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » I/O and Streams
Bookmark "Creating file blocks" Watch "Creating file blocks" New topic

Creating file blocks

Ryan Waggoner
Ranch Hand

Joined: Jun 27, 2007
Posts: 75
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...

Nitesh Kant

Joined: Feb 25, 2007
Posts: 1638

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 ]

apigee, a better way to API!
Ryan Waggoner
Ranch Hand

Joined: Jun 27, 2007
Posts: 75
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?

Nicholas Jordan
Ranch Hand

Joined: Sep 17, 2006
Posts: 1282
[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.

"The differential equations that describe dynamic interactions of power generators are similar to that of the gravitational interplay among celestial bodies, which is chaotic in nature."
I agree. Here's the link: http://aspose.com/file-tools
subject: Creating file blocks
Similar Threads
about static and instance initializer blocks with inheritance
Order of initialization
need for constructors in this case
Problem in framing or understanding the exact approach for the given specification
B&S: Locking