public FileStream(RandomAccessFile source) throws OggFormatException, IOException {
        this.source = source;

        ArrayList<Long> po = new ArrayList<>();
        int pageNumber = 0;
        try {
            while (true) {
                po.add(this.source.getFilePointer());

                // skip data if pageNumber>0
                OggPage op = getNextPage(pageNumber > 0);
                if (op == null) {
                    break;
                }

                LogicalOggStreamImpl los = (LogicalOggStreamImpl) getLogicalStream(op
                        .getStreamSerialNumber());
                if (los == null) {
                    los = new LogicalOggStreamImpl(this);
                    logicalStreams.put(op.getStreamSerialNumber(), los);
                }

                if (pageNumber == 0) {
                    los.checkFormat(op);
                }

                los.addPageNumberMapping(pageNumber);
                los.addGranulePosition(op.getAbsoluteGranulePosition());

                if (pageNumber > 0) {
                    this.source.seek(this.source.getFilePointer() + op.getTotalLength());
                }

                pageNumber++;
            }
        } catch (EndOfOggStreamException e) {
            // ok
        } catch (IOException e) {
            throw e;
        }
        // System.out.println("pageNumber: "+pageNumber);
        this.source.seek(0L);
        pageOffsets = new long[po.size()];
        int i = 0;
        for (Long next : po) {
            pageOffsets[i++] = next;
        }
    }