public static ByteBufferWriter of(FSDataOutputStream ouput, Closeable close) throws IOException {
        return new ByteBufferWriter() {
            String name;

            @Override
            public void write(ByteBuffer src) throws IOException {
                try {
                    IOUtil.writeFully(ouput, src);
                } catch (Exception e) {
                    throw new IOException(String.format("name: %s", name), e);
                }
            }

            @Override
            public void flush() throws IOException {
                ouput.hflush();
            }

            @Override
            public void close() throws IOException {
                if (close != null) {
                    close.close();
                }
            }

            @Override
            public void setName(String name) {
                this.name = name;
            }
        };
    }
Open a writer with known incomming data size.
indexr-common/src/main/java/io/indexr/io/ByteBufferWriter.java