Skip to content

Implementation of MantaSeekableByteChannel.read(ByteBuffer) is broken #468

Open
@dekobon

Description

@dekobon

Looking at our implementation of MantaSeekableByteChannel.read(ByteBuffer) it appears that we don't follow the API contract:

    public int read(final ByteBuffer dst) throws IOException {
        if (!open) {
            throw new ClosedChannelException();
        }

        final MantaObjectInputStream stream = connectOrGetResponse();
        final long size = size();

        if (position.get() >= size) {
            return EOF;
        }

        final byte[] buff = dst.array();
        final int bytesRead = stream.read(buff);

        position.addAndGet(bytesRead);

        return bytesRead;
    }

Interface documentation:

    /**
     * Reads a sequence of bytes from this channel into the given buffer.
     *
     * <p> Bytes are read starting at this channel's current position, and
     * then the position is updated with the number of bytes actually read.
     * Otherwise this method behaves exactly as specified in the {@link
     * ReadableByteChannel} interface.
     */

This method is not reading data into the supplied byte buffer at all. In the Java source code, many of the implementations that implement this method use the static method IOUtil.read. Within that implementation you can see that data is clearly being read into the ByteBuffer. Whereas in the MantaSeekableByteChannel implementation no data is being read into the ByteBuffer.

Metadata

Metadata

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions