Example usage for org.apache.cassandra.io FSReadError FSReadError

List of usage examples for org.apache.cassandra.io FSReadError FSReadError

Introduction

In this page you can find the example usage for org.apache.cassandra.io FSReadError FSReadError.

Prototype

public FSReadError(Throwable cause, String path) 

Source Link

Usage

From source file:com.fullcontact.cassandra.io.compress.CompressedRandomAccessReader.java

License:Apache License

@Override
protected void reBuffer() {
    CompressionMetadata.Chunk chunk = metadata.chunkFor(current);
    try {//from  w  ww  .  j  a v  a  2s.  com
        decompressChunk(chunk);
    } catch (CorruptBlockException e) {
        throw new CorruptSSTableException(e, getPath());
    } catch (IOException e) {
        throw new FSReadError(e, getPath());
    }
}

From source file:com.fullcontact.cassandra.io.compress.CompressionMetadata.java

License:Apache License

/**
 * Read offsets of the individual chunks from the given input.
 *
 * @param input Source of the data.//from w  w w.  j a va 2  s .  com
 * @return collection of the chunk offsets.
 */
private Memory readChunkOffsets(DataInput input) {
    try {
        int chunkCount = input.readInt();
        Memory offsets = Memory.allocate(chunkCount * 8);

        for (int i = 0; i < chunkCount; i++) {
            try {
                offsets.setLong(i * 8, input.readLong());
            } catch (EOFException e) {
                String msg = String.format("Corrupted Index File %s: read %d but expected %d chunks.",
                        indexFilePath, i, chunkCount);
                throw new CorruptSSTableException(new IOException(msg, e), indexFilePath);
            }
        }

        return offsets;
    } catch (IOException e) {
        throw new FSReadError(e, indexFilePath);
    }
}

From source file:com.fullcontact.cassandra.io.util.RandomAccessReader.java

License:Apache License

protected RandomAccessReader(Path file, int bufferSize, boolean skipIOCache, PoolingSegmentedFile owner,
        FileSystem fs) throws FileNotFoundException {
    inputPath = file;//from   w ww. j  av a2  s . com
    try {
        inputFileStatus = fs.getFileStatus(inputPath);
    } catch (IOException e) {
        throw new RuntimeException(e);
    }

    this.fs = fs;

    try {
        this.input = fs.open(file);
    } catch (IOException e) {
        throw new RuntimeException(e);
    }

    this.owner = owner;

    filePath = file.toString();

    // allocating required size of the buffer
    if (bufferSize <= 0)
        throw new IllegalArgumentException("bufferSize must be positive");
    buffer = new byte[bufferSize];

    this.skipIOCache = skipIOCache;

    // we can cache file length in read-only mode
    try {
        fileLength = fs.getFileStatus(file).getLen();
    } catch (IOException e) {
        throw new FSReadError(e, filePath);
    }
    validBufferBytes = -1; // that will trigger reBuffer() on demand by read/seek operations
}

From source file:com.fullcontact.cassandra.io.util.RandomAccessReader.java

License:Apache License

/**
 * Read data from file starting from current currentOffset to populate buffer.
 *//*from  www .j a v a  2  s .  c  om*/
protected void reBuffer() {
    resetBuffer();

    try {
        if (bufferOffset >= fs.getFileStatus(inputPath).getLen()) // TODO: is this equivalent?
            return;

        input.seek(bufferOffset);

        int read = 0;

        while (read < buffer.length) {
            int n = input.read(buffer, read, buffer.length - read);
            if (n < 0)
                break;
            read += n;
        }

        validBufferBytes = read;
        bytesSinceCacheFlush += read;
    } catch (IOException e) {
        throw new FSReadError(e, filePath);
    }
}

From source file:com.fullcontact.cassandra.io.util.RandomAccessReader.java

License:Apache License

public void deallocate() {
    buffer = null; // makes sure we don't use this after it's ostensibly closed

    try {// w w w  . j  a  va 2  s .  c o m
        input.close();
    } catch (IOException e) {
        throw new FSReadError(e, filePath);
    }
}

From source file:com.fullcontact.cassandra.io.util.RandomAccessReader.java

License:Apache License

public ByteBuffer readBytes(int length) throws EOFException {
    assert length >= 0 : "buffer length should not be negative: " + length;

    byte[] buff = new byte[length];

    try {// ww w.  j  a  va 2 s. com
        readFully(buff); // reading data buffer
    } catch (EOFException e) {
        throw e;
    } catch (IOException e) {
        throw new FSReadError(e, filePath);
    }

    return ByteBuffer.wrap(buff);
}