Search in sources :

Example 1 with DiskReader

use of com.bonree.brfs.disknode.DiskReader in project BRFS by zhangnianli.

the class ReadMessageHandler method handle.

@Override
public void handle(DiskMessage msg, HandleResultCallback callback) {
    HandleResult result = new HandleResult();
    try {
        String offsetParam = msg.getParams().get(PARAM_READ_OFFSET);
        String lengthParam = msg.getParams().get(PARAM_READ_LENGTH);
        int offset = offsetParam == null ? 0 : Integer.parseInt(offsetParam);
        int length = lengthParam == null ? Integer.MAX_VALUE : Integer.parseInt(lengthParam);
        DiskReader reader = new DiskReader(msg.getFilePath());
        byte[] data = reader.read(offset, length);
        result.setSuccess(true);
        result.setData(data);
    } catch (IOException e) {
        result.setSuccess(false);
        result.setCause(e);
    } finally {
        callback.completed(result);
    }
}
Also used : HandleResult(com.bonree.brfs.disknode.server.handler.HandleResult) IOException(java.io.IOException) DiskReader(com.bonree.brfs.disknode.DiskReader)

Aggregations

DiskReader (com.bonree.brfs.disknode.DiskReader)1 HandleResult (com.bonree.brfs.disknode.server.handler.HandleResult)1 IOException (java.io.IOException)1