public DirectObjectPointer build() {
            if (bean == null && fileChannel == null && mappedByteBuffer == null) {
                throw new IllegalArgumentException("One of fromBean, fromFileChannel or fromMappedByteBuffer is mandatory");
            }

            DirectObjectPointer pointer = null;
            if (bean != null) {
                pointer = DirectObjectPointer.createFromBean(bean, directObjectContext != null ? directObjectContext : new DirectObjectContext());
            } else if (fileChannel != null) {
                try {
                    // read objSize
                    ByteBuffer tempBuffer = ByteBuffer.allocate(4).order(ByteOrder.nativeOrder());
                    fileChannel.read(tempBuffer);

                    tempBuffer.flip();
                    tempBuffer.position(0);
                    int objSize = tempBuffer.getInt();

                    pointer = DirectObjectPointer.createFromFileChannel(fileChannel, objSize);
                } catch (IOException e) {
                    throw new IllegalArgumentException("Cannot read from file channel", e);
                }
            } else if (mappedByteBuffer != null) {
                // read objSize
                int objSize = mappedByteBuffer.getInt();

                pointer = DirectObjectPointer.createFromMappedByteBuffer(mappedByteBuffer, objSize);
            }

            // autoclose option
            if (autoRelease) {
                pointer = new DirectObjectPointerAutoRelease(pointer.address);
            }

            return pointer;
        }