Forums Register Login

Creating file blocks

+Pie Number of slices to send: Send
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!
+Pie Number of slices to send: Send
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 ]
+Pie Number of slices to send: Send
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!
+Pie Number of slices to send: Send
[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.
Climb the rope! CLIMB THE ROPE! You too tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com


reply
reply
This thread has been viewed 1172 times.
Similar Threads
about static and instance initializer blocks with inheritance
need for constructors in this case
B&S: Locking
Order of initialization
Problem in framing or understanding the exact approach for the given specification
More...

All times above are in ranch (not your local) time.
The current ranch time is
Apr 16, 2024 06:05:26.