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

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

Introduction

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

Prototype

@Override
public synchronized void close() throws IOException 

Source Link

Document

Close it down!

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 {/*  www . ja  v  a 2s  .  c o 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();
    }//from  w ww.  jav  a 2s . c  o  m
    return size;
}