protected static void writesection(DrawStream out, Object[] o, int start, int count) {
    int s = start <= 0 ? 0 : (start > o.length ? o.length : start);
    int c = count <= 0 ? o.length : count;

    if (c > o.length) c = o.length;

    for (int i = 0; i < c && (i + s) < o.length; i++) out.write(o[s + i]);
  }
  /** @return a (parent) container with containers and items (sub-folders and items) */
  public static JUpnpContainer browseFolder(
      JUpnpContainer parent, AssetKey ref, DrawStream out, String mediaType, boolean countonly) {
    if (parent == null) parent = new JUpnpContainer(ref.getId(), ref, "", 0, mediaType);
    parent.parentID = parentCache.get(ref) == null ? "-1" : parentCache.get(ref);

    int count = 0;

    String dir = ref.getId();
    String lp = ref.getLocation().getLocalPath();
    if (lp != null && lp.length() > 0) {
      dir = lp + (lp.endsWith("/") || lp.endsWith("\\") ? "" : "/") + dir;
    }

    String parentID = ref.toUrlEncodedString();

    File f = new File(dir);
    File[] entries = f.listFiles();
    if (entries != null) {
      for (File entry : entries) {
        if (entry.isDirectory()) {
          count++;
          String d = entry.getName();
          AssetKey myref =
              new AssetKey("Folder", d, AssetLocation.mutantEnv(Agents.getMyHostName(), dir));
          JUpnpContainer cont = new JUpnpContainer(d, myref, parentID, 1, mediaType);
          parentCache.put(myref, parentID);
          out.write(cont);
          if (!countonly) parent.addContainer(cont);
        }
      }
    }

    // now list files...

    AssetLocation env = AssetLocation.mutantEnv(dir);
    AssetMap assets = null;
    if ("Movie".equals(mediaType)) assets = JavaAssetMgr.find("Movie", env, false);
    else if ("Music".equals(mediaType)) assets = JavaAssetMgr.find("Music", env, false);
    else if ("Photo".equals(mediaType)) assets = JavaAssetMgr.find("Photo", env, false);
    else assets = JavaAssetMgr.find("Movie", env, false);

    for (AssetBrief movie : assets.jvalues()) {
      movie.setParentID(parentID);
      parentCache.put(movie.getKey(), parentID);
      // res.add(movie.toUpnpItem(parentID));
      if (!countonly) parent.addItem(movie);
    }

    parent.childCount = count;

    return parent;
  }