akelday commented on a change in pull request #98: URL: https://github.com/apache/commons-compress/pull/98#discussion_r425640169
########## File path: src/main/java/org/apache/commons/compress/archivers/sevenz/HeaderChannelBuffer.java ########## @@ -0,0 +1,173 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ +package org.apache.commons.compress.archivers.sevenz; + +import org.apache.commons.compress.utils.IOUtils; + +import java.io.IOException; +import java.io.InputStream; +import java.nio.BufferUnderflowException; +import java.nio.ByteBuffer; +import java.nio.ByteOrder; +import java.nio.channels.Channels; +import java.nio.channels.ReadableByteChannel; +import java.util.zip.CRC32; + +/** + * Enables little-endian primitive type reads from a {@link ReadableByteChannel} + * or {@link InputStream}, internally using a paged-in {@link ByteBuffer}. + * <br> + * Access is serial only but does allow a + * virtual buffer capacity of {@code Long.MAX_VALUE}. + * If the requested capacity is within the maximum page size (default 16MiB) + * the buffer will be fully read and held in a {@link HeaderInMemoryBuffer}. + * + * @NotThreadSafe + * @since 1.21 + */ +class HeaderChannelBuffer implements HeaderBuffer { + private static final int DEFAULT_PAGE_MAX = 16_777_216; + // This must match the largest get<Element> (currently getLong) + private static final int MAX_GET_ELEMENT_SIZE = 8; + private final ReadableByteChannel channel; + private final ByteBuffer buffer; + private long remaining; + + private HeaderChannelBuffer(final ReadableByteChannel channel, final long capacity, final int maxPageBytes) { + this.channel = channel; + this.buffer = ByteBuffer.allocate(maxPageBytes).order(ByteOrder.LITTLE_ENDIAN); Review comment: Good point, easier to understand as well. Done. ---------------------------------------------------------------- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: [email protected]
