Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
Copyright (C) 2011 the original author or authors. See the file distributed with this work for additional information regarding copyright ownership. Licensed 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 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.iq80.leveldb.table;
import static org.iq80.leveldb.CompressionType.SNAPPY;
public class FileChannelTable extends Table
    public FileChannelTable(String nameFileChannel fileChannelComparator<Slicecomparatorboolean verifyChecksums)
            throws IOException
    protected Footer init() throws IOException {
        long size = .size();
        ByteBuffer footerData = read(size - ..);
        return Footer.readFooter(Slices.copiedBuffer(footerData));
    protected Block readBlock(BlockHandle blockHandle)
            throws IOException
        // read block trailer
        ByteBuffer trailerData = read(blockHandle.getOffset() + blockHandle.getDataSize(), .);
        BlockTrailer blockTrailer = BlockTrailer.readBlockTrailer(Slices.copiedBuffer(trailerData));
// todo re-enable crc check when ported to support direct buffers
//        // only verify check sums if explicitly asked by the user
//        if (verifyChecksums) {
//            // checksum data and the compression type in the trailer
//            PureJavaCrc32C checksum = new PureJavaCrc32C();
//            checksum.update(data.getRawArray(), data.getRawOffset(), blockHandle.getDataSize() + 1);
//            int actualCrc32c = checksum.getMaskedValue();
//            Preconditions.checkState(blockTrailer.getCrc32c() == actualCrc32c, "Block corrupted: checksum mismatch");
//        }
        // decompress data
        ByteBuffer uncompressedBuffer = read(blockHandle.getOffset(), blockHandle.getDataSize());
        Slice uncompressedData;
        if (blockTrailer.getCompressionType() == ) {
            synchronized (FileChannelTable.class) {
                int uncompressedLength = uncompressedLength(uncompressedBuffer);
                if (.capacity() < uncompressedLength) {
                     = ByteBuffer.allocateDirect(uncompressedLength);
                uncompressedData = Slices.copiedBuffer();
        else {
            uncompressedData = Slices.copiedBuffer(uncompressedBuffer);
        return new Block(uncompressedData);
    private ByteBuffer read(long offsetint lengththrows IOException {
        ByteBuffer uncompressedBuffer = ByteBuffer.allocate(length);
        ifuncompressedBuffer.hasRemaining() ) {
            throw new IOException("Could not read all the data");
        return uncompressedBuffer;
New to GrepCode? Check out our FAQ X