Skip to content

Instantly share code, notes, and snippets.

@gclaramunt
Created November 4, 2011 14:24
Show Gist options
  • Save gclaramunt/1339424 to your computer and use it in GitHub Desktop.
Save gclaramunt/1339424 to your computer and use it in GitHub Desktop.
Naive tail in Java (to keep up with basic skills)
import java.io.BufferedReader;
import java.io.FileReader;
class NaiveTail{
public static void main(String[] args) throws Exception{
int size=new Integer(args[0]);
String[] circularBuffer=new String[size];
int i=0;
BufferedReader in=new BufferedReader(new FileReader(args[1]));
String line;
while ((line=in.readLine())!=null){
circularBuffer[i++] = line;
i=i % size;
}
for(int j=0; j<size; j++){
System.out.println(circularBuffer[(i+j) % size]);
}
if (args.length>2 && args[2].equals("f")){
while (true){
line=in.readLine();
if (line != null) {
System.out.println(line);
}
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment