Example usage for org.apache.cassandra.utils ByteBufferUtil inputStream

List of usage examples for org.apache.cassandra.utils ByteBufferUtil inputStream

Introduction

In this page you can find the example usage for org.apache.cassandra.utils ByteBufferUtil inputStream.

Prototype

public static InputStream inputStream(ByteBuffer bytes) 

Source Link

Usage

From source file:org.apache.lucene.cassandra.fs.CassandraFileSystemThriftStore.java

License:Apache License

private synchronized InputStream getInputStream(ByteBuffer bb) throws IOException {

    ByteBuffer output = null;//w  w w  .j  a v  a2 s . co m

    if (compressedData == null || compressedData.capacity() < bb.remaining())
        compressedData = ByteBuffer.allocateDirect(bb.remaining());

    compressedData.limit(compressedData.capacity());
    compressedData.rewind();
    compressedData.put(bb.duplicate());
    compressedData.limit(compressedData.position());
    compressedData.rewind();

    if (Snappy.isValidCompressedBuffer(compressedData)) {

        int uncompressedLength = Snappy.uncompressedLength(compressedData);

        if (uncompressedData == null || uncompressedData.capacity() < uncompressedLength) {
            uncompressedData = ByteBuffer.allocateDirect(uncompressedLength);
        }

        int len = Snappy.uncompress(compressedData, uncompressedData);

        uncompressedData.limit(len);
        uncompressedData.rewind();

        output = uncompressedData;
    } else {
        output = compressedData;
    }

    return ByteBufferUtil.inputStream(output);
}

From source file:org.apache.lucene.cassandra.fs.CassandraFileSystemThriftStore.java

License:Apache License

private InputStream readLocalBlock(LocalBlock blockInfo) throws IOException {

    if (blockInfo.file == null)
        throw new RuntimeException("Local file name is not defined");

    if (blockInfo.length == 0)
        return ByteBufferUtil.inputStream(ByteBufferUtil.EMPTY_BYTE_BUFFER);

    RandomAccessFile raf = null;/*from w w  w  .j  a v  a2 s.  c om*/
    try {
        raf = new RandomAccessFile(blockInfo.file, "r");

        if (logger.isDebugEnabled())
            logger.debug("Mmapping " + blockInfo.length + " bytes");

        MappedByteBuffer bb = raf.getChannel().map(FileChannel.MapMode.READ_ONLY, blockInfo.offset,
                blockInfo.length);

        return getInputStream(bb);

    } catch (FileNotFoundException e) {
        throw new RuntimeException("Local file does not exist: " + blockInfo.file);
    } catch (IOException e) {
        throw new RuntimeException(String.format("Unable to mmap block %s[%d,%d]", blockInfo.file,
                blockInfo.length, blockInfo.offset), e);
    } finally {
        FileUtils.closeQuietly(raf);
    }

}

From source file:org.apache.lucene.cassandra.fs.CassandraFileSystemThriftStore.java

License:Apache License

public INode retrieveINode(Path path) throws IOException {
    ByteBuffer pathKey = getPathKey(path);
    ColumnOrSuperColumn pathInfo;// ww w . ja  va2  s.c  o  m

    pathInfo = performGet(pathKey, inodeDataPath, consistencyLevelRead);

    // If not found and I already tried with CL= ONE, retry with higher CL.
    if (pathInfo == null && consistencyLevelRead.equals(ConsistencyLevel.ONE)) {
        pathInfo = performGet(pathKey, inodeDataPath, ConsistencyLevel.QUORUM);
    }

    if (pathInfo == null) {
        // Now give up and return null.
        return null;
    }

    return INode.deserialize(ByteBufferUtil.inputStream(pathInfo.column.value), pathInfo.column.getTimestamp());
}