@Override public int read(byte[] b, int off, int len) throws IOException { if (len <= 0) { return 0; } while (true) { if (buffer == null) { try { buffer = nextBuffer(); } catch (IllegalStateException e) { String msg = DataUtils.formatMessage( DataUtils.ERROR_BLOCK_NOT_FOUND, "Block not found in id {0}", Arrays.toString(idBuffer.array())); throw new IOException(msg, e); } if (buffer == null) { return -1; } } int result = buffer.read(b, off, len); if (result > 0) { pos += result; return result; } buffer = null; } }