forked from I2P_Developers/i2p.i2p
Console: Handle wrapper log trunctaion
More efficient line skipping
This commit is contained in:
@ -169,11 +169,22 @@ public class LogsHelper extends HelperBase {
|
|||||||
// platform encoding or UTF8
|
// platform encoding or UTF8
|
||||||
boolean utf8 = !_context.hasWrapper();
|
boolean utf8 = !_context.hasWrapper();
|
||||||
StringBuilder buf = new StringBuilder(MAX_WRAPPER_LINES * 80);
|
StringBuilder buf = new StringBuilder(MAX_WRAPPER_LINES * 80);
|
||||||
toSkip = readTextFile(f, utf8, MAX_WRAPPER_LINES, toSkip, buf);
|
long ntoSkip = readTextFile(f, utf8, MAX_WRAPPER_LINES, toSkip, buf);
|
||||||
if (toSkip >= 0)
|
if (ntoSkip < toSkip) {
|
||||||
str = buf.toString();
|
if (ntoSkip < 0) {
|
||||||
else
|
// error
|
||||||
str = null;
|
str = null;
|
||||||
|
} else {
|
||||||
|
// truncated?
|
||||||
|
str = "";
|
||||||
|
}
|
||||||
|
// remove old setting
|
||||||
|
if (prop != null)
|
||||||
|
_context.router().saveConfig(PROP_LAST_WRAPPER, null);
|
||||||
|
} else {
|
||||||
|
str = buf.toString();
|
||||||
|
}
|
||||||
|
toSkip = ntoSkip;
|
||||||
}
|
}
|
||||||
String loc = DataHelper.escapeHTML(f.getAbsolutePath());
|
String loc = DataHelper.escapeHTML(f.getAbsolutePath());
|
||||||
if (str == null) {
|
if (str == null) {
|
||||||
@ -300,13 +311,22 @@ public class LogsHelper extends HelperBase {
|
|||||||
in = new BufferedReader(new InputStreamReader(new FileInputStream(f), "UTF-8"));
|
in = new BufferedReader(new InputStreamReader(new FileInputStream(f), "UTF-8"));
|
||||||
else
|
else
|
||||||
in = new BufferedReader(new InputStreamReader(new FileInputStream(f)));
|
in = new BufferedReader(new InputStreamReader(new FileInputStream(f)));
|
||||||
Queue<String> lines = new ArrayBlockingQueue<String>(maxNumLines);
|
|
||||||
long i = 0;
|
long i = 0;
|
||||||
|
while (i < skipLines) {
|
||||||
|
// skip without readLine() to avoid object churn
|
||||||
|
int c;
|
||||||
|
do {
|
||||||
|
c = in.read();
|
||||||
|
if (c < 0)
|
||||||
|
return i; // truncated
|
||||||
|
} while (c != '\n');
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
Queue<String> lines = new ArrayBlockingQueue<String>(maxNumLines);
|
||||||
synchronized(lines) {
|
synchronized(lines) {
|
||||||
String line = null;
|
String line = null;
|
||||||
while ( (line = in.readLine()) != null) {
|
while ( (line = in.readLine()) != null) {
|
||||||
if (i++ < skipLines)
|
i++;
|
||||||
continue;
|
|
||||||
if (lines.size() >= maxNumLines)
|
if (lines.size() >= maxNumLines)
|
||||||
lines.poll();
|
lines.poll();
|
||||||
lines.offer(line);
|
lines.offer(line);
|
||||||
|
Reference in New Issue
Block a user