Created
November 4, 2011 14:24
-
-
Save gclaramunt/1339424 to your computer and use it in GitHub Desktop.
Naive tail in Java (to keep up with basic skills)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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