@Override
    public String read() throws IOException {
        CharBuffer response = CharBuffer.allocate(bufferSize);
        StringBuilder result = new StringBuilder();

        do {
            response.clear();
            reader.read(response);
            result.append(response.array(), response.arrayOffset(), response.position());
        } while (response.get(response.position() - 1) != '\n');

        return result.toString();
    }
@Test
    public void testSlowResponse() throws Exception {
        String response =
                "{\"jsonrpc\":\"2.0\",\"id\":1,"
                        + "\"result\":\"Geth/v1.5.4-stable-b70acf3c/darwin/go1.7.3\"}\n";
        unixDomainSocket = new UnixDomainSocket(reader, writer, response.length());
        final LinkedList<String> segments = new LinkedList<>();
        // 1st part of response
        segments.add(response.substring(0, 50));
        // rest of response
        segments.add(response.substring(50));
        doAnswer(
                        invocation -> {
                            String segment = segments.poll();
                            if (segment == null) {
                                return 0;
                            } else {
                                Object[] args = invocation.getArguments();
                                ((CharBuffer) args[0]).append(segment);
                                return segment.length();
                            }
                        })
                .when(reader)
                .read(any(CharBuffer.class));

        IpcService ipcService =
                new IpcService() {
                    @Override
                    protected IOFacade getIO() {
                        return unixDomainSocket;
                    }
                };
        ipcService.send(new Request(), Web3ClientVersion.class);
    }