예제 #1
0
 public static synchronized void removeMetaInfo(String fileId) throws FileAccessException {
   if (fileId == null) return;
   removeMetaInfoInMem(fileId);
   if (FileHelper.exist(
       IPackagingConstants.PACKAGING_PATH, getSubPath(fileId), META_INFO_FILENAME))
     FileHelper.delete(IPackagingConstants.PACKAGING_PATH, getSubPath(fileId), META_INFO_FILENAME);
 }
예제 #2
0
  /** This Constructor is used to create metaInfo during sending. */
  private MetaInfo(
      String fileId,
      int blockSize,
      int thresholdSize,
      String transId,
      String originalEventId,
      int totalBlocks,
      int lastBlockSize)
      throws FileAccessException, ApplicationException {
    _subPath = getSubPath(fileId);

    if (FileHelper.exist(IPackagingConstants.PACKAGING_PATH, _subPath, META_INFO_FILENAME)) {
      getMetaInfoFromFile(fileId);
      checkMetaInfo(
          fileId, blockSize, thresholdSize, transId, originalEventId, totalBlocks, lastBlockSize);
    } else {
      _fileId = fileId;
      _transId = transId;
      _blockSize = blockSize;
      _thresholdSize = thresholdSize;
      _originalEventId = originalEventId;
      _totalBlocks = totalBlocks;
      _lastBlockSize = lastBlockSize;
      createMetaInfo();
      storeMetaInfoIntoFile();
    }
  }
예제 #3
0
 private synchronized void storeMetaInfoIntoFile() throws FileAccessException {
   _timeLastAction = TimeUtil.localToUtc();
   File tmpFile = new File(META_INFO_FILENAME);
   FileWriter file = null;
   BufferedWriter bw = null;
   PrintWriter pw = null;
   try {
     file = new FileWriter(tmpFile);
     bw = new BufferedWriter(file);
     pw = new PrintWriter(bw);
     pw.println(_blockSize);
     pw.println(parseBlockReceivedToString());
     pw.println(_totalBlocks);
     pw.println(_fileId);
     pw.println(_lastBlock);
     pw.println(_lastBlockSent);
     pw.println(_lastBlockSize);
     pw.println(_subPath);
     pw.println(_thresholdSize);
     pw.println(_transId);
     pw.println(parseBlockFilenameToString());
     pw.println(_timeCreated);
     pw.println(_originalEventId);
     pw.println(_GNCI);
     pw.println(_finishedOnce);
     int originalDataLen = (_originalData == null) ? -1 : _originalData.length;
     pw.println(originalDataLen);
     for (int i = 0; i < originalDataLen; i++) {
       if (_originalData[i] != null) pw.println(_originalData[i]);
       else pw.println(NULL_DELIMITER);
     }
     pw.println(_timeLastAction);
     close(pw);
     if (FileHelper.exist(IPackagingConstants.PACKAGING_PATH, _subPath, META_INFO_FILENAME))
       FileHelper.replace(
           IPackagingConstants.PACKAGING_PATH, _subPath, META_INFO_FILENAME, tmpFile);
     else
       FileHelper.create(
           IPackagingConstants.PACKAGING_PATH, _subPath, META_INFO_FILENAME, tmpFile);
     tmpFile.delete();
   } catch (IOException ioe) {
     throw new FileAccessException("Unable to store meta info to file.");
   } finally {
     close(pw);
   }
 }
예제 #4
0
 /** This Constructor is used to create metaInfo when receiving. */
 private MetaInfo(String fileId, int totalBlocks)
     throws FileAccessException, ApplicationException {
   _subPath = getSubPath(fileId);
   if (FileHelper.exist(IPackagingConstants.PACKAGING_PATH, _subPath, META_INFO_FILENAME)) {
     getMetaInfoFromFile(fileId);
     checkMetaInfo(fileId);
     if (_totalBlocks < totalBlocks) {
       _totalBlocks = totalBlocks; // new total Block value
       storeMetaInfoIntoFile();
     }
   } else {
     _fileId = fileId;
     createMetaInfo();
     if (_totalBlocks < totalBlocks) _totalBlocks = totalBlocks;
     storeMetaInfoIntoFile();
   }
 }
예제 #5
0
  private synchronized void getMetaInfoFromFile(String fileId) throws FileAccessException {
    // String[] metaInfo = new String[6];
    File fileDesc = null;
    FileReader reader = null;
    BufferedReader breader = null;
    try {
      fileDesc =
          FileHelper.getFile(
              IPackagingConstants.PACKAGING_PATH, getSubPath(fileId), META_INFO_FILENAME);
      reader = new FileReader(fileDesc);
      breader = new BufferedReader(reader);

      _blockSize = Integer.parseInt(breader.readLine());
      parseStringToBlockReceived(breader.readLine());
      _totalBlocks = Integer.parseInt(breader.readLine());
      _fileId = breader.readLine();
      _lastBlock = Integer.parseInt(breader.readLine());
      _lastBlockSent = Integer.parseInt(breader.readLine());
      _lastBlockSize = Integer.parseInt(breader.readLine());
      _subPath = breader.readLine();
      _thresholdSize = Integer.parseInt(breader.readLine());
      _transId = breader.readLine();
      parseStringToBlockFilename(breader.readLine());
      _timeCreated = breader.readLine();
      _originalEventId = breader.readLine();
      _GNCI = breader.readLine();
      _finishedOnce = Boolean.valueOf(breader.readLine()).booleanValue();

      int originalDataLen = Integer.parseInt(breader.readLine());
      if (originalDataLen < 0) _originalData = null;
      else {
        _originalData = new String[originalDataLen];
        for (int i = 0; i < originalDataLen; i++) {
          _originalData[i] = breader.readLine();
          if (NULL_DELIMITER.equals(_originalData[i])) _originalData[i] = null;
        }
      }
      _timeLastAction = Long.valueOf(breader.readLine()).longValue();
    } catch (IOException ioe) {
      throw new FileAccessException("Unable to read meta info from file.", ioe);
    } finally {
      close(breader);
    }
  }
예제 #6
0
 /** This Constructor is used to create metaInfo when receiving acknowledgement. */
 private MetaInfo(String fileId) throws FileAccessException {
   _subPath = getSubPath(fileId);
   if (FileHelper.exist(IPackagingConstants.PACKAGING_PATH, _subPath, META_INFO_FILENAME))
     getMetaInfoFromFile(fileId);
   else throw new FileAccessException("Meta Info file not found!");
 }