public void write(byte b) throws IOException {
		if (!(b == 0 || b == 1))
			throw new IllegalArgumentException("Argument must be 0 or 1");
		currentByte = (byte)(currentByte << 1 | b);  // shift will implicitly convert byte to int!!!
		numBitsInCurrentByte++;
		if (numBitsInCurrentByte == 8) {
			output.write(currentByte);
			numBitsInCurrentByte = 0;
			currentByte = (byte) 0;
		}
	}