FileDocCategorySizeDatePackage
ChannelHelper.javaAPI Docmp4parser 1.0-RC-172750Wed Dec 19 20:10:38 GMT 2012com.coremedia.iso

ChannelHelper

public class ChannelHelper extends Object

Fields Summary
Constructors Summary
Methods Summary
public static voidclose(java.nio.channels.SelectionKey key)

        try {
            key.channel().close();
        } catch (IOException e) {
            // nop
        }

    
public static java.nio.ByteBufferreadFully(java.nio.channels.ReadableByteChannel channel, long size)


        if (channel instanceof FileChannel && size > 1024 * 1024) {
            ByteBuffer bb = ((FileChannel) channel).map(FileChannel.MapMode.READ_ONLY, ((FileChannel) channel).position(), size);
            ((FileChannel) channel).position(((FileChannel) channel).position() + size);
            return bb;
        } else {
            ByteBuffer buf = ByteBuffer.allocate(l2i(size));
            readFully(channel, buf, buf.limit());
            buf.rewind();
            assert buf.limit() == size;

            return buf;
        }

    
public static voidreadFully(java.nio.channels.ReadableByteChannel channel, java.nio.ByteBuffer buf)

        readFully(channel, buf, buf.remaining());
    
public static intreadFully(java.nio.channels.ReadableByteChannel channel, java.nio.ByteBuffer buf, int length)

        int n, count = 0;
        while (-1 != (n = channel.read(buf))) {
            count += n;
            if (count == length) {
                break;
            }
        }
        if (n == -1) {
            throw new EOFException("End of file. No more boxes.");
        }
        return count;
    
public static voidwriteFully(java.nio.channels.WritableByteChannel channel, java.nio.ByteBuffer buf)

        do {
            int written = channel.write(buf);
            if (written < 0) {
                throw new EOFException();
            }
        } while (buf.hasRemaining());