mirror of
https://github.com/eclipse-sailing-analytics/sailing-analytics.git
synced 2026-10-15 08:41:01 +00:00
Moved CountingOutputStream from a GWT/Java bundle (com.sapsailing.domain.common) to a pure java bundle due to GWT compile problems in the Eclipse IDE
This commit is contained in:
1 parent
8d309ddf91
commit
16df463800
2 files changed
+1
-2
No files matched your search
+54
@@ -0,0 +1,54 @@
|
||||
package com.sap.sailing.server.replication.impl;
|
||||
|
||||
import java.io.FilterOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.OutputStream;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
public class CountingOutputStream extends FilterOutputStream {
|
||||
private static final Logger logger = Logger.getLogger(CountingOutputStream.class.getName());
|
||||
|
||||
private long count;
|
||||
private final long logEveryHowManyBytes;
|
||||
private long lastMultiple;
|
||||
private final Level level;
|
||||
private final String name;
|
||||
|
||||
public CountingOutputStream(OutputStream out, long logEveryHowManyBytes, Level logLevel, String name) {
|
||||
super(out);
|
||||
this.level = logLevel;
|
||||
this.name = name;
|
||||
this.logEveryHowManyBytes = logEveryHowManyBytes;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(int b) throws IOException {
|
||||
super.write(b);
|
||||
count(1);
|
||||
}
|
||||
|
||||
private void count(int bytesWritten) {
|
||||
count += bytesWritten;
|
||||
if (count >= (lastMultiple+1)*logEveryHowManyBytes) {
|
||||
lastMultiple++;
|
||||
log();
|
||||
}
|
||||
}
|
||||
|
||||
private void log() {
|
||||
logger.log(level, "wrote "+count+" bytes to "+name);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(byte[] b) throws IOException {
|
||||
super.write(b);
|
||||
count(b.length);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(byte[] b, int off, int len) throws IOException {
|
||||
super.write(b, off, len);
|
||||
count(len);
|
||||
}
|
||||
}
|
||||
-1
@@ -17,7 +17,6 @@ import javax.servlet.http.HttpServletResponse;
|
||||
import org.osgi.framework.BundleContext;
|
||||
import org.osgi.util.tracker.ServiceTracker;
|
||||
|
||||
import com.sap.sailing.domain.common.impl.CountingOutputStream;
|
||||
import com.sap.sailing.server.RacingEventService;
|
||||
import com.sap.sailing.server.gateway.SailingServerHttpServlet;
|
||||
import com.sap.sailing.server.replication.ReplicationService;
|
||||
|
||||
Reference in new issue
Block a user