title: ByteArrayOutputStream or Binary Writer equivalent in Swift
body: <p>I wondering equivalent of Java <code>java.io.ByteArrayOutputStream</code> or C#'s <code>BinaryWriter</code> into Swift.</p>
  <p>Having some difficulties in the following <code>static public class CustomArrayOutputStream extends java.io.ByteArrayOutputStream</code> part. I wonder how to achieve the same functionalities in the Swift.</p>
  <p><strong>Swift Code</strong></p>
  <pre><code>public class CustomSerializer {
     fileprivate var output: CustomArrayOutputStream
  
     func custom_bool(value: Bool) {
        output.write(value == true ? 1 : 0)
     }
  }
  
  // Having difficulties to convert it to Swift
  static public class CustomArrayOutputStream : ?? {
      public func getBuffer() -&gt; [UInt8] {
          return buf
      }
  }
  </code></pre>
  <p><strong>Java Code:</strong></p>
  <pre><code>public class CustomSerializer {
     protected CustomArrayOutputStream output;
  
     public void custom_bool(Boolean value) {
        output.write(value.booleanValue() ? 1: 0);
     }
  }
  
  static public class CustomArrayOutputStream extends java.io.ByteArrayOutputStream {
      public byte[] getBuffer() {
          return buf;
      }
  }
  </code></pre>
  <p>or equivalent of <strong>C# BinaryWriter</strong> in Swift</p>
  <pre><code>protected readonly BinaryWriter output;
  </code></pre>
  <p><strong>Update:</strong></p>
  <p>The first case is to achieve something similar</p>
  <pre><code>var content:[UInt8] = output.getBuffer() 
  var size: Int = output.size() 
  </code></pre>
  <p>but <code>OutputStream</code> does not have <code>getBuffer()</code> and  <code>size()</code> do not exist.</p>
  <p>or</p>
  <p>the second use case, do not know how to convert the following Java into Swift</p>
  <p><strong>Java</strong></p>
  <pre><code>public int getOffset() {
      return (int)output.BaseStream.Position;
  }
  </code></pre>
  <p><strong>Swift</strong></p>
  <pre><code>public func getOffset() -&gt; Int {
      return output.???
  }
  </code></pre>