001/*
002 * Copyright (C) 2012 eXo Platform SAS.
003 *
004 * This is free software; you can redistribute it and/or modify it
005 * under the terms of the GNU Lesser General Public License as
006 * published by the Free Software Foundation; either version 2.1 of
007 * the License, or (at your option) any later version.
008 *
009 * This software is distributed in the hope that it will be useful,
010 * but WITHOUT ANY WARRANTY; without even the implied warranty of
011 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
012 * Lesser General Public License for more details.
013 *
014 * You should have received a copy of the GNU Lesser General Public
015 * License along with this software; if not, write to the Free
016 * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
017 * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
018 */
019
020package org.crsh.vfs.spi;
021
022import java.io.IOException;
023import java.io.InputStream;
024import java.util.Iterator;
025
026/**
027 * <p>A driver for the file system, this interface is the Service Provider Interface (SPI) part
028 * provided by CRaSH.</p>
029 *
030 * <p>The driver works with handles which are opaque objects that model a path in the file system,
031 * an handle can represent a file or a directory and is considered as non modifiable from the file
032 * system perspective.</p>
033 *
034 * @param <H> the handle generic type.
035 */
036public interface FSDriver<H> {
037
038  /**
039   * Returns the root handle.
040   *
041   * @return the root handle
042   * @throws IOException any io exception
043   */
044  H root() throws IOException;
045
046  /**
047   * Returns the name of the handle.
048   *
049   * @param handle the handle
050   * @return the handle name
051   * @throws IOException any io exception
052   */
053  String name(H handle) throws IOException;
054
055  /**
056   * Returns true if the handle represent a directory.
057   *
058   * @param handle the handle
059   * @return true if the handle is a directory, false otherwise
060   * @throws IOException any io exception
061   */
062  boolean isDir(H handle) throws IOException;
063
064  /**
065   * Return the specific child of a directory handle, null should be returned if no such
066   * child exist.
067   *
068   * @param handle the directory handle
069   * @param name the child name
070   * @return the specified child
071   * @throws IOException any io exception
072   */
073  H child(H handle, String name) throws IOException;
074
075  /**
076   * Returns an iterable over the children of of a specific directory handle.
077   *
078   * @param handle the directory handle
079   * @return the children as an iterable
080   * @throws IOException any io exception
081   */
082  Iterable<H> children(H handle) throws IOException;
083
084  /**
085   * Return the last modified date timestamp of an handle.
086   *
087   * @param handle the handle
088   * @return the last modified timestamp
089   * @throws IOException any io exception
090   */
091  long getLastModified(H handle) throws IOException;
092
093  /**
094   * Return an iterator over the resources represented by the specified file handle.
095   *
096   * @param handle the file handle
097   * @return the iterator
098   * @throws IOException any io exception
099   */
100  Iterator<InputStream> open(H handle) throws IOException;
101
102}