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); } }
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); } }