syncTimer = new Timer();
TimerTask task = new TimerTask() {
@Override
public void run() {
Set<FileInfo> setToWork = Collections.synchronizedSet(setOfFiles);
Wrapper wrapper = WrapperFactory.getWrapperForCredentials(WrapperFactory.GOOGLE_DOCS);
boolean needToUpdateList = false;
for (FileInfo fi:setToWork) {
File file = new File(fi.getfName());
boolean update = false;
if (fi.getLastModified()!=file.lastModified()) update = true;
if (fi.getLength()!=file.length()) update = true;
if (update) {
log.add("need to update file "+fi.getfName()+" with docID="+fi.getDocumentLink()+" with mimeType="+fi.getFormat().getMimeType());
needToUpdateList=true;
try {
wrapper.update(fi.getfName(),fi.getDocumentLink(),fi.getFormat().getMimeType());
fi.setLastModified(file.lastModified());
fi.setLength(file.length());
log.add("updated!");
} catch (Exception e) {
log(e);
}
}
}
if (needToUpdateList) {
try {
wrapper.getListOfDocs(false);
} catch (Exception ex) {
log(ex);
}
}
}