StreamLogger bug fix and added new line to JSONWriter flush function
This commit is contained in:
parent
e9715298b6
commit
f1e5e17d50
3 changed files with 18 additions and 24 deletions
|
|
@ -42,12 +42,12 @@ public class InputStreamLogger extends InputStream implements StreamLogger.LogCa
|
||||||
}
|
}
|
||||||
public int read(byte b[]) throws IOException {
|
public int read(byte b[]) throws IOException {
|
||||||
int n = in.read(b);
|
int n = in.read(b);
|
||||||
log.log(b, 0, b.length);
|
log.log(b, 0, n);
|
||||||
return n;
|
return n;
|
||||||
}
|
}
|
||||||
public int read(byte b[], int off, int len) throws IOException {
|
public int read(byte b[], int off, int len) throws IOException {
|
||||||
int n = in.read(b, off, len);
|
int n = in.read(b, off, len);
|
||||||
log.log(b, off, len);
|
log.log(b, off, n);
|
||||||
return n;
|
return n;
|
||||||
}
|
}
|
||||||
public long skip(long n) throws IOException {
|
public long skip(long n) throws IOException {
|
||||||
|
|
|
||||||
|
|
@ -30,7 +30,7 @@ public class StreamLogger {
|
||||||
|
|
||||||
|
|
||||||
protected void log(int n){
|
protected void log(int n){
|
||||||
if(n == DELIMETER)
|
if(n < 0 || n == DELIMETER)
|
||||||
flushLog();
|
flushLog();
|
||||||
else
|
else
|
||||||
buffer.append(n);
|
buffer.append(n);
|
||||||
|
|
@ -38,34 +38,27 @@ public class StreamLogger {
|
||||||
flushLog();
|
flushLog();
|
||||||
}
|
}
|
||||||
protected void log(byte[] b, int off, int len){
|
protected void log(byte[] b, int off, int len){
|
||||||
try {
|
|
||||||
if (logger.isLoggable()) {
|
if (logger.isLoggable()) {
|
||||||
for(int i=0; i<len; ++i){
|
for(int i=0; i<len; ++i){
|
||||||
if(b[off+i] == DELIMETER){
|
if(b[off+i] == DELIMETER)
|
||||||
buffer.append(new String(b, off, i, "UTF-8"));
|
|
||||||
flushLog();
|
flushLog();
|
||||||
off += i;
|
else
|
||||||
len -= i;
|
buffer.append((char)b[off+i]);
|
||||||
i = 0;
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
if(len > 0)
|
|
||||||
buffer.append(new String(b, off, len, "UTF-8"));
|
|
||||||
if(buffer.length() > MAX_BUFFER_SIZE)
|
if(buffer.length() > MAX_BUFFER_SIZE)
|
||||||
flushLog();
|
flushLog();
|
||||||
}
|
}
|
||||||
} catch (UnsupportedEncodingException e){
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void flushLog(){
|
protected void flushLog(){
|
||||||
|
if(buffer.length() > 0) {
|
||||||
if (prefix != null)
|
if (prefix != null)
|
||||||
logger.log(prefix + ": " + buffer.toString());
|
logger.log(prefix + ": " + buffer.toString());
|
||||||
else
|
else
|
||||||
logger.log(buffer.toString());
|
logger.log(buffer.toString());
|
||||||
clearLog();
|
clearLog();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
protected void clearLog(){
|
protected void clearLog(){
|
||||||
buffer.delete(0, buffer.length());
|
buffer.delete(0, buffer.length());
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -144,6 +144,7 @@ public class JSONWriter{
|
||||||
}
|
}
|
||||||
|
|
||||||
public void flush(){
|
public void flush(){
|
||||||
|
out.print("\n");
|
||||||
out.flush();
|
out.flush();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue