nahuelbkn

Appendable

Jun 19th, 2020
140
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.13 KB | None | 0 0
  1. package json;
  2.  
  3. import java.io.DataOutputStream;
  4. import java.io.IOException;
  5. import java.io.ObjectOutputStream;
  6. import java.io.OutputStream;
  7.  
  8. public class AppendableObjectOutputStream extends ObjectOutputStream
  9. {
  10.       private boolean append;
  11.         private boolean initialized;
  12.         private DataOutputStream dout;
  13.  
  14.         protected AppendableObjectOutputStream(boolean append) throws IOException, SecurityException {
  15.             super();
  16.             this.append = append;
  17.             this.initialized = true;
  18.         }
  19.  
  20.         public AppendableObjectOutputStream(OutputStream out, boolean append) throws IOException {
  21.             super(out);
  22.             this.append = append;
  23.             this.initialized = true;
  24.             this.dout = new DataOutputStream(out);
  25.             this.writeStreamHeader();
  26.         }
  27.  
  28.         @Override
  29.         protected void writeStreamHeader() throws IOException {
  30.             if (!this.initialized || this.append) return;
  31.             if (dout != null) {
  32.                 dout.writeShort(STREAM_MAGIC);
  33.                 dout.writeShort(STREAM_VERSION);
  34.             }
  35.         }
  36.  
  37.     }
Advertisement
Add Comment
Please, Sign In to add comment