/** * Writes the bits represented by a bit string to the buffer. * * @throws IllegalArgumentException If any characters other than * '0' and '1' appear in the string. */ public void writeBits(String bitString) throws IOException { if (bitString == null) { throw new IllegalArgumentException("Bit string cannot be null"); } for (char c : bitString.toCharArray()) { if (c == '1') { writeBits(1, 1); } else if (c == '0') { writeBits(0, 1); } else { throw new IllegalArgumentException( "Found illegal character '" + c + "'; write terminated"); } } }
/** * Writes the bits represented by a bit string to the buffer. * * @param bitString a string of '0' and/or '1' characters representing * bits to be written. Each character in the string results * in a call to {@link #writeBits(int, int)} * that writes 1 bit. * @throws IllegalArgumentException If any characters other than * '0' and '1' appear in the string. * @throws IOException if writing fails for any other reason */ public void writeBits(String bitString) throws IOException { if (bitString == null) { throw new IllegalArgumentException("Bit string cannot be null"); } for (char c : bitString.toCharArray()) { if (c == '1') { writeBits(1, 1); } else if (c == '0') { writeBits(0, 1); } else { throw new IllegalArgumentException( "Found illegal character '" + c + "'; write terminated"); } } }