private ChannelFuture finishEncode(final ChannelHandlerContext ctx, ChannelPromise promise) { if (finished) { promise.setSuccess(); return promise; } finished = true; final ByteBuf footer = ctx.alloc().buffer(); closeBlock(footer); final int streamCRC = this.streamCRC; final Bzip2BitWriter writer = this.writer; try { writer.writeBits(footer, 24, END_OF_STREAM_MAGIC_1); writer.writeBits(footer, 24, END_OF_STREAM_MAGIC_2); writer.writeInt(footer, streamCRC); writer.flush(footer); } finally { blockCompressor = null; } return ctx.writeAndFlush(footer, promise); }
final int mtfAlphabetSize = this.mtfAlphabetSize; writer.writeBits(out, 3, totalTables); writer.writeBits(out, 15, totalSelectors); writer.writeUnary(out, selectorMTF.valueToFront(selector)); int currentLength = tableLengths[0]; writer.writeBits(out, 5, currentLength); int delta = Math.abs(codeLength - currentLength); while (delta-- > 0) { writer.writeBits(out, 2, value); writer.writeBoolean(out, false); currentLength = codeLength;
writer.writeBits(out, 24, BLOCK_HEADER_MAGIC_1); writer.writeBits(out, 24, BLOCK_HEADER_MAGIC_2); writer.writeInt(out, crc.getCRC()); writer.writeBoolean(out, false); // Randomised block flag. We never create randomised blocks writer.writeBits(out, 24, bwtStartPointer);
/** * Writes an integer as 32 bits to the output {@link ByteBuf}. * @param value The integer to write */ void writeInt(ByteBuf out, final int value) { writeBits(out, 32, value); }
/** * Writes a zero-terminated unary number to the output {@link ByteBuf}. * Example of the output for value = 6: {@code 1111110} * @param value The number of {@code 1} to write */ void writeUnary(ByteBuf out, int value) { if (value < 0) { throw new IllegalArgumentException("value: " + value + " (expected 0 or more)"); } while (value-- > 0) { writeBoolean(out, true); } writeBoolean(out, false); }
writer.writeBits(out, 24, BLOCK_HEADER_MAGIC_1); writer.writeBits(out, 24, BLOCK_HEADER_MAGIC_2); writer.writeInt(out, crc.getCRC()); writer.writeBoolean(out, false); // Randomised block flag. We never create randomised blocks writer.writeBits(out, 24, bwtStartPointer);
/** * Writes an integer as 32 bits to the output {@link ByteBuf}. * @param value The integer to write */ void writeInt(ByteBuf out, final int value) { writeBits(out, 32, value); }
/** * Write the Huffman symbol to output byte map. */ private void writeSymbolMap(ByteBuf out) { Bzip2BitWriter writer = this.writer; final boolean[] blockValuesPresent = this.blockValuesPresent; final boolean[] condensedInUse = new boolean[16]; for (int i = 0; i < condensedInUse.length; i++) { for (int j = 0, k = i << 4; j < HUFFMAN_SYMBOL_RANGE_SIZE; j++, k++) { if (blockValuesPresent[k]) { condensedInUse[i] = true; } } } for (boolean isCondensedInUse : condensedInUse) { writer.writeBoolean(out, isCondensedInUse); } for (int i = 0; i < condensedInUse.length; i++) { if (condensedInUse[i]) { for (int j = 0, k = i << 4; j < HUFFMAN_SYMBOL_RANGE_SIZE; j++, k++) { writer.writeBoolean(out, blockValuesPresent[k]); } } } }
private ChannelFuture finishEncode(final ChannelHandlerContext ctx, ChannelPromise promise) { if (finished) { promise.setSuccess(); return promise; } finished = true; final ByteBuf footer = ctx.alloc().buffer(); closeBlock(footer); final int streamCRC = this.streamCRC; final Bzip2BitWriter writer = this.writer; try { writer.writeBits(footer, 24, END_OF_STREAM_MAGIC_1); writer.writeBits(footer, 24, END_OF_STREAM_MAGIC_2); writer.writeInt(footer, streamCRC); writer.flush(footer); } finally { blockCompressor = null; } return ctx.writeAndFlush(footer, promise); }
writer.writeBits(out, 24, BLOCK_HEADER_MAGIC_1); writer.writeBits(out, 24, BLOCK_HEADER_MAGIC_2); writer.writeInt(out, crc.getCRC()); writer.writeBoolean(out, false); // Randomised block flag. We never create randomised blocks writer.writeBits(out, 24, bwtStartPointer);
final int mtfAlphabetSize = this.mtfAlphabetSize; writer.writeBits(out, 3, totalTables); writer.writeBits(out, 15, totalSelectors); writer.writeUnary(out, selectorMTF.valueToFront(selector)); int currentLength = tableLengths[0]; writer.writeBits(out, 5, currentLength); int delta = Math.abs(codeLength - currentLength); while (delta-- > 0) { writer.writeBits(out, 2, value); writer.writeBoolean(out, false); currentLength = codeLength;
/** * Writes an integer as 32 bits to the output {@link ByteBuf}. * @param value The integer to write */ void writeInt(ByteBuf out, final int value) { writeBits(out, 32, value); }
/** * Writes a zero-terminated unary number to the output {@link ByteBuf}. * Example of the output for value = 6: {@code 1111110} * @param value The number of {@code 1} to write */ void writeUnary(ByteBuf out, int value) { if (value < 0) { throw new IllegalArgumentException("value: " + value + " (expected 0 or more)"); } while (value-- > 0) { writeBoolean(out, true); } writeBoolean(out, false); }
private ChannelFuture finishEncode(final ChannelHandlerContext ctx, ChannelPromise promise) { if (finished) { promise.setSuccess(); return promise; } finished = true; final ByteBuf footer = ctx.alloc().buffer(); closeBlock(footer); final int streamCRC = this.streamCRC; final Bzip2BitWriter writer = this.writer; try { writer.writeBits(footer, 24, END_OF_STREAM_MAGIC_1); writer.writeBits(footer, 24, END_OF_STREAM_MAGIC_2); writer.writeInt(footer, streamCRC); writer.flush(footer); } finally { blockCompressor = null; } return ctx.writeAndFlush(footer, promise); }
writer.writeBits(out, 24, BLOCK_HEADER_MAGIC_1); writer.writeBits(out, 24, BLOCK_HEADER_MAGIC_2); writer.writeInt(out, crc.getCRC()); writer.writeBoolean(out, false); // Randomised block flag. We never create randomised blocks writer.writeBits(out, 24, bwtStartPointer);
final int mtfAlphabetSize = this.mtfAlphabetSize; writer.writeBits(out, 3, totalTables); writer.writeBits(out, 15, totalSelectors); writer.writeUnary(out, selectorMTF.valueToFront(selector)); int currentLength = tableLengths[0]; writer.writeBits(out, 5, currentLength); int delta = Math.abs(codeLength - currentLength); while (delta-- > 0) { writer.writeBits(out, 2, value); writer.writeBoolean(out, false); currentLength = codeLength;
/** * Writes out the encoded block data. */ private void writeBlockData(ByteBuf out) { final Bzip2BitWriter writer = this.writer; final int[][] huffmanMergedCodeSymbols = this.huffmanMergedCodeSymbols; final byte[] selectors = this.selectors; final char[] mtf = mtfBlock; final int mtfLength = this.mtfLength; int selectorIndex = 0; for (int mtfIndex = 0; mtfIndex < mtfLength;) { final int groupEnd = Math.min(mtfIndex + HUFFMAN_GROUP_RUN_LENGTH, mtfLength) - 1; final int[] tableMergedCodeSymbols = huffmanMergedCodeSymbols[selectors[selectorIndex++]]; while (mtfIndex <= groupEnd) { final int mergedCodeSymbol = tableMergedCodeSymbols[mtf[mtfIndex++]]; writer.writeBits(out, mergedCodeSymbol >>> 24, mergedCodeSymbol); } } }
/** * Write the Huffman symbol to output byte map. */ private void writeSymbolMap(ByteBuf out) { Bzip2BitWriter writer = this.writer; final boolean[] blockValuesPresent = this.blockValuesPresent; final boolean[] condensedInUse = new boolean[16]; for (int i = 0; i < condensedInUse.length; i++) { for (int j = 0, k = i << 4; j < HUFFMAN_SYMBOL_RANGE_SIZE; j++, k++) { if (blockValuesPresent[k]) { condensedInUse[i] = true; } } } for (boolean isCondensedInUse : condensedInUse) { writer.writeBoolean(out, isCondensedInUse); } for (int i = 0; i < condensedInUse.length; i++) { if (condensedInUse[i]) { for (int j = 0, k = i << 4; j < HUFFMAN_SYMBOL_RANGE_SIZE; j++, k++) { writer.writeBoolean(out, blockValuesPresent[k]); } } } }
private ChannelFuture finishEncode(final ChannelHandlerContext ctx, ChannelPromise promise) { if (finished) { promise.setSuccess(); return promise; } finished = true; final ByteBuf footer = ctx.alloc().buffer(); closeBlock(footer); final int streamCRC = this.streamCRC; final Bzip2BitWriter writer = this.writer; try { writer.writeBits(footer, 24, END_OF_STREAM_MAGIC_1); writer.writeBits(footer, 24, END_OF_STREAM_MAGIC_2); writer.writeInt(footer, streamCRC); writer.flush(footer); } finally { blockCompressor = null; } return ctx.writeAndFlush(footer, promise); }
writer.writeBits(out, 24, BLOCK_HEADER_MAGIC_1); writer.writeBits(out, 24, BLOCK_HEADER_MAGIC_2); writer.writeInt(out, crc.getCRC()); writer.writeBoolean(out, false); // Randomised block flag. We never create randomised blocks writer.writeBits(out, 24, bwtStartPointer);