public int read()

in common/src/main/java/org/mvndaemon/mvnd/common/DaemonConnection.java [179:216]


        public int read(byte[] dest, int offset, int max) throws IOException {
            if (max == 0) {
                return 0;
            }

            if (buffer.remaining() == 0) {
                try {
                    selector.select();
                } catch (ClosedSelectorException e) {
                    return -1;
                }
                if (!selector.isOpen()) {
                    return -1;
                }

                BufferCaster.cast(buffer).clear();
                int nread;
                try {
                    nread = socket.read(buffer);
                } catch (IOException e) {
                    if (isEndOfStream(e)) {
                        BufferCaster.cast(buffer).position(0);
                        BufferCaster.cast(buffer).limit(0);
                        return -1;
                    }
                    throw e;
                }
                BufferCaster.cast(buffer).flip();

                if (nread < 0) {
                    return -1;
                }
            }

            int count = Math.min(buffer.remaining(), max);
            buffer.get(dest, offset, count);
            return count;
        }