Ejemplo n.º 1
0
 public FileAccess(String domain) {
   _domain = domain;
   _isLocal = Util.isLocal();
   if (_isLocal) {
     _rootFile = Util.initLocalResource(_domain);
     return;
   }
   try {
     // _home=(IFileMgrHome)ServiceLookup.getInstance(
     //  ServiceLookup.CLIENT_CONTEXT).getHome(IFileMgrHome.class);
     // if (_home == null) {
     //  System.out.println("Lookup failure: Home should not be null.");
     //  throw new Exception();
     // }
     // _remote = _home.create();
     _remote =
         (IFileMgr)
             ServiceLocator.instance(ServiceLocator.CLIENT_CONTEXT)
                 .getObj(IFileMgrHome.class.getName(), IFileMgrHome.class, new Object[0]);
     if (_remote == null) {
       System.out.println("Lookup failure: Remote should not be null.");
       throw new Exception();
     }
   } catch (Exception ex) {
     System.out.println(" Exception in SetUp  : " + ex.getMessage());
     ex.printStackTrace();
   }
 }
Ejemplo n.º 2
0
  /**
   * write zipped data to a group of existing files in a webdav server to be stored in the original
   * form using the current domain
   *
   * @param paths The paths relative to the domain for the files to be written
   * @param block The zipped contents of the block of data to be written and the description for
   *     each file
   * @param last true if this is the last block of data
   * @return The total number of bytes stored or null if method failed
   */
  public long writeToStreamZipped(String[] paths, MultiFileBlock block, boolean last) {
    long result = -1L;
    if (_tempFile == null) _tempFile = Util.createCache();

    try {
      byte[] buffer = block.getBlockData();
      ByteArrayInputStream bIn = new ByteArrayInputStream(buffer);
      GZIPInputStream zIn = new GZIPInputStream(bIn);
      int bufSize = 0;

      byte[] tmpBuf = new byte[buffer.length];
      FileOutputStream fOut = new FileOutputStream(_tempFile.getCanonicalPath(), true);
      BlockFileDescriptor des = block.getBlockFileDescriptor(0);
      int i = 1;
      do {
        bufSize = zIn.read(tmpBuf);
        if (bufSize != -1) {
          long partSize = des.getFileSize() - _tempFile.length();
          if (partSize < bufSize) {
            fOut.write(tmpBuf, 0, (int) partSize);
            fOut.close();
            if (_isLocal) {
              File partRootFile = Util.initLocalResource(des.getFileDomain());
              File tmpFile =
                  new File(
                      partRootFile.getCanonicalPath() + File.separatorChar + des.getFilePath());
              if (_tempFile.renameTo(tmpFile)) {
                result = tmpFile.length();
              }
            } else {
              WebdavResource webdavRes = Util.initWebdavResource(_domain);
              if (webdavRes == null) {
                _tempFile.delete();
                _tempFile = null;
                return result;
              }
              result = Util.putFile(webdavRes, des.getFileDomain(), des.getFilePath(), _tempFile);
            }
            _tempFile = Util.createCache();
            des = block.getBlockFileDescriptor(i);
            i++;
            fOut = new FileOutputStream(_tempFile.getCanonicalPath(), true);
            fOut.write(tmpBuf, (int) partSize, (int) (bufSize - partSize));
          } else {
            fOut.write(tmpBuf, 0, bufSize);
          }
          fOut.flush();
        }
      } while (bufSize == tmpBuf.length);
      fOut.close();

      zIn.close();
      bIn.close();

      if (last) {
        if (_isLocal) {
          File partRootFile = Util.initLocalResource(des.getFileDomain());
          File tmpFile =
              new File(partRootFile.getCanonicalPath() + File.separatorChar + des.getFilePath());
          if (_tempFile.renameTo(tmpFile)) {
            _tempFile = null;
            return tmpFile.length();
          }
        } else {
          WebdavResource webdavRes = Util.initWebdavResource(_domain);
          if (webdavRes == null) {
            _tempFile.delete();
            _tempFile = null;
            return result;
          }
          result = Util.putFile(webdavRes, des.getFileDomain(), des.getFilePath(), _tempFile);
        }
      } else {
        return _tempFile.length();
      }
    } catch (Exception ex) {
      ex.printStackTrace();
    }
    return result;
  }
Ejemplo n.º 3
0
 public void setDomain(String domain) {
   if (!domain.equals(_domain)) {
     _domain = domain;
     if (_isLocal) _rootFile = Util.initLocalResource(_domain);
   }
 }