private DocumentWriter newFolderWriter(final String id, final File file,
        final int offset) {
        final boolean root = isRoot(id);
        final DocumentWriter writer = newDocument(id);
        writer.setPrimaryType(NT_FOLDER);
        writer.addProperty(JCR_CREATED, factories().getDateFactory().create(
            file.lastModified()));
        writer.addProperty(JCR_CREATED_BY, null); // ignored
        final File[] children = file.listFiles(filenameFilter);
        long totalChildren = 0;
        int nextOffset = 0;
        for (int i = 0; i < children.length; i++) {
            final File child = children[i];
            // Only include as a child if we can access and read the file.
            // Permissions might prevent us from reading the file, and the file
            // might not exist if it is a broken symlink
            // (see MODE-1768 for details).
            if (child.exists() && child.canRead() &&
                (child.isFile() || child.isDirectory())) {
                // we need to count the total accessible children
                totalChildren++;
                // only add a child if it's in the current page
                if (i >= offset && i < offset + pageSize) {
                    // We use identifiers that contain the file/directory name
                    final String childName = child.getName();
                    final String childId =
                        root ? DELIMITER + childName : id + DELIMITER +
                            childName;
                    writer.addChild(childId, childName);
                    nextOffset = i + 1;
                }
            }
        }
        // if there are still accessible children add the next page
        if (nextOffset < totalChildren) {
            writer.addPage(id, nextOffset, pageSize, totalChildren);
        }
        return writer;
    }