[SIGAR-133] use InputStream.skip (bytes) instead of Reader.skip (chars) in onChange
This commit is contained in:
parent
5a602a0a06
commit
6c390d494a
|
@ -18,8 +18,10 @@
|
||||||
|
|
||||||
package org.hyperic.sigar;
|
package org.hyperic.sigar;
|
||||||
|
|
||||||
|
import java.io.FileInputStream;
|
||||||
import java.io.FileReader;
|
import java.io.FileReader;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.io.InputStream;
|
||||||
import java.io.InputStreamReader;
|
import java.io.InputStreamReader;
|
||||||
import java.io.Reader;
|
import java.io.Reader;
|
||||||
|
|
||||||
|
@ -54,24 +56,24 @@ public abstract class FileTail extends FileWatcher {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void onChange(FileInfo info) {
|
public void onChange(FileInfo info) {
|
||||||
|
InputStream in = null;
|
||||||
Reader reader = null;
|
Reader reader = null;
|
||||||
String name = info.getName();
|
String name = info.getName();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
if (this.useSudo) {
|
if (this.useSudo) {
|
||||||
reader =
|
in = new SudoFileInputStream(name);
|
||||||
new InputStreamReader(new SudoFileInputStream(name));
|
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
reader = new FileReader(name);
|
in = new FileInputStream(name);
|
||||||
}
|
}
|
||||||
|
|
||||||
long offset = getOffset(info);
|
long offset = getOffset(info);
|
||||||
|
|
||||||
if (offset > 0) {
|
if (offset > 0) {
|
||||||
reader.skip(offset);
|
in.skip(offset); //use InputStream to skip bytes
|
||||||
}
|
}
|
||||||
|
reader = new InputStreamReader(in);
|
||||||
tail(info, reader);
|
tail(info, reader);
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
error(name, e);
|
error(name, e);
|
||||||
|
@ -79,6 +81,9 @@ public abstract class FileTail extends FileWatcher {
|
||||||
if (reader != null) {
|
if (reader != null) {
|
||||||
try { reader.close(); } catch (IOException e) { }
|
try { reader.close(); } catch (IOException e) { }
|
||||||
}
|
}
|
||||||
|
if (in != null) {
|
||||||
|
try { in.close(); } catch (IOException e) { }
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue