1 11 package org.eclipse.pde.internal.runtime.logview; 12 13 import java.io.File ; 14 import java.io.IOException ; 15 import java.io.InputStream ; 16 import java.io.RandomAccessFile ; 17 18 public class TailInputStream extends InputStream { 19 20 private RandomAccessFile fRaf; 21 22 private long fTail; 23 24 public TailInputStream(File file, long maxLength) throws IOException { 25 super(); 26 fTail = maxLength; 27 fRaf = new RandomAccessFile (file, "r"); skipHead(file); 29 } 30 31 private void skipHead(File file) throws IOException { 32 if (file.length() > fTail) { 33 fRaf.seek(file.length() - fTail); 34 int c= read(); 36 while(c!='\n' && c!='r' && c!=-1){ 37 c=read(); 38 } 39 40 } 41 } 42 43 public int read() throws IOException { 44 byte[] b = new byte[1]; 45 int len = fRaf.read(b, 0, 1); 46 if (len < 0) { 47 return len; 48 } 49 return b[0]; 50 } 51 52 public int read(byte[] b) throws IOException { 53 return fRaf.read(b, 0, b.length); 54 } 55 56 public int read(byte[] b, int off, int len) throws IOException { 57 return fRaf.read(b, off, len); 58 } 59 60 public void close() throws IOException { 61 fRaf.close(); 62 } 63 64 } 65 | Popular Tags |