Relative Content

Tag Archive for file-storage

How are Java ByteBuffer’s limit and position variable’s updated?

There are two scenarios: writing and reading
Writing:
Whenever I write something to the ByteBuffer by calling its put(byte[]) method the position variable is incremented as: current position + size of byte[] and limit stays at the max.
If, however, I put the data in a view buffer then I will have to, manually, calculate and update the position
Before I call the write(ByteBuffer) method of the channel to write something, I will have to flip() the Bytebuffer so that
position points to zero and limit points to the last byte that was written to the ByteBuffer.
Reading:
Whenever I call the read(ByteBuffer) method of a channel to read something, the position variable stays at 0 and the limit variable of the ByteBuffer points to the last byte that was read. So, if the ByteBuffer is smaller than the file being read, the limit variable is pushed to max
This means that the ByteBuffer is already flipped and I can proceed to extracting the values from the ByteBuffer.
Please, correct me where I am wrong 🙂

Interaction between programs

I am writing an interactive program in which it takes speech input from the user for a specific list of commands.

Binary data storage scheme (saving user-uploaded files)

In our app we are currently saving binary data to the database (terrible, I know; but this is legacy stuff and it wasn’t my decision). We’re trying to migrate this data out to an external device and I’m trying to come up with a scheme to save these files.

Why do we need a format for binary executable files

When binary files (i.e. executables) are saved they usually have a format (e.g. ELF or .out) where we have a header containing pointers to where data or code is stored inside the file. But why don’t we store the binary files directly in the form of sequence of machine instructions.
Why do we need to store data separately from the code?
Secondly when the assembler creates a binary file is the file is among the above formats?