Package com.netfever.common.datasource.api

Examples of com.netfever.common.datasource.api.IFile


  public String getMime(String name) throws StorageException {
    String res;
    byte[] buf = new byte[256];
    int nread;
    InputStream in;
    IFile file = null;
   
    try {
      file = this.datasource.getRoot().getFileItem(name + ".mime")

      if (file.exists()) {
        res = "";

        in = file.openRead();

        try {
          while ((nread = in.read(buf)) > 0) {
            res = res + new String(buf, 0, nread);
          }
        } finally {
          in.close();
        }

        return res;
      } else {
        return null;
      }
    } catch (NetfeverException e) {
      throw new StorageException(e.getDetails(), e);
    } catch (IOException e) {
      UUID uuid = UUID.randomUUID();
     
      throw new StorageException(
          new FaultDetails(
              uuid.toString(),
              0,
              "Streaming error. Contact administrator with id " + uuid,
              "Error reading stream " +
              file.getAbsoluteName() +
              " with error " +
              e.getMessage(),
              null),
          e);     
    }
View Full Code Here


   * @param events
   * @throws StorageServletException
   */
  public void retrieveFile(String file, HttpServletResponse response)
      throws StorageException {
    IFile webStream = null;
    InputStream in;
    ServletOutputStream out;
    byte[] buf;
    int nread;
    String mime;

    try {
      webStream = this.datasource.getRoot().getFileItem(file);

      mime = getMime(file);
      mime = (mime == null) ? mimeFactory.createMime(FileUtils
          .getFileExtension(file)) : mime;

      response.setContentType(mime);
      response.setContentLength(webStream.getLength());

      in = webStream.openRead();

      try {
        out = response.getOutputStream();

        buf = new byte[BUFFER_2K];

        while ((nread = in.read(buf)) > 0) {
          out.write(buf, 0, nread);
          out.flush();
        }
      } finally {
        in.close();
      }
    } catch (NetfeverException e) {
      throw new StorageException(e.getDetails(), e);
    } catch (IOException e) {
      UUID uuid = UUID.randomUUID();
     
      throw new StorageException(
          new FaultDetails(
              uuid.toString(),
              0,
              "Streaming error. Contact administrator with id " + uuid,
              "Error reading stream " +
              webStream.getAbsoluteName() +
              " with error " +
              e.getMessage(),
              null),
          e);           
    }
View Full Code Here

  public static IFile[] getDefinitionFiles(IPath root, String filename)
      throws StorageServletException {
    ArrayList<IFile> res;
    IItem[] files;
    IPath path;
    IFile f;

    try {
      files = root.enumerate();
      res = new ArrayList<IFile>();

      for (IItem file: files) {
        if (file instanceof IPath) {
          path = (IPath)file;
         
          f = path.getFileItem(filename);

          if (f.exists()) {
            res.add(f);
          }
        }
      }
     
View Full Code Here

TOP

Related Classes of com.netfever.common.datasource.api.IFile

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.