1 9 10 package org.jboss.util.stream; 11 12 import java.io.ObjectOutputStream ; 13 import java.io.IOException ; 14 15 25 public class AutoResetObjectOutputStream 26 extends ObjectOutputStreamAdapter 27 { 28 29 protected int after; 31 32 protected int count; 34 44 public AutoResetObjectOutputStream(ObjectOutputStream out, int after) 45 throws IOException 46 { 47 super(out); 48 49 setResetAfter(after); 50 } 51 52 60 public void setResetAfter(int after) { 61 if (after <= 0) 62 throw new IllegalArgumentException ("after <= 0"); 63 64 this.after = after; 65 } 66 67 73 public final int getResetAfter() { 74 return after; 75 } 76 77 82 public final int getCount() { 83 return count; 84 } 85 86 94 protected void writeObjectOverride(Object obj) throws IOException { 95 super.writeObjectOverride(obj); 96 count++; 97 98 if (count >= after) { 99 reset(); 100 } 101 } 102 103 108 public void reset() throws IOException { 109 out.reset(); 110 count = 0; 111 } 112 } 113 | Popular Tags |