code: @Override
  	public int writeBit(int bit) throws BitStreamException {
  		//TODO what is the correct behaviour here?
  		//throw EOBSE or return reduced count
  		if (position + bufferSize + 1 > size) throw new BitStreamException("array full");
  
  		if (bufferSize == 0) {
  			bufferBits = bit;
  			bufferSize = 1;
  		} else if (bufferSize + 1 <= 32) {
  			bufferBits = (bufferBits << 1) | bit & 1;
  			bufferSize ++;
  		} else {
  			flushBuffer();
  			bufferBits = bit;
  			bufferSize = 1;
  
  		}
  
  		return 1;
  	}
docs: bit writer methods