Hey guys
I'm working on this java assignment it has to do with buffers take a look:
-----------------------------------------------
In this assignment, you will unblock buffered input records and
repack the byte data obtained into a new set of blocked files.
The records inside the blocks have varying sizes according the
following scheme.
The data types are character (c), string (s), integer (d) and float(f).
The size of the data of the given type will also be encoded, with
the exception of character data, which will always have size 1.
The data layout will encoded as a format string, similar but not
equivalent to C I/O format strings:
(xiyjzk....) where x, y, z and so on are the data type indicators
and i, j, k and so on are the size indicators.
The parenthesis symbols, "(" and ")" are part of the format
string.
Since character data is always length 1, the length indicator is
omitted. Floating point data is formatted as l.r where l is the
number of decimal places to the left of the decimal and r is the
number of places to the right of the decimal point.
BNF:
format-string ->
"("{decimal-format|string-format|float-format|char-format}+")"
decimal-format -> "d"digit
string-format -> "s"digit
float-format -> "f"digit"."digit"
char-format -> "c"
digit -> 1|2|3|4|5|6|7|8|9
For instance (s5d3) would mean a string of length 5 followed by
an integer taking up three bytes (as an ASCII value).
A more robust format string might be
(s5d3cf3.5s2cd3d3f1.2)
parsed as s5, d3, c, f3.5, s2, c, d3, d3, f1.2
Data:
The length of the data will be the sum of the digits.
Data immediately follows the format string in the buffer:
(s5d3cf3.5s2cd2d4f1.2)keith123q12312345xyz98765432 1
The data is then interpreted as follows:
s5: keith
d3: 123
c: q
f3.5: 123.12345
s2: xy
c: z
d2: 98
d4: 7654
f1.2: 3.21
The next record follows immediately in the buffer:
(s5d3cf3.5s2cd3d3f1.2)keith123q12312345xyz98765432 1(d1d1cs2)12abc(d5)13579...
Use compile time -D to define buffer size. See
~kbg/302/C++/define.cpp. If the buffer is exhausted before the data
is, inspect the next buffer-full until all inputs are exhausted.
Outputs:
Your program must distribute all the string data to one file, all the
character data to another, all the integer data to yet another, and
all the floating point data to a fourth file. The same formatting
methods must be used to encode the data (WHERE APPROPRIATE!).
Thus the sample above would be distributed:
string file: (s5s2s2...)keithxybc....
or (s5)keith(s2)xy(s2)bc...
integer file (d3d3d3d1d1d5...)1239876541213579...
or (d3)123(d3)987(d3)654(d1)1(d1)2(d5)13579...
float file: (f3.5f1.2...12312345321
or (f3.5)12312345(f1.2)321
character file: (ccc...)qza...
or (c)q(c)z(c)a...
THEN, WHEN EACH OUTPUT BUFFER IS FULL (AND ONLY THEN) IT IS WRITTEN TO THE
CORRESPONDING FILE.
File inputs on the command line must be used.
Use _unformatted_ I/O: read, write.
I/O CAN ONLY BE DONE A BUFFER-FULL AT A TIME....
END OF FILE IS DETERMINED BY COUNTING THE NUMBER OF INPUT ITEMS,
(not by eof methods)
YOU MAY USE AT MOST 10 BUFFERS.
Example: assume a buffer size of 16, 2 input buffers, 1 output buffer per type.
the input: (s5f5.4)ABCDE123451234(f3.4)1231234(d9c)987654321X
the first 16 bytes are read in
I1: (s5f5.4)ABCDE123 // to one input buffer
... the beginning and end of the format string are determined...
move the format and data to the string output BUFFER (not the file)
S1: (s5)ABCDE
move the format and data to the float output buffer (not the file)
F1: (f5.4)123
now the input buffer is exhausted. read in another:
I2: 451234(f3.4)1231
and finish the copy to the float buffer, which becomes
F1: (f5.4)123451234 // this now has 15 items in it.
now find the beginning and end of the next format string and
in buffer I2. (THE END OF THE FORMAT STRING NEED NOT BE IN THE
BUFFER!)
But when the move to the float buffer is attempted, there
isn't enough room!!! so, fill as much as will fit; then write out the
float buffer:
so, the float buffer, F1, becomes (f5.4)123451234( ie. gets filled up.
the write of the buffer does not change its contents.
then the rest of the current float format string is memcpy'ed (hint)
into the buffer:
(f5.4)123451234(
F1: f3.4))123451234( ... notice what happens
^
this is where the next data is placed.
then the data is copied in behind the format string:
F1: f3.4)12313451234(
^
this is where the next data is placed.
... but the input buffer is exhausted! again. --
read in some more over writing the first input buffer:
I1: 234(d9c)98765432
and finish the copy into the float buffer:
F1: f3.4)12312341234(
^
this is where the next data is placed.
now process format string (d9c) in buffer I1....
but before the processing is finished, the buffer is exhausted,
so...
At this point in the computation, only one output has been performed:
that of the full buffer of float data. There have been three reads to fill
the input buffers.
END OF EXAMPLE...
Assumptions / other issues:
1. The formating digit will be between 1-9, inclusive.
2. Validity checking: will format and data fit in two buffers? If not, exit
gracefully.
(f9.9f9.9f9.9f9.9f9.9f9.9f9.9f9.9f9.9f9.9f9.9f9.9f 9.9f9.9f9.9f9.9f9.9f9.9f9.9f9.9f9.9f9.9f9.9f9.9f9. 9f9.9f9.9f9.9f9.9f9.9f9.9f9.9f9.9f9.9f9.9f9.9f9.9f 9.9f9.9f9.9f9.9f9.9f9.9f9.9f9.9f9.9f9.9f9.9f9.9f9. 9f9.9f9.9f9.9f9.9f9.9f9.9)
-------------------------------------------------
Seems complicated. And I can't understand how to do this program. Anyone familiar with this kind of problem.
Help will be appreciated. Thank you