Working on a lempel-ziv decompression method, and we're having some trouble. Text lines like below won't decomress correcctly.
----------+----+----+----+----+----+----+----+----
It becomes like below and makes a mess of the next line.
----------+----+----+----+----+----+----+----+
Do you see any faults in the code?
public void lzDecompression(String filePath, String newFileName) throws IOException {
bReader = new BufferedReader(new FileReader(infile));
StreamTokenizer streamT = new StreamTokenizer(bReader);
//Adds charachters as ordenary characters in stream tokenizer (using
//streamT.ordenaryChar() and
//streamT.wordChars()). # is special character for compression.
String outputData = "";
int offset, length;
while (streamT.nextToken() != StreamTokenizer.TT_EOF) {
switch (streamT.ttype) {
case StreamTokenizer.TT_WORD:
searchBuffer.append(streamT.sval);
outputData += streamT.sval;
trimSearchBuffer();
break;
case StreamTokenizer.TT_NUMBER:
offset = (int)streamT.nval;
streamT.nextToken();
//Checking if a word comes after the number instead of
//separator => number was part of word
if (streamT.ttype == StreamTokenizer.TT_WORD) {
searchBuffer.append(offset+streamT.sval);
outputData += offset+streamT.sval;
break;
}
streamT.nextToken();
length = (int)streamT.nval;
String output = searchBuffer.substring(offset, offset+length);
outputData += output;
searchBuffer.append(output);
trimSearchBuffer();
break;
}
}
//Writes outputData to file
}
}