Another funny implementation of the line iterator mentioned before. Those two did not at all understand the concept of lightweight associated with an iterator. Each call of next() or hasNext() resulted in a call of this method:
public String getLineAtPosition (int index) {
FileInputStream dataFile = new FileInputStream(this.fileName);
byte[] buffer = new byte[1];
String data = "";
while ((dataFile.available() != 0) && (index != 0)) {
dataFile.read(buffer);
data += (char) buffer[0];
if (lineBreak(data)) {
index--;
data = "";
}
}
if (dataFile.available() == 0) {
return "Insufficient data.";
}
while (dataFile.available() != 0) {
dataFile.read(buffer);
data += (char) buffer[0];
if (lineBreak(data)) {
data = noLineBreak(data);
break;
}
}
return data;
}Well, there are a lot of grave mistakes in here, too. But imagine this method called every time! A test case reading Goethe’s “Zauberlehrling” (111 lines) took almost a minute to finish…
Posted by torturedtutor 