Source:
<code>public static FileTermination checkTermination(SeekableByteChannel channel) throws IOException { final long fileSize = channel.size(); if (fileSize < BlockCompressedStreamConstants.EMPTY_GZIP_BLOCK.length) { return FileTermination.DEFECTIVE; } channel.position(fileSize - BlockCompressedStreamConstants.EMPTY_GZIP_BLOCK.length); final ByteBuffer bytebuffer = ByteBuffer.allocate(BlockCompressedStreamConstants.EMPTY_GZIP_BLOCK.length); readFully(channel, bytebuffer); if (Arrays.equals(bytebuffer.array(), BlockCompressedStreamConstants.EMPTY_GZIP_BLOCK)) { return FileTermination.HAS_TERMINATOR_BLOCK; } final int bufsize = (int)Math.min(fileSize, BlockCompressedStreamConstants.MAX_COMPRESSED_BLOCK_SIZE); final byte[] buf = new byte[bufsize]; channel.position(fileSize - bufsize); readFully(channel, ByteBuffer.wrap(buf)); for (int i = buf.length - BlockCompressedStreamConstants.EMPTY_GZIP_BLOCK.length; i >= 0; --i) { if (!preambleEqual(BlockCompressedStreamConstants.GZIP_BLOCK_PREAMBLE, buf, i, BlockCompressedStreamConstants.GZIP_BLOCK_PREAMBLE.length)) { continue; } <START> final ByteBuffer byteBuffer = ByteBuffer.wrap(buf, i + BlockCompressedStreamConstants.GZIP_BLOCK_PREAMBLE.length, 4); <END> byteBuffer.order(ByteOrder.LITTLE_ENDIAN); final int totalBlockSizeMinusOne = byteBuffer.getShort() & 0xFFFF; if (buf.length - i == totalBlockSizeMinusOne + 1) { return FileTermination.HAS_HEALTHY_LAST_BLOCK; } else { return FileTermination.DEFECTIVE; } } return FileTermination.DEFECTIVE; }</code><technical_language>want change naming distinguish bytebuffer</technical_language>

Target:
public static FileTermination checkTermination(SeekableByteChannel channel) throws IOException { final long fileSize = channel.size(); if (fileSize < BlockCompressedStreamConstants.EMPTY_GZIP_BLOCK.length) { return FileTermination.DEFECTIVE; } final long initialPosition = channel.position(); boolean exceptionThrown = false; try { channel.position(fileSize - BlockCompressedStreamConstants.EMPTY_GZIP_BLOCK.length); final ByteBuffer lastBlockBuffer = ByteBuffer.allocate(BlockCompressedStreamConstants.EMPTY_GZIP_BLOCK.length); readFully(channel, lastBlockBuffer); if (Arrays.equals(lastBlockBuffer.array(), BlockCompressedStreamConstants.EMPTY_GZIP_BLOCK)) { return FileTermination.HAS_TERMINATOR_BLOCK; } final int bufsize = (int) Math.min(fileSize, BlockCompressedStreamConstants.MAX_COMPRESSED_BLOCK_SIZE); final byte[] bufferArray = new byte[bufsize]; channel.position(fileSize - bufsize); readFully(channel, ByteBuffer.wrap(bufferArray)); for (int i = bufferArray.length - BlockCompressedStreamConstants.EMPTY_GZIP_BLOCK.length; i >= 0; --i) { if (!preambleEqual(BlockCompressedStreamConstants.GZIP_BLOCK_PREAMBLE, bufferArray, i, BlockCompressedStreamConstants.GZIP_BLOCK_PREAMBLE.length)) { continue; } final ByteBuffer byteBuffer = ByteBuffer.wrap(bufferArray, i + BlockCompressedStreamConstants.GZIP_BLOCK_PREAMBLE.length, 4); byteBuffer.order(ByteOrder.LITTLE_ENDIAN); final int totalBlockSizeMinusOne = byteBuffer.getShort() & 0xFFFF; if (bufferArray.length - i == totalBlockSizeMinusOne + 1) { return FileTermination.HAS_HEALTHY_LAST_BLOCK; } else { return FileTermination.DEFECTIVE; } } return FileTermination.DEFECTIVE; } catch (final Throwable e) { exceptionThrown = true; throw e; } finally { if(!exceptionThrown) { channel.position(initialPosition); } } }