/** Constructs a new bit writer. */ public BitWriter() { writer = new ome.codecs.BitWriter(); }
/** Gets an array containing all bits written thus far. */ public byte[] toByteArray() { return this.writer.toByteArray(); }
/** * 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 write(String bitString) { this.writer.write(bitString); }
/** * The CodecOptions parameter must be an instance of * {@link HuffmanCodecOptions}, and should have the following fields set: * {@link HuffmanCodecOptions#table table} * {@link CodecOptions#bitsPerSample bitsPerSample} * {@link CodecOptions#maxBytes maxBytes} * * @see Codec#decompress(RandomAccessInputStream, CodecOptions) */ @Override public byte[] decompress(RandomAccessInputStream in, CodecOptions options) throws CodecException, IOException { if (in == null) throw new IllegalArgumentException("No data to decompress."); if (options == null || !(options instanceof HuffmanCodecOptions)) { throw new CodecException("Options must be an instance of " + "ome.codecs.HuffmanCodecOptions."); } HuffmanCodecOptions huffman = (HuffmanCodecOptions) options; int nSamples = (huffman.maxBytes * 8) / huffman.bitsPerSample; int bytesPerSample = huffman.bitsPerSample / 8; if ((huffman.bitsPerSample % 8) != 0) bytesPerSample++; BitWriter out = new BitWriter(); for (int i=0; i<nSamples; i++) { int sample = getSample(in, options); out.write(sample, bytesPerSample * 8); } return out.toByteArray(); }
/** Tests the BitWriter class. */ public static void main(String[] args) { ome.codecs.BitWriter.main(args); }
BitWriter out = new BitWriter(); for (int i=0; i<values.length; i++) out.write(values[i], bits[i]); BitBuffer bb = new BitBuffer(out.toByteArray()); for (int i=0; i<values.length; i++) { int value = bb.getBits(bits[i]); sb.append(r.nextInt(2)); out = new BitWriter(); LOGGER.info("Writing values to byte array"); out.write(sb.toString()); LOGGER.info("Reading values from byte array"); bb = new BitBuffer(out.toByteArray()); for (int i = 0; i < 5000; i++) { int value = bb.getBits(1);
/** Tests the BitWriter class. */ public static void main(String[] args) { ome.codecs.BitWriter.main(args); }
int[] nums = new int[trials]; int[] len = new int[trials]; BitWriter bw = new BitWriter(); int totallen = 0; bw.write(nums[i], len[i]); BitBuffer bb = new BitBuffer(bw.toByteArray()); int readint; LOGGER.info("Reading from BitBuffer"); bb = new BitBuffer(bw.toByteArray()); bb = new BitBuffer(bw.toByteArray()); for (int i = 0; i < trials; i++) { int c = r.nextInt(100);
/** * 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 write(String bitString) { this.writer.write(bitString); }
/** Constructs a new bit writer. */ public BitWriter() { writer = new ome.codecs.BitWriter(); }
/** Gets an array containing all bits written thus far. */ public byte[] toByteArray() { return this.writer.toByteArray(); }
/** Writes the given value using the given number of bits. */ public void write(int value, int numBits) { this.writer.write(value, numBits); }
/** Constructs a new bit writer with the given initial buffer size. */ public BitWriter(int size) { writer = new ome.codecs.BitWriter(size); }
/** Writes the given value using the given number of bits. */ public void write(int value, int numBits) { this.writer.write(value, numBits); }
/** Constructs a new bit writer with the given initial buffer size. */ public BitWriter(int size) { writer = new ome.codecs.BitWriter(size); }