aboutsummaryrefslogtreecommitdiff
path: root/moaSig/moa-sig-lib/src/main/java/at/gv/egovernment/moa/spss/util/FilteredOutputStream.java
diff options
context:
space:
mode:
authorAndreas Fitzek <andreas.fitzek@iaik.tugraz.at>2015-12-04 13:12:24 +0100
committerAndreas Fitzek <andreas.fitzek@iaik.tugraz.at>2015-12-04 13:12:24 +0100
commit7510ab5173001711ecb5d6c8834878e7cce63ff9 (patch)
treee07bba24e87b9b3d1e8d8275c68809a59c3e067d /moaSig/moa-sig-lib/src/main/java/at/gv/egovernment/moa/spss/util/FilteredOutputStream.java
parent191ba3411f2db0a48ae8d4243926b33a063bf769 (diff)
downloadmoa-sig-7510ab5173001711ecb5d6c8834878e7cce63ff9.tar.gz
moa-sig-7510ab5173001711ecb5d6c8834878e7cce63ff9.tar.bz2
moa-sig-7510ab5173001711ecb5d6c8834878e7cce63ff9.zip
CMS verification
Diffstat (limited to 'moaSig/moa-sig-lib/src/main/java/at/gv/egovernment/moa/spss/util/FilteredOutputStream.java')
-rw-r--r--moaSig/moa-sig-lib/src/main/java/at/gv/egovernment/moa/spss/util/FilteredOutputStream.java76
1 files changed, 76 insertions, 0 deletions
diff --git a/moaSig/moa-sig-lib/src/main/java/at/gv/egovernment/moa/spss/util/FilteredOutputStream.java b/moaSig/moa-sig-lib/src/main/java/at/gv/egovernment/moa/spss/util/FilteredOutputStream.java
new file mode 100644
index 0000000..3a9fe51
--- /dev/null
+++ b/moaSig/moa-sig-lib/src/main/java/at/gv/egovernment/moa/spss/util/FilteredOutputStream.java
@@ -0,0 +1,76 @@
+package at.gv.egovernment.moa.spss.util;
+
+import java.io.BufferedOutputStream;
+import java.io.IOException;
+import java.io.OutputStream;
+import java.math.BigDecimal;
+
+public class FilteredOutputStream extends BufferedOutputStream {
+ private BigDecimal from = null;
+ private BigDecimal to = null;
+ private BigDecimal counter = new BigDecimal("0");
+ BigDecimal one = new BigDecimal("1");
+
+ public FilteredOutputStream(OutputStream innerStream,
+ int bufferSize, BigDecimal from,
+ BigDecimal to) {
+ super(innerStream, bufferSize);
+ this.from = from;
+ this.to = to;
+ }
+
+ @Override
+ public synchronized void write(int b) throws IOException {
+ if(!inRange(counter)) {
+ super.write(b);
+ }
+ counter = counter.add(one);
+ }
+
+ @Override
+ public synchronized void write(byte[] b, int off, int len) throws IOException {
+ this.filteredWrite(b, off, len);
+ }
+
+ @Override
+ public synchronized void flush() throws IOException {
+ super.flush();
+ }
+
+ @Override
+ public void write(byte[] b) throws IOException {
+ if(b != null) {
+ this.filteredWrite(b, 0, b.length);
+ }
+ }
+
+ @Override
+ public void close() throws IOException {
+ super.close();
+ }
+
+ private synchronized void filteredWrite(byte[] b, int off, int len) throws IOException {
+ for(int i = 0; i < len; i++) {
+ if(!inRange(counter)) {
+ super.write(b[off+i]);
+ }
+ counter = counter.add(one);
+ }
+ }
+
+ private boolean inRange(BigDecimal counter) {
+ if ( (from == null) || (to == null))
+ return false;
+
+ int compare = counter.compareTo(from);
+ if (compare == -1)
+ return false;
+ else {
+ compare = counter.compareTo(to);
+ if (compare == 1)
+ return false;
+ else
+ return true;
+ }
+ }
+}