/** * Create a new file header block with the given uncompressed content. * The block will have RAW (no) compression and FILE_HEADER content type. * * @param rawContent the uncompressed content of the block * @return a new {@link Block} object */ public static Block createRawFileHeaderBlock(final byte[] rawContent) { return new Block(BlockContentType.FILE_HEADER, rawContent); }
@Override public String toString() { final byte[] uncompressed = getUncompressedContent(); final byte[] compressed = getCompressedContent(); final String raw = Arrays.toString(Arrays.copyOf(uncompressed, Math.min(5, uncompressed.length))); final String comp = Arrays.toString(Arrays.copyOf(compressed, Math.min(5, compressed.length))); return String.format("compression method=%s, content type=%s, id=%d, raw size=%d, compressed size=%d, raw=%s, comp=%s.", getCompressionMethod().name(), getContentType().name(), getContentId(), getUncompressedContentSize(), getCompressedContentSize(), raw, comp); } }
private void doWrite(final OutputStream outputStream) throws IOException { outputStream.write(getCompressionMethod().getMethodId()); outputStream.write(getContentType().getContentTypeId()); ITF8.writeUnsignedITF8(getContentId(), outputStream); ITF8.writeUnsignedITF8(getCompressedContentSize(), outputStream); ITF8.writeUnsignedITF8(getUncompressedContentSize(), outputStream); outputStream.write(getCompressedContent()); }
private void contentCheck(final Block actual, final byte[] expectedRaw, final byte[] expectedCompressed) { // raw and compressed data are equal to what was given Assert.assertEquals(actual.getUncompressedContent(), expectedRaw); Assert.assertEquals(actual.getUncompressedContentSize(), expectedRaw.length); Assert.assertEquals(actual.getCompressedContent(), expectedCompressed); Assert.assertEquals(actual.getCompressedContentSize(), expectedCompressed.length); }
public static void write(final int major, final Slice slice, final OutputStream outputStream) { slice.nofBlocks = 1 + slice.external.size() + (slice.embeddedRefBlock == null ? 0 : 1); { slice.contentIDs = new int[slice.external.size()]; final int i = 0; for (final int id : slice.external.keySet()) slice.contentIDs[i] = id; } slice.headerBlock = Block.createRawSliceHeaderBlock(createSliceHeaderBlockContent(major, slice)); slice.headerBlock.write(major, outputStream); slice.coreBlock.write(major, outputStream); for (final Block block : slice.external.values()) block.write(major, outputStream); }
private Block roundTrip(final Block in, final Version version) throws IOException { byte[] written; try (final ByteArrayOutputStream os = new ByteArrayOutputStream()) { in.write(version.major, os); written = os.toByteArray(); } try (final InputStream is = new ByteArrayInputStream(written)) { return Block.read(version.major, is); } }
@Test(dataProvider = "RoundTripTest") public void testFileHeaderBlockRoundTrips(final byte[] testData, final Version version) throws IOException { final Block fhBlock = Block.createRawFileHeaderBlock(testData); final Block rtBlock = roundTrip(fhBlock, version); contentCheck(rtBlock, testData, testData); }
@Test(dataProvider = "RoundTripTest") public void testSliceHeaderBlockRoundTrips(final byte[] testData, final Version version) throws IOException { final Block shBlock = Block.createRawSliceHeaderBlock(testData); final Block rtBlock = roundTrip(shBlock, version); contentCheck(rtBlock, testData, testData); }
@Test(dataProvider = "RoundTripTest") public void testCompressionHeaderBlockRoundTrips(final byte[] testData, final Version version) throws IOException { final Block chBlock = Block.createRawCompressionHeaderBlock(testData); final Block rtBlock = roundTrip(chBlock, version); contentCheck(rtBlock, testData, testData); }
@Test(dataProvider = "RoundTripTest") public void testCoreBlockRoundTrips(final byte[] testData, final Version version) throws IOException { final Block coreBlock = Block.createRawCoreDataBlock(testData); final Block rtBlock = roundTrip(coreBlock, version); contentCheck(rtBlock, testData, testData); }
@Override public String toString() { final byte[] uncompressed = getUncompressedContent(); final byte[] compressed = getCompressedContent(); final String raw = Arrays.toString(Arrays.copyOf(uncompressed, Math.min(5, uncompressed.length))); final String comp = Arrays.toString(Arrays.copyOf(compressed, Math.min(5, compressed.length))); return String.format("compression method=%s, content type=%s, id=%d, raw size=%d, compressed size=%d, raw=%s, comp=%s.", getCompressionMethod().name(), getContentType().name(), getContentId(), getUncompressedContentSize(), getCompressedContentSize(), raw, comp); } }
private void doWrite(final OutputStream outputStream) throws IOException { outputStream.write(getCompressionMethod().getMethodId()); outputStream.write(getContentType().getContentTypeId()); ITF8.writeUnsignedITF8(getContentId(), outputStream); ITF8.writeUnsignedITF8(getCompressedContentSize(), outputStream); ITF8.writeUnsignedITF8(getUncompressedContentSize(), outputStream); outputStream.write(getCompressedContent()); }
public static void write(final int major, final Slice slice, final OutputStream outputStream) throws IOException { slice.nofBlocks = 1 + slice.external.size() + (slice.embeddedRefBlock == null ? 0 : 1); { slice.contentIDs = new int[slice.external.size()]; final int i = 0; for (final int id : slice.external.keySet()) slice.contentIDs[i] = id; } slice.headerBlock = Block.createRawSliceHeaderBlock(createSliceHeaderBlockContent(major, slice)); slice.headerBlock.write(major, outputStream); slice.coreBlock.write(major, outputStream); for (final Block block : slice.external.values()) block.write(major, outputStream); }
/** * Create a new slice header block with the given uncompressed content. * The block will have RAW (no) compression and MAPPED_SLICE content type. * * @param rawContent the uncompressed content of the block * @return a new {@link Block} object */ public static Block createRawSliceHeaderBlock(final byte[] rawContent) { return new Block(BlockContentType.MAPPED_SLICE, rawContent); }
/** * Create a new core data block with the given uncompressed content. * The block will have RAW (no) compression and CORE content type. * * @param rawContent the uncompressed content of the block * @return a new {@link Block} object */ public static Block createRawCoreDataBlock(final byte[] rawContent) { return new Block(BlockContentType.CORE, rawContent); }
/** * Create a new file header block with the given uncompressed content. * The block will have RAW (no) compression and FILE_HEADER content type. * * @param rawContent the uncompressed content of the block * @return a new {@link Block} object */ public static Block createRawFileHeaderBlock(final byte[] rawContent) { return new Block(BlockContentType.FILE_HEADER, rawContent); }
/** * Create a new core data block with the given uncompressed content. * The block will have RAW (no) compression and CORE content type. * * @param rawContent the uncompressed content of the block * @return a new {@link Block} object */ public static Block createRawCoreDataBlock(final byte[] rawContent) { return new Block(BlockContentType.CORE, rawContent); }
/** * Create a new slice header block with the given uncompressed content. * The block will have RAW (no) compression and MAPPED_SLICE content type. * * @param rawContent the uncompressed content of the block * @return a new {@link Block} object */ public static Block createRawSliceHeaderBlock(final byte[] rawContent) { return new Block(BlockContentType.MAPPED_SLICE, rawContent); }
/** * Create a new compression header block with the given uncompressed content. * The block will have RAW (no) compression and COMPRESSION_HEADER content type. * * @param rawContent the uncompressed content of the block * @return a new {@link Block} object */ public static Block createRawCompressionHeaderBlock(final byte[] rawContent) { return new Block(BlockContentType.COMPRESSION_HEADER, rawContent); }
/** * Create a new compression header block with the given uncompressed content. * The block will have RAW (no) compression and COMPRESSION_HEADER content type. * * @param rawContent the uncompressed content of the block * @return a new {@link Block} object */ public static Block createRawCompressionHeaderBlock(final byte[] rawContent) { return new Block(BlockContentType.COMPRESSION_HEADER, rawContent); }