1 /*******************************************************************************
\r
2 * Copyright (c) 2007, 2010 Association for Decentralized Information Management
\r
3 * in Industry THTH ry.
\r
4 * All rights reserved. This program and the accompanying materials
\r
5 * are made available under the terms of the Eclipse Public License v1.0
\r
6 * which accompanies this distribution, and is available at
\r
7 * http://www.eclipse.org/legal/epl-v10.html
\r
10 * VTT Technical Research Centre of Finland - initial API and implementation
\r
11 *******************************************************************************/
\r
12 package org.simantics.message.ui;
15 import java.io.IOException;
16 import java.io.InputStream;
17 import java.io.RandomAccessFile;
19 public class TailInputStream extends InputStream {
21 private RandomAccessFile fRaf;
25 public TailInputStream(File file, long maxLength) throws IOException {
28 fRaf = new RandomAccessFile(file, "r"); //$NON-NLS-1$
32 private void skipHead(File file) throws IOException {
33 if (file.length() > fTail) {
34 fRaf.seek(file.length() - fTail);
35 // skip bytes until a new line to be sure we start from a beginnng of valid UTF-8 character
37 while (c != '\n' && c != 'r' && c != -1) {
44 public int read() throws IOException {
45 byte[] b = new byte[1];
46 int len = fRaf.read(b, 0, 1);
53 public int read(byte[] b) throws IOException {
54 return fRaf.read(b, 0, b.length);
57 public int read(byte[] b, int off, int len) throws IOException {
58 return fRaf.read(b, off, len);
61 public void close() throws IOException {