As part of my Java course, I wrote a "zip" writer and reader - as Huffman algorithm works.
My class extends Reader, and have an object Reader r. In my main method, I have these lines:
input = new BufferedReader(new HuffmanReader(new FileReader("output.hff")));
String str = input.readLine();
It should return the decompressed string I wrote to the file, after decompressing it, of course. But it returns the first line of the file!
My read function:
public int read(char[] cbuf, int off, int len) throws IOException {
//...
r.read(buffer,0,8192)
//does the decompress process
String fnlStr = ... //The final result
cbuf = fnlStr.toCharArray();
//close streams
return cbuf.length;
}
My Debug window shows this:
HuffmanReader.read(char[], int, int) line: 23
BufferedReader.fill() line: not available
BufferedReader.readLine(boolean) line: not available
BufferedReader.readLine() line: not available
Run.main(String[]) line: 23
It calls my read function twice. How can I stop the bufferReader from calling the read function again?