private boolean rotateIfNecessary()

in src/main/java/org/apache/sling/sitemap/impl/SitemapGeneratorExecutor.java [324:351]


        private boolean rotateIfNecessary() throws IOException {
            // create a checkpoint before flushing the pending url.
            buffer.createCheckpoint();
            // flush the sitemap to write the last url to the underlying buffer
            currentSitemap.flush();
            // if the buffer size exceeds the limit (-10 bytes for the closing tag)
            if (buffer.size() + 10 > configuration.getMaxSize()) {
                // retain bytes of the last written url in a temporary buffer
                overflowBuffer.reset();
                IOUtils.copy(buffer.copyAfterCheckpoint(), overflowBuffer);
                // rollback the buffer to the checkpoint
                buffer.rollback();
                // decrease the url count as we effectively move one url
                currentSitemap.urlCount --;
                // close, write and rotate the sitemap
                rotateSitemap();
                // write the overflow
                currentSitemap.flush();
                IOUtils.copy(overflowBuffer.copy(), buffer);
                currentSitemap.urlCount ++;
                return true;
            } else if (currentSitemap.urlCount + 1 > configuration.getMaxEntries()) {
                rotateSitemap();
                return true;
            }

            return false;
        }