Skip to content

Enhance SkipBox to support skipping on non-FileChannel DataSource #483

@zhou-hao

Description

@zhou-hao

Currently, SkipBox relies on FileChannel-specific behavior to efficiently skip box content.
When the underlying DataSource is not backed by a FileChannel (e.g. streaming sources, in-memory sources, custom DataSource implementations), SkipBox cannot skip data efficiently and may fail or require full reads.

This limitation makes it difficult to use SkipBox in streaming or non-file-based scenarios.

throw new RuntimeException("Cannot skip box "+type+" if data source is not seekable");

Would the maintainers be open to adding this fallback mechanism to SkipBox to improve support for non-FileChannel data sources?

 long remaining = contentSize;
  ByteBuffer skipBuffer = ByteBuffer.allocate((int) Math.min(8192, remaining));
  while (remaining > 0) {
      skipBuffer.clear();
      if (remaining < skipBuffer.capacity()) {
          skipBuffer.limit((int) remaining);
      }
      int read = dataSource.read(skipBuffer);
      if (read < 0) {
          throw new EOFException("Unexpected end of stream while skipping mdat box, remaining: " + remaining);
      }
      remaining -= read;
  }

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions