Example usage for org.apache.hadoop.hdfs DFSInputStream getFileLength

List of usage examples for org.apache.hadoop.hdfs DFSInputStream getFileLength

Introduction

In this page you can find the example usage for org.apache.hadoop.hdfs DFSInputStream getFileLength.

Prototype

public long getFileLength() 

Source Link

Usage

From source file:org.apache.mele.embedded.HadoopQueueEmbedded.java

License:Apache License

private boolean ackCheck() throws IOException {
    LOG.info("Starting ack check");
    BitSet bitSet = new BitSet();
    FileSystem fileSystem = null;
    try {//from   w  w w. j  a v  a2s  . co m
        _ackLock.lock();
        _ackOutputStream.close();
        fileSystem = newFileSystem(_file);
        FileStatus fileStatus = fileSystem.getFileStatus(_file);
        long dataLength = fileStatus.getLen();
        long totalAckLength = getTotalAckLength(fileSystem);
        if (!couldContainAllAcks(totalAckLength)) {
            LOG.info("Existing early [" + totalAckLength + "] because [" + totalAckLength % 12 + "]");
            return false;
        }
        for (Path ackFile : _ackFiles) {
            LOG.info("Starting ack check for file [" + ackFile + "]");
            DFSInputStream inputStream = null;
            try {
                inputStream = getDFS(fileSystem.open(ackFile));
                long length = inputStream.getFileLength();
                DataInputStream dataInputStream = new DataInputStream(inputStream);
                while (length > 0) {
                    int pos = (int) dataInputStream.readLong();
                    // @TODO check position
                    // 4 bytes for storing the length of the message
                    int len = dataInputStream.readInt() + 4;
                    bitSet.set(pos, pos + len);
                    length -= 12;
                }
                if (bitSet.cardinality() == dataLength) {
                    return true;
                }
            } finally {
                if (inputStream != null) {
                    inputStream.close();
                }
            }
        }
        return false;
    } finally {
        reopenAckFile(fileSystem);
        _ackLock.unlock();
        if (fileSystem != null) {
            fileSystem.close();
        }
    }
}

From source file:org.apache.mele.embedded.HadoopQueueEmbedded.java

License:Apache License

private long getTotalAckLength(FileSystem fileSystem) throws IOException {
    long size = 0;
    for (Path ackFile : _ackFiles) {
        DFSInputStream inputStream = getDFS(fileSystem.open(ackFile));
        size += inputStream.getFileLength();
        inputStream.close();/*ww w . ja  v  a 2 s  .  c  o  m*/
    }
    return size;
}