reader = new RandomAccessFile(file, RAF_MODE); } catch (final FileNotFoundException e) { listener.fileNotFound(); if (length < position) { listener.fileRotated(); readLines(save); } catch (final IOException ioe) { listener.handle(ioe); listener.fileNotFound(); Thread.sleep(delayMillis); listener.handle(e); } catch (final Exception e) { listener.handle(e); } finally { try { listener.handle(e);
/** * Creates a Tailer for the given file, with a specified buffer size. * @param file the file to follow. * @param cset the Charset to be used for reading the file * @param listener the TailerListener to use. * @param delayMillis the delay between checks of the file for new content in milliseconds. * @param end Set to true to tail from the end of the file, false to tail from the beginning of the file. * @param reOpen if true, close and reopen the file between reading chunks * @param bufSize Buffer size */ public Tailer(final File file, final Charset cset, final TailerListener listener, final long delayMillis, final boolean end, final boolean reOpen , final int bufSize) { this.file = file; this.delayMillis = delayMillis; this.end = end; this.inbuf = new byte[bufSize]; // Save and prepare the listener this.listener = listener; listener.init(this); this.reOpen = reOpen; this.cset = cset; }
this.listener.fileRotated(); this.listener.fileNotFound();
/** * Stops the tailer with an exception * @param e The exception to send to listener */ private void stop(final Exception e) { listener.handle(e); stop(); }
reader = new RandomAccessFile(file, RAF_MODE); } catch (FileNotFoundException e) { listener.fileNotFound(); listener.fileRotated(); } catch (FileNotFoundException e) { listener.fileNotFound(); listener.handle(e);
/** * Read new lines. * * @param reader The file to read * @return The new position after the lines have been read * @throws java.io.IOException if an I/O error occurs. */ private long readLines(RandomAccessFile reader) throws IOException { long pos = reader.getFilePointer(); String line = readLine(reader); while (line != null) { pos = reader.getFilePointer(); listener.handle(line); line = readLine(reader); } reader.seek(pos); // Ensure we can re-read if necessary return pos; }
/** * Creates a Tailer for the given file, with a delay other than the default 1.0s. * @param file the file to follow. * @param listener the TailerListener to use. * @param delay the delay between checks of the file for new content in milliseconds. * @param end Set to true to tail from the end of the file, false to tail from the beginning of the file. */ public Tailer(File file, TailerListener listener, long delay, boolean end) { this.file = file; this.delay = delay; this.end = end; // Save and prepare the listener this.listener = listener; listener.init(this); }
reader = new RandomAccessFile(file, "r"); } catch (FileNotFoundException e) { listener.fileNotFound(); listener.fileRotated(); } catch (FileNotFoundException e) { listener.fileNotFound(); listener.handle(e);
/** * Creates a Tailer for the given file, with a specified buffer size. * @param file the file to follow. * @param listener the TailerListener to use. * @param delayMillis the delay between checks of the file for new content in milliseconds. * @param end Set to true to tail from the end of the file, false to tail from the beginning of the file. * @param reOpen if true, close and reopen the file between reading chunks * @param bufSize Buffer size */ public Tailer(File file, TailerListener listener, long delayMillis, boolean end, boolean reOpen, int bufSize) { this.file = file; this.delayMillis = delayMillis; this.end = end; this.inbuf = new byte[bufSize]; // Save and prepare the listener this.listener = listener; listener.init(this); this.reOpen = reOpen; }
reader = new RandomAccessFile(file, RAF_MODE); } catch (final FileNotFoundException e) { listener.fileNotFound(); if (length < position) { listener.fileRotated(); readLines(save); } catch (final IOException ioe) { listener.handle(ioe); listener.fileNotFound(); Thread.sleep(delayMillis); listener.handle(e); } catch (final Exception e) { listener.handle(e); } finally { try { listener.handle(e);
/** * Creates a Tailer for the given file, with a specified buffer size. * @param file the file to follow. * @param cset the Charset to be used for reading the file * @param listener the TailerListener to use. * @param delayMillis the delay between checks of the file for new content in milliseconds. * @param end Set to true to tail from the end of the file, false to tail from the beginning of the file. * @param reOpen if true, close and reopen the file between reading chunks * @param bufSize Buffer size */ public Tailer(final File file, final Charset cset, final TailerListener listener, final long delayMillis, final boolean end, final boolean reOpen , final int bufSize) { this.file = file; this.delayMillis = delayMillis; this.end = end; this.inbuf = new byte[bufSize]; // Save and prepare the listener this.listener = listener; listener.init(this); this.reOpen = reOpen; this.cset = cset; }
reader = new RandomAccessFile(file, RAF_MODE); } catch (final FileNotFoundException e) { listener.fileNotFound(); if (length < position) { listener.fileRotated(); readLines(save); } catch (IOException ioe) { listener.handle(ioe); } catch (final FileNotFoundException e) { listener.fileNotFound();
/** * Creates a Tailer for the given file, with a specified buffer size. * @param file the file to follow. * @param cset the Charset to be used for reading the file * @param listener the TailerListener to use. * @param delayMillis the delay between checks of the file for new content in milliseconds. * @param end Set to true to tail from the end of the file, false to tail from the beginning of the file. * @param reOpen if true, close and reopen the file between reading chunks * @param bufSize Buffer size */ public Tailer(final File file, final Charset cset, final TailerListener listener, final long delayMillis, final boolean end, final boolean reOpen , final int bufSize) { this.file = file; this.delayMillis = delayMillis; this.end = end; this.inbuf = new byte[bufSize]; // Save and prepare the listener this.listener = listener; listener.init(this); this.reOpen = reOpen; this.cset = cset; }
/** * Creates a Tailer for the given file, with a specified buffer size. * * @param file * the file to follow. * @param listener * the TailerListener to use. * @param delayMillis * the delay between checks of the file for new content in milliseconds. * @param end * Set to true to tail from the end of the file, false to tail from the beginning of the file. * @param reOpen * if true, close and reopen the file between reading chunks * @param bufSize * Buffer size */ public LookbackTailer(File file, TailerListener listener, long delayMillis, boolean end, boolean reOpen, int bufSize, long start) { super(file, listener, delayMillis, end, reOpen, bufSize); this.file = file; this.delayMillis = delayMillis; this.end = end; this.start = start; this.inbuf = new byte[bufSize]; // Save and prepare the listener this.listener = listener; listener.init(this); this.reOpen = reOpen; }